0

Serial Communication & Adafruit IO
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Serial Communication & Adafruit IO

by JoseeMallah on Fri Jan 08, 2021 5:33 am

Hello everyone!
I am using an Arduino UNO to get analog readings from 2 sensors. Then, I am sending the product (*) of these 2 values to a NodeMCU via serial communication. The value is received correctly: when I use
Code: Select all | TOGGLE FULL SIZE
Serial.write(Serial.read())
correct values are displayed. However, when I move the value received to a variable then print it:
Code: Select all | TOGGLE FULL SIZE
x = Serial.read()
Serial.println(x)

different (wrong) values are shown. And these same wrong values are uploaded to Adafruit IO.
So, does anyone know what's happening? Any format or data size differences? Why am I obtaining wrong values? And how to get the correct ones?
Thank you

JoseeMallah
 
Posts: 9
Joined: Thu Oct 31, 2019 6:34 am

Re: Serial Communication & Adafruit IO

by dastels on Fri Jan 08, 2021 11:11 am

What language are you coding in and what is the type of x? There is probably some incorrect casting/coercion happening.

Dave

dastels
 
Posts: 6801
Joined: Tue Oct 20, 2015 3:22 pm

Re: Serial Communication & Adafruit IO

by JoseeMallah on Sun Jan 10, 2021 11:50 am

Yes right thank you, I had to use parseFloat().

JoseeMallah
 
Posts: 9
Joined: Thu Oct 31, 2019 6:34 am

Please be positive and constructive with your questions and comments.