I needed to figure out how to send binary data from my PC to an Arduino for a project to control 3 stepper motors. I thought the demo code might be of interest to Forum users.
The attached Python code sends 5 numbers to the Arduino - in Arduino terms they are an UNSIGNED LONG, 3 INTs and a BYTE.
In the demo the Arduino just sends the numbers back to the Python script to show they were properly received.
The Arduino code uses a STRUCT and a UNION to simplify the receipt and usage of the data from the PC.
The Python code as some similarities with the demo here.
SendBinary.py (2.85 KB)
ReceiveBinary.ino (2.05 KB)