Go Down

Topic: Demo of PC-Arduino comms using Python (Read 3 times) previous topic - next topic


did some playing with python here - http://playground.arduino.cc//Main/IEEE754tools -to get 64 bit double to Arduino and pack it as 32 bit float and back. Might be useful.

it misses start/stop bytes and CRC's in communication to be reliable.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Jul 26, 2014, 09:07 pm Last Edit: Jul 27, 2014, 03:14 am by ron_sutherland Reason: 1
I've been tinkering with Python and command processing firmware on an Uno.

PySerial caused my Uno to reset when I open a port from Windows. Also PySerial is broken with Python 3.4.1, so I hacked out the parts I wanted and fixed them to connect without reset. My python script will eventually be used as a setup tool for my project, but at the moment it is for debugging.
My repo:http://epccs.org/hg/epccs/Software/file/tip/Expert/SensActuIrrig

On the Uno I am working on a command processor; it works from the serial monitor or can be automated (as in the Python above). I was  thinking about Standard Commands for Programmable Instruments (SCPI) when I started, but then I added crc16.
Code: [Select]
   pos               usage
    [first digit]     optional id used to address, which holds until changed
    [white space]     optional used to separate  id from command
    [first alpha]     optional command, a string of alpha only
    [white space]     optional used to separate command from arguments
    [arguments]       one or more comma delimited e.g. "13,high" 
   \n                no crc
   ;crc16\n        crc16 is calculated on input until ';' is received

My repo: http://epccs.org/hg/epccs/Software/file/tip/Embeded/SensActuIrrig

Upload stretch then use Serial Monitor to send these commands:
debug on
dout 13,high
dout 13,low


PySerial caused my Uno to reset when I open a port from Windows.

That is normal. It is not confined to Windows.

My demo code takes account of it.



That is normal.

Looks like it, I am still sorting out the details for my project, but the MCU reset when the host connects is looking like a problem. If I'm half way done with a task that the Uno is timing, and the host connects ... the tasks is stopped. That would be fine if the host were timing the task, but that is not what I want. With the changes, I've made to Pyserial I can connect over and over without the reset, but if I use the serial monitor before I connect the Uno resets the first time my hack connects, but not the next. If I power off the host, and then back on the Uno resets the first time. Seems to be no way to prevent this. So some stuff is on the way that will allow a switch to disable the DTR line, and enable again to upload firmware.


If I'm half way done with a task that the Uno is timing, and the host connects ... the tasks is stopped.

I don't really understand what you are trying to do. Why not have the PC open the Serial port at the start and leave it open until everything is finished?

I think there is an option to disable the auto-reset on the Uno board, but that would make uploading programs difficult.

I have a standalone Atmega328 on a perf-board circuit running 24/7. I can connect it to my PC with a USB-TTL cable. I have two connectors on the perf-board one of which has no connection to the reset line. If I just want to capture data from the running program I can connect the PC to that connector without causing a reset.


Go Up