Previous Thread  Next Thread

chat icon Reading From Arduino Without Pyserial

bhain7

Posted: Wed Feb 13, 2013 1:43 am
Joined: 13 Feb 2013
Posts: 7
I was wondering if there was any way to read sensor data from Arduino without using Pyserial.

Pyserial is a pain to setup.
Reply with quote


stiv

Posted: Wed Feb 13, 2013 5:52 pm
Joined: 05 Aug 2003
Posts: 3645
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.
Reply with quote


bhain7

Posted: Wed Feb 13, 2013 9:55 pm
Joined: 13 Feb 2013
Posts: 7
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.
Reply with quote


bhain7

Posted: Thu Feb 21, 2013 12:43 am
Joined: 13 Feb 2013
Posts: 7
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.
Reply with quote


stiv

Posted: Thu Feb 21, 2013 12:52 am
Joined: 05 Aug 2003
Posts: 3645
Quote:
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.
Reply with quote


quisto

Posted: Sat Feb 23, 2013 4:36 pm
Joined: 23 Feb 2013
Posts: 1
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:
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:
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:
arduino = serial.Serial('/dev/ttyACM0', 9600)

or “COM*” on windows

If you need to write values (example ”a”):
Code:
arduino.write(b'a') # I must add that b before the 'a'


If you need to read values:
Code:
arduino.readline()


Good luck!
Reply with quote


bhain7

Posted: Thu Feb 28, 2013 5:52 pm
Joined: 13 Feb 2013
Posts: 7
Hah woo! Worked all the way until
Code:
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:
import sys
sys.path.append("C:\Python33\Lib\site-packages")
import serial

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


bhain7

Posted: Thu Feb 28, 2013 6:23 pm
Joined: 13 Feb 2013
Posts: 7
arduino = serial.Serial('COM5', 9600)

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

Smile
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group