that is all the code.
data = arduino.read(20)hi = data[0]
void setup() { Serial.begin(9600);}void loop() { Serial.print(300); Serial.print(',');}
import serialarduino= serial.Serial('COM3', 9600)data = arduino.read(20)hi = int(data[0])
I dont know if you know python or not, but when i do it tells me the output. Heres what i did to test it.
Serial.print(300);
depending on what i set "hi" to it gives me a different number.
def openPort(): global running ser.flushInput() # tell the arduino to start sending running = True ser.write('3') ser.write('G') def checkInput(b): # see if the bytes have been received in the correct order correct = True for i in range(0,4): #print i," - " # ,hex(ord(b[i])) if (ord(b[i]) >> 6) != i : correct = False return correct def getData(): global reading, running if running : a = ser.read(4) if checkInput(a) : reading[0] = ((ord(a[0]) & 0x1f)<< 5) | (ord(a[1]) &0x1f) reading[1] = ((ord(a[2]) & 0x1f)<<5) | (ord(a[3]) &0x1f) #print reading[0]," - ",reading[1] else: correct = False while correct == False : # resyncronise print "lost sync ",ser.inWaiting() b = ser.read(1) t = a[1] + a[2] + a[3] + b[0] a = t correct = checkInput(a)
Would you recommend breaking the numbers down before sending them?