Python Forum

Full Version: python data format to c data format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
hex is hex