Serial comms in Python
-
Now that I have set up the serial comms between Omega and Arduino, the next step is to write some Python code that talks to Arduino.
Installing python is easy:
$ opkg update $ opkg install python
But this does not install the Python serial library. I couldn't figure out which package should I install to be able to do
import serial
.
-
Ok, never mind, I've downloaded the library from http://sourceforge.net/projects/pyserial/files/pyserial/2.7/
Extracted the tar and copied the serial folder to my project root.Here's some Python code for quick reference:
import serial port = serial.Serial("/dev/ttyATH0", baudrate=115200, timeout=3.0) port.open() port.isOpen() port.write("blahblahblah")
-
Thank you so much for posting this. I plan to use one of my Onion's in this way.
-
I've never installed a python library before, how do you do it. I want to use pyserial as well
-
@Adam-Watts, since the storage space on Omega is fairly limited, I did not install any Python package manager. If you use a module in one project, then its ok to copy the module folder in your project root.
Here's my file tree:
/root/myproject - project folder
/root/myproject/serial - pyserial module, "serial" folder copied from http://sourceforge.net/projects/pyserial/files/pyserial/2.7
/root/myproject/main.py - python script that does your stuffIn you main.py file, you can then just
import serial
and Python will know that it has to look in the working directory for the module folder.
-
Has anyone managed to install pyserial for Python3?
pyserial isn't one of the packages listed by opkg.
When trying to build from the source (http://pythonhosted.org/pyserial/pyserial.html and https://pypi.python.org/pypi/pyserial) I get an error:
"unable to open /usr/lib/python3.4/config-3.4/Makefile"; sure enough, the whole config-3.4 directory is missing after a python3-light install.
I'm unfamiliar enough with the python packages to know why.(note: the soureforge link above is just for Python 2.7 and before, and is a bit dated).
Thanks in advance,
Bill
-
Hi @Bill-M, have you tried this
makefile
? https://gitlab.labs.nic.cz/turris/openwrt-packages/commit/c0294ca1999f26debc4093266bd4a3b36f89e72e