3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Super Easy PC Control of 110 Vac using a Crydom Solid-State Relay

Step 2Python Test Code

Below is the magic Python code. Again, can't get much easier than this. I've also attached the code in a file called "Test.py".

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 StepDownload PDFView All StepsNext Step »
8 comments
Aug 21, 2010. 6:13 PMcgrooms says:
Thanks, I fix that problem now I have this error File "temp.py", line 7, in ser = serial.Serial( COM_PORT-1, BAUD, timeout=0.5, rtscts=0 ) File "/usr/lib/python2.6/dist-packages/serial/serialutil.py", line 166, in __init__ self.open() File "/usr/lib/python2.6/dist-packages/serial/serialposix.py", line 175, in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException: could not open port 6: [Errno 2] No such file or directory: '/dev/ttyS6'
Aug 13, 2010. 2:54 AMcgrooms says:
having the same problem getting errors File "test.py", line 8 print "On" ^ IndentationError: expected an indented block
May 4, 2010. 11:38 AMCrimson-Deity says:
I can't get this to work. All I get is a
errors.
May 5, 2010. 8:15 AMCrimson-Deity says:
Thanks for the quick respons ! :D

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.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
54
Followers
16
Author:jimk3038(www.ph-elec.com)
Founder of Powerhouse Electronics. For more info goto: www.ph-elec.com