Reading From Arduino Without Pyserial

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

bhain7
Posts: 7
Joined: Wed Feb 13, 2013 1:30 am

Reading From Arduino Without Pyserial

Postby bhain7 » Wed Feb 13, 2013 1:43 am

I was wondering if there was any way to read sensor data from Arduino without using Pyserial.

Pyserial is a pain to setup.

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Wed Feb 13, 2013 5:52 pm

The trick with pyserial is to install it for Python 3.3, which Blender uses. Then you need to add the path to pyserial to sys.path in Blender since Blender uses it's own copy of Python.

Other options, needing either some hardware on the Arduino side or some low-level coding, include bit-banging on the parallel port or sending data over TCP/IP.

bhain7
Posts: 7
Joined: Wed Feb 13, 2013 1:30 am

Postby bhain7 » Wed Feb 13, 2013 9:55 pm

I'll try to find Pyserial for Python 3.3 and follow that and get back to you.

What kind of hardware do you suggest on the arduino side? That seems practical to me if it is cheap and will bring it closer to a plug and play experience.

Advice much much appreciated Stiv.

stiv wrote:The trick with pyserial is to install it for Python 3.3, which Blender uses. Then you need to add the path to pyserial to sys.path in Blender since Blender uses it's own copy of Python.

Other options, needing either some hardware on the Arduino side or some low-level coding, include bit-banging on the parallel port or sending data over TCP/IP.

bhain7
Posts: 7
Joined: Wed Feb 13, 2013 1:30 am

Postby bhain7 » Thu Feb 21, 2013 12:43 am

I'm not quite sure how to install it specifically for Python 3.3. Does this have to do with the version of pyserial? or what ?


stiv wrote:The trick with pyserial is to install it for Python 3.3, which Blender uses. Then you need to add the path to pyserial to sys.path in Blender since Blender uses it's own copy of Python.

Other options, needing either some hardware on the Arduino side or some low-level coding, include bit-banging on the parallel port or sending data over TCP/IP.

stiv
Posts: 3646
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Postby stiv » Thu Feb 21, 2013 12:52 am

I'm not quite sure how to install it specifically for Python 3.3. Does this have to do with the version of pyserial? or what ?


It has to do with the version of Python used to do the pyserial install. Like running easy_install-3.3, or python3 setup.py...

There are two issues here:

One is the modules must be built for the correct version of python since struct sizes change between versions.

The other is having the module end up where the appropriate version of python (or blender) can see it. This is less important and can be tweaked by setting the PYTHONPATH env var or appending to sys.path before importing.

quisto
Posts: 1
Joined: Sat Feb 23, 2013 3:23 pm

Postby quisto » Sat Feb 23, 2013 4:36 pm

Yesterday I added pyserial to Blender 2.66 on Ubuntu and Windows.

I could not get pyserial working with Python outside Blender, but I could make it works with the internal Python included in Blender.

I've taken the following steps:

Ubuntu (12.04-64bit):
- Open a terminal and setup python3.2 with “sudo apt-get install python3.2“
- Download the pyserial source - pyserial-2.6.tar.gz
- Decompress it, open a terminal and go to the folder where you have decompressed it.
- Execute “sudo python3.2 setup.py install” or “sudo python3 setup.py install”. I'm not sure which is the correct one, but if you want, you can run both commands.
- Open your blender and open a python console
- Write:

Code: Select all

import sys
sys.path.append("/usr/local/lib/python3.2/site-packages/")
import serial


After running ‘import serial’ you should not get any errors.

Windows (XP-32bit):
- Setup Python33 on C:\Python33
- Download the pyserial source - pyserial-2.6.tar.gz
- Decompress it with 7zip on C:\Python33 - You need to have "setup.py" in that folder.
- Run “cmd”, go to C:\Python33 and Execute “python.exe setup.py install”
- Open your blender and open a python console
- Write:

Code: Select all

import sys
sys.path.append("C:\Python33\Lib\site-packages")
import serial


After running ‘import serial’ you should not get any errors.

Now you should be able to run:

Code: Select all

arduino = serial.Serial('/dev/ttyACM0', 9600)

or “COM*” on windows

If you need to write values (example ”a”):

Code: Select all

arduino.write(b'a') # I must add that b before the 'a'


If you need to read values:

Code: Select all

arduino.readline()


Good luck!

bhain7
Posts: 7
Joined: Wed Feb 13, 2013 1:30 am

Postby bhain7 » Thu Feb 28, 2013 5:52 pm

Hah woo! Worked all the way until

Code: Select all

arduino = serial.Serial('/dev/ttyACM0', 9600)

I am on windows, and I'm not sure what it is I should be changing to COM*


Also was wondering if I will need to run:

Code: Select all

import sys
sys.path.append("C:\Python33\Lib\site-packages")
import serial

at the beginning of every serial code in order to import serial?

bhain7
Posts: 7
Joined: Wed Feb 13, 2013 1:30 am

Postby bhain7 » Thu Feb 28, 2013 6:23 pm

arduino = serial.Serial('COM5', 9600)

Aha, had to close Arduino scripting too, thanks for the assistance mate. It seems to be working properly now !

:)


Return to “Coding Blender”

Who is online

Users browsing this forum: No registered users and 1 guest