NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Import Error No Module Named Serial iPhone R/C Car Help

December 06, 2012
by bmanlinehan
bmanlinehan's Avatar

Every time I try to run the pyCar.py script in python it returns this message to me; "Traceback (most recent call last): File "C:UsersBrendanDesktoppyCar.py", line 1, in <module> import serial ImportError: No module named 'serial'

" I tried to install pySerial, but I'm not sure if it installed correctly because I still get this error message. I don't know if its a problem with the microcontroller or something to do with python. This is the code I have currently for pyCar.py:

import serial
#screen size 320x480

maxX = float(480)
maxY = float(550)
s = serial.Serial("COM5", 115200)

def transformPoint(x,y):
    scaledx = (float(x)/maxX)*255 
    scaledy = (float(y)/maxY)*255 
    (left,right) = (capValue(scaledy + scaledx), capValue(scaledy - scaledx))
    return (left,right)

def capValue(val):
    if val > 255:
        val = 255
    elif val < -255:
        val = -255
    return val

def handleNewPoint(command):
    try:
        (x,y) = command.split(",")
        (left,right) = transformPoint(x,y)
        s.write("L " + str(int(left)) + "\n")
        s.write("R " + str(int(right)) + "\n")
        #print " L "  + str(int(left)) + " R " + str(int(right))
        print (' L '  + str(int(left)) + ' R ' + str(int(right)))
    except:
        print ('Error occurred. Ignore and move on')

while(True):
        import pipe
pipe.create('\\.\PIPE\iphonerccarpipe')
print ('pipe.read()')
pipe.write('handleNewPoint')
pipe.close()

P.S. I use Windows 7 64-bit.

December 07, 2012
by Ralphxyz
Ralphxyz's Avatar

Hi Brendan, I cannot really help you with the Python problem except to say I also had problems with Python Serial. Search the forum for "serial" for suggestion on how to test a serial connection.

As far as File "C:UsersBrendanDesktoppyCar.py", line 1, what you really want is:

C:\Users\Brendan\DesktoppyCar.py you get that by escaping the \ with a \\

So you would enter:

C:\\Users\\Brendan\\DesktoppyCar.py

Ralph

December 08, 2012
by JimFrederickson
JimFrederickson's Avatar

I had that problem too...
(At some point...)

You had noted that you are running Windows x64 bit.

Are you running Python 64 bit?

I am nearly certain that the Serial Library for Python is 32 bit only.

You need to be running Python 32 bit and then install the Python Serial Library from the Windows Installer.

I had tried downloading and installing the Python Serial Library from an "all versions download", but like most Software with Linux Foundations there was "alot left to the imagination in their installation docs"... (I guess some may say "left to experience"... Regardless...)

I eventually relented and used the Windows Installer, and an Ubuntu Installer, instead and with those 2 changes all worked perfectly...

(Also I think there are a couple Python Serial Libraries, from different sources, so make sure you have the proper one and make sure it is current and for the version of Python you are using... The 2.x and 3.x version are different "species" ;) )

I use the link:
PySerial

Post a Reply

Please log in to post a reply.

Did you know that interrupts can cause problems if you're not careful about timing and memory access? Learn more...