harmsm / PyCmdMessenger

Python interface for CmdMessenger arduino serial communication library
MIT License
80 stars 32 forks source link

example throws error #36

Open ghost opened 6 years ago

ghost commented 6 years ago

the first exchange "who_are_you" works fine, however for the sequence

c.send("sum_two_ints",4,1) msg = c.receive()

python 3.6 throws this error on the receive line: struct.error: unpack requires a buffer of 2 bytes

headrotor commented 2 months ago

This is probably caused by using a different microcontroller than the default Atmel. This worked for me on a Teensy (arm)

       # Board input parameters:
       #      int_bytes: number of bytes to store an integer
       #      long_bytes: number of bytes to store a long
       #      float_bytes: number of bytes to store a float
       #      double_bytes: number of bytes to store a double``

       #  These can be looked up here:
       #      https://www.arduino.cc/en/Reference/HomePage (under data types)`

arduino = PyCmdMessenger.ArduinoBoard("/dev/ttyACM0",baud_rate=9600)
teensy = PyCmdMessenger.ArduinoBoard("/dev/ttyACM0",
                                     int_bytes=4,
                                     baud_rate=9600)

...
# Initialize the messenger
c = PyCmdMessenger.CmdMessenger(teensy,commands)