-1
The following code on the Arduine yields the value 26.
int a = 32760;
int b = -32750;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(b-a);
}
I would like to send these two values via serial to a python script (Serial.println(String(a)) and Serial.println(String(b))) and get the same subtraction value with python
I believe I should use the python Struct library with the Signed short format, but I don’t know exactly how to do this.
Do not give thanks and do not give greetings in the publications. See What kind of behavior is expected from users?, see also Greetings and Thanks and see the comments of Edits only to remove greetings/thanks?
– Augusto Vasques
My suggestion is to send as ASCII, or even as a JSON structure, to Python. Dealing with binary formats is problematic. The question is also very broad, is about Python but contains Arduino code... the correct question would have an example in Python tried to unpacking a binary value from a string or byte array, without involving the issue of communication between Arduino and computer. Being.
– epx