dpharris 13 Posted April 27, 2014 Share Posted April 27, 2014 Hi -- I have been trying to use Serial.parseInt() -- but can't get it to work. It appears to read on digit only. So, I thought, try an example. However, ReadASCIIString does;t work, either, at least in my hands :-( Using Tiva Launchpad. Any advice welcome. Thanks, David energia 1 Quote Link to post Share on other sites
SixSixSevenSeven 23 Posted April 27, 2014 Share Posted April 27, 2014 Without seeing code, knowing what should be happening and what is happening we can't really help from that information. Quote Link to post Share on other sites
dpharris 13 Posted April 27, 2014 Author Share Posted April 27, 2014 ReadSCIIString is one of the supplied Examples supplied with Energia. It doesn't work. Captures *one* digit, then hangs. I have tried numbers work-arounds without success. I note others have pointed this out, also. David Quote Link to post Share on other sites
angeld 0 Posted May 1, 2014 Share Posted May 1, 2014 yes, i have the same proble i can't use parseInt or parseFloat, i did an aplication with bluethoot and rbg, and i need to read the values of my cell phone, but i need to read only whit parseInt. it didn't works. dpharris how i can do? the problem is to i have an arduino and the same program works, i think to should give support these functions. Quote Link to post Share on other sites
dpharris 13 Posted May 2, 2014 Author Share Posted May 2, 2014 Here is the code for this. https://github.com/energia/Energia/blob/master/hardware/lm4f/cores/lm4f/Stream.cppI do not see an error on a quick look. Perhaps you can find it? David Quote Link to post Share on other sites
angeld 0 Posted May 5, 2014 Share Posted May 5, 2014 i was reviewing this program:void setup(){ Serial.begin(9600); pinMode(RED_LED, OUTPUT); digitalWrite(RED_LED, HIGH);}void loop(){ while( Serial.available() > 0 ) { byte inc = Serial.parseInt(); Serial.println(inc); }}and when i used for the first time, and send a number from one to ten, in the serial monitor appears the correct number, example, ifyou send 9,0,0 in the serial monitor appears 9 but the others not appear, and you need to press reset if you want to do once again.i think to in some library the declaration of the variables are wrong, and not return the correct value. try to run the example and see what happens pleaseim not a good programer but is what i found Quote Link to post Share on other sites
energia 485 Posted May 5, 2014 Share Posted May 5, 2014 Thank you for reporting this issue! This was a very fundamental bug in HardwareSerial. 1: peek() would loop forever if the RX buffer was empty. 2: read() would increase the buffer read pointer even if no byte was read because the buffer was empty. Both of these issues have been fixed and pushed up to github: Patch: https://github.com/energia/Energia/commit/b95f5f346a320bf8d06f4d4281ec31d0d62f9cff Easiest way to fix this in your installation is: 1: Download the patched file from https://raw.githubusercontent.com/energia/Energia/master/hardware/lm4f/cores/lm4f/HardwareSerial.cpp 2: In your Energia folder browse to hardware/lm4f/cores/lm4f 3: Rename HardwareSerial.cpp to HardwareSerial.org 4: Copy the file you downloaded under 1 to this folder. 5: Restart Energia. Thanks again for the report! Robert dpharris 1 Quote Link to post Share on other sites
dpharris 13 Posted May 6, 2014 Author Share Posted May 6, 2014 Thanks for the quick fix! Quote Link to post Share on other sites
angeld 0 Posted May 6, 2014 Share Posted May 6, 2014 i did the modifications that you told me, and then i loaded the SerialASCIIString but it didn't work, i think that when you its used Serial.read inside the funtion of Serial.available() it doesn't work. i think that the funtion Serial.read, is not recognizing '\n'. because i did this program excluding '\n', and it worked. and in the serial monitor appears the correct value and the RGB led change its color, const int redPin = RED_LED;const int greenPin = GREEN_LED;const int bluePin = BLUE_LED;void setup() { Serial.begin(9600); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);}void loop() {while (Serial.available() > 0) { int red = Serial.parseInt(); int green = Serial.parseInt(); int blue = Serial.parseInt(); // look for the newline. That's the end of your // sentence: if (Serial.read() == '\n') { Serial.println("finish"); } analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); Serial.print(red, HEX); Serial.print(green, HEX); Serial.println(blue, HEX); }} i don't know whats happening // pins for the LEDs:const int redPin = RED_LED;const int greenPin = GREEN_LED;const int bluePin = BLUE_LED;void setup() { // initialize serial: Serial.begin(9600); // make the pins outputs: pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT);} example of SerialASCIIString void loop() {// if there's any serial available, read it:while (Serial.available() > 0) { // look for the next valid integer in the incoming serial stream: int red = Serial.parseInt(); // do it again: int green = Serial.parseInt(); // do it again: int blue = Serial.parseInt(); // look for the newline. That's the end of your // sentence: if (Serial.read() == '\n') { // constrain the values to 0 - 255 // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" red = constrain(red, 0, 255); green = constrain(green, 0, 255); blue = constrain(blue, 0, 255); // fade the red, green, and blue legs of the LED: analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); // print the three numbers in one string as hexadecimal: Serial.print(red, HEX); Serial.print(green, HEX); Serial.println(blue, HEX); } }} in the example you need to get '\n' but because it doesn't detect '\n' it never execute the if condition Quote Link to post Share on other sites
energia 485 Posted May 6, 2014 Share Posted May 6, 2014 In the Energia Serial monitor there is a little drop down box left of the baudrate setting drop down box. Make sure that that is set to "Newline". By default it is set to "No line ending" which means that it does not send '\n'. When you set it to "Newline" it will send the '\n' and you should be able to run the Sketch without problems. Quote Link to post Share on other sites
angeld 0 Posted May 7, 2014 Share Posted May 7, 2014 jeje thanks it's work Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.