Robin2:
I haven't been able to find a piece of example code (both the Python and the Arduino stuff) that can reliably send and receive binary data between a PC and an Arduino. I'm thinking of writing an example, but it would be a waste of time if there is already something out there.
If anyone can provide any links to an existing example I would appreciate it.
...R
Hi,
I've been looking for the same example code as you in 2014. and your code is the only one for both receiving and sending the data with Python + Arduino.
This was the first of your threads that I encountered and I tested both your examples with Python 7 on Windows 10 + Arduino. You said: "I have only tested this on Linux. It would be great if someone would try it on Windows or on a Mac.", and since that thread and the sticky one are locked, it seems this is the only place suitable for sending you a feedback.
According to the download count of your examples it is obvious quite a lot of people find them useful but unfortunately both threads with your code are locked.
What I am trying to do is to measure 6 temperatures with Arduino (by reading NTC 100k analog sensors), sending the temperatures to Windows PC for displaying them in the GUI where the slider could be used to set the target temperature. While I already did a command line Python program which does the described, I was struggling with doing the same in the GUI and that's how I've found you posts.
Now that I tested your code I am sure I can adapt it for what I am trying to do but there are a few problems which are not critical but it would be nice if they could be resolved. The problems I encountered when testing your unmodified examples are:
-
It is not possible to exit the Python program in the case there are not com ports (No Serial Port Found). In that case after clicking on 'x' the program is not responding and it has to be stopped by force. On the other hand, if the COM port is found then exiting from the program works well.
-
The output of print from inside exit_handler() function is never printed out and I am not sure if cD.stopListening() and aC.closeSerial() get ever executed.
-
When trying to upload Arduino code after exiting the Python program upon selecting the COM port, avrdude is throwing: "avrdude: ser_open(): can't open device "\.\COMXX": Access is denied.". The workaround is to start the Python program again and to exit before selecting the COM port or to unplug the USB cable and plug it again.
However, these minor problems are not something that would prevent program's usage as they are all easily avoidable. Your code is really simple and reliable, the other programs that I've found not only were working in only one direction (just sending the data or just receiving the data), were using multiple threads, Queues, Queue managers etc. and didn't work well.
One thing that would be nice to change would be to make the sending of slider value happen only a second or two after the slider stops moving. That way the serial communication wouldn't be overwhelmed during the slider movement. Of course, such a behaviour is suitable for only certain applications - It wouldn't be suitable for controlling the servo for camera movement but it would be suitable for setting the target temperature where the target value doesn't have to be updated while the slider is still moving.
And you somewhere mentioned XOR/CRC protected messages, it would be nice if you could send those examples too.
Thank you for the code and have a nice day
Regards