python data format to c data format - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python data format to c data format (/thread-6650.html) |
python data format to c data format - tony1812 - Dec-01-2017 Hello, I am writing a python code to write data to the serial port for Anduino to receive. Pi side pos_i=50 #degree in the range of 0-180 print(pos_i) pos_b=pos_i.to_bytes(1, 'little') # squeeze the degree value into one single byte print(pos_b) while True: ser.write(pos_b) #write the single byte to serial sleep(0.1)Duino side void loop() { //Serial.println(); if (!Serial.available()>0) { byte inByte = Serial.read(); int pos = int(inByte); //inByte; myservo.write(pos); delay(delay_time); }//if }Here is the question, in python byte's format is in 180 is \xb4 but in c the format is 0xb4, o when Arduino receives the byte fro python, does it auto magically convert to the c format? Is there a utility function to convert python format to c format? Thanks RE: python data format to c data format - Larz60+ - Dec-02-2017 hex is hex |