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
Question [SOLVED] [datetime.strptime] ValueError: time data 'foo' does not match format 'bar' Winfried 1 1,285 Jan-02-2025, 02:09 AM
Last Post: lyly19
  Python: How to import data from txt, instead of running the data from the code? Melcu54 1 658 Dec-13-2024, 06:50 AM
Last Post: Gribouillis
  Convert Json to table format python_student 4 14,737 Dec-05-2024, 04:32 PM
Last Post: Larz60+
  search API calls in different format pythonnewbieee 4 1,327 Sep-23-2024, 04:14 AM
Last Post: Pedroski55
  Python script to extract data from API to database melpys 0 876 Aug-12-2024, 05:53 PM
Last Post: melpys
Exclamation Date format convert problem for SQL server eotret 5 2,122 Aug-09-2024, 07:19 AM
Last Post: Pedroski55
  To fetch and iterate data from CSV file using python vyom1109 3 1,049 Aug-05-2024, 10:05 AM
Last Post: Pedroski55
  Invalid Date Format fo Cached Files jland47 1 1,037 May-22-2024, 07:04 PM
Last Post: deanhystad
  Compare current date on calendar with date format file name Fioravanti 1 2,051 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 1,693 Mar-09-2024, 12:33 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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