Get the same value as an Arduino subtraction with Python

Asked

Viewed 30 times

-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.

  • 1

    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?

  • 2

    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.

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.