Step 2Python Test Code
import sys, serial
from time import sleep
COM_PORT = 7
BAUD = 9600
ser = serial.Serial( COM_PORT-1, BAUD, timeout=0.5, rtscts=0 )
# Toggle the DTR pin on for 15 seconds, then off for 5 seconds.
while ( 1 ) :
print "On"
ser.setDTR( 1 )
sleep( 15 )
print "Off"
ser.setDTR( 0 )
sleep( 5 )
Test.py329 bytes| « Previous Step | Download PDFView All Steps | Next Step » |






































Python is kinda weird, in that, it's really picky about indenting in the source code. It drives Python crazy if you happen to indent with tabs and spaces within the same file. Either use spaces, or tabs, but never both in the save file. Some of the better editors have the ability to show tabs with special visible characters. Using this special mode you can verify you have not mixed spaces and tabs. To execute a block of code within some loop like a "while" loop, Python looks for an extra level of indention. The syntax would look like the following.
while 1:
print "Hello World"
This loop would print forever to the console simple because "print" is indented under the "while" statement.
Help this helps,
Jim
errors.
I have never, ever programmed ANYTHING before so I'm a noob to the max. Could you make a tutorial on how to use Python? I tried to copy and paste the "Test.py" content into the IDLE Python text thing, but some sort of error occured. My laptop is somewhere out of my reach at the moment so ill post a picture ASAP.
Anyway, step number one - go out and buy two books. Learning Python and Python Cookbook. These are really good to get you jump started. I've attached a picture of my two books. You can see my books are kinda beat up - that is a good sign - means the books are used a lot!
Next, try to run my little code block. I'm guessing your missing the extra serial port package. Python does not have support for serial ports by default. No problem - go back to my instructable and download the extra installer for the serial port package. This package adds serial port control to Python.
Next, run each line of code in IDLE. IDLE will tell you when you hit a problem. But, once you install the serial port package I guessing you won't have any problems.
Good luck,
Jim