Hi I'm new to this forum and I have a problem that I just can't seem to figure out. I have an infinite loop that goes through and writes something to the arduino and then it recieves to different values. The problem is that even though it works sometimes it doesn't always sync up to the correct values being exchanged, and if I send a value over 10 (as a char) to the arduino it reads the value incorrectly. If anyone could point me in the right direction that would be great.
this the part of my python script that exchanges the values...
class getSerial(threading.Thread): #its threaded so that I can run the pygame part at the same time
def __init__(self):
threading.Thread.__init__(self) #ser1 is instantiated correctly in a different part of the program
def run(self):
while 1:
try: #gsa is an object of a class that holds all of the values for the entire program
ser1.write(chr(gsa.getForward())) #here is the problem, whenever I send anything over 10 it mixes up the entire
gsa.setpressure(ser1.read()) #program and when I check the arduino serial output its telling me the ASCII
print ser1.read() #values but it still won't go over 10
except:
print "couldn't read."
this is my arduino loop...
void loop() // all parts of the serial are set up before I am just trying to cut down on the amount of info
{
if(Serial.available() > 0)
{
forward = Serial.read() - 48; //I subtracted 48 to try and get 0-9 integers
Serial.print(readpressure()); // readpressure() calls a method that returns the pressure read by the arduino
Serial.print(forward); //I'm sending the forward variable back to check it
}
}
sorry if I was vague; if anyone can help that would be fantastic