cevepe
February 23, 2016, 11:32am
1
I have problem with serial.read().
I need that when I enter a value of "1", so that divorced IF which lists the current temperature. I do not want to keep me Arduino via delay() list each temperature, but I want to list only the temperature of 1x based on a value of "1".
IF value of work. Why?
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available())
{
byte value = Serial.read();
if(value == 1)
{
Serial.write(value);
}
}
}
system
February 23, 2016, 11:41am
2
I need that when I enter a value of "1", so that divorced IF which lists the current temperature.
That collection of words does not form a useful thought.
byte value = Serial.read();
if(value == 1)
What is sending the data? If the data is sent as text, you should be testing for having received the character 1, not the value 1.
if(value == '1')
holmes4
February 23, 2016, 11:42am
3
Because you are NOT entering a value of 1 you typed the char '1' ! you have never entered a number on a keyboard you have entered the chars 1 2 3 etc.
Mark
cevepe
February 23, 2016, 11:50am
4
I will send data from Raspberry. When you send the number "1," I need to get the current temperature of the Arduino.
Here is a python code
import serial
s = serial.Serial(port='/dev/tty.AMA0', baudrate=9600)
s.write("1")
data = s.read()
print(data);
s.close()
system
February 23, 2016, 12:07pm
5
When you send the number "1," I need to get the current temperature of the Arduino.
When you send "1", you are sending the character '1', NOT the value 1.