Hi there,
i am strugling for past few days and really dont know what am I missing.
Doing this as hobby so pls don't judge.
My set up Arduino reads sensor (light) sends data to NodeMcu who sends it to localhost.
The thing i am struggling is i cant extract variable coming from Arduino ..
the code:
how output should work:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop() { // run over and over
if (Serial.available()) {
Serial.write(Serial.read());
}
}
OUTPUT
520.00
710.00
1020.00
640.00
Now if i try to Serial.read() and store it as variable i get gibberish and values which i cant use. Any attempt to mess with 1st code i get this result
void loop() { // run over and over
if (Serial.available()) {
float arrivingdatabyte = Serial.read();
delay(1000);
Serial.println(arrivingdatabyte);
}
}
OUTPUT
55.00
13.00
11.00
44.00
19.00
so pls can someone help me what am I doing wrong. Or @ least point me to right direction.
Many thanks.
Data is sent over a serial link one character at a time so when you receive a character and print it, which is what you are doing, you see a print of a representation of the value one character at a time, not the actual value
If you want to turn what you receive into a value that you can use then you need to read each of the characters and convert the whole thing.