Python Forum
python data format to c data format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python data format to c data format
#1
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
Reply
#2
hex is hex
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 214 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Help with to check an Input list data with a data read from an external source sacharyya 3 403 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  need help with data analysing with python and sqlite Hardcool 2 357 Jan-30-2024, 06:49 AM
Last Post: Athi
  Python date format changes to date & time 1418 4 587 Jan-20-2024, 04:45 AM
Last Post: 1418
  loop through csv format from weburl in python maddyad82 3 387 Jan-17-2024, 10:08 PM
Last Post: deanhystad
  Export data from PDF as tabular format zinho 5 693 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  format json outputs ! evilcode1 3 1,739 Oct-29-2023, 01:30 PM
Last Post: omemoe277
  Better python library to create ER Diagram by using pandas data frames as tables klllmmm 0 1,102 Oct-19-2023, 01:01 PM
Last Post: klllmmm
  Bulk loading of data using python shivamsvmsri 2 670 Sep-28-2023, 09:04 AM
Last Post: shivamsvmsri
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 742 Sep-22-2023, 02:33 PM
Last Post: carecavoador

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020