I'm new so I might be making a stupid mistake, but I'm declaring:

char dollars;

at the begging of file, afterwards I'm reading a data from a web page, printing it to my serial. That part work well. The data returned from the web page is a number, 55 for instance.

The number get's printed correctly to the serial. But when I try to save the complete number it changes. for instance, when I get 0 from the server. The printed result is 10.

here is the important part of my code:

unsigned long lastRead = millis();
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c = www.read();
      dollars = www.read();
      lastRead = millis();


while the www.read is repeating each of the returned characters it works fine Serial.print(c); but when I save it to the dollars char var, it get garbled up into something different. What am I doing wrong?

I'm planning to show that number from the web page onto my 4 digit screen at the end.

  • You are going to have to go more in depth with your char variable. I know what you are trying to do, and I have seen it fail before, but I remember there was one solution. The read method needs to be built on and you have to be more specific. It would be amazing if you could post the rest of the code.
    – user7516
    Feb 23, 2015 at 23:32

1 Answer 1


Webpages usually return data in text format with new line characters at the end.
In case of 55 you would get "55\r\n" or [53, 53, 13, 10] in bytes.
You need to parse the characters, like Serial.parseInt() does.

You are also only sending every second byte back to the serial monitor and only saving the last byte from the other every second byte.
After you read a byte with Serial.read() you can't read the same byte again, you get the next one.
In case of 55 you would send back "5\r" to the serial monitor and only store "\n" or 10 into dollars.
In case of 0 you would send back "0\n" to the serial monitor and store some unknown value into dollars, because you read more bytes that was sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.