<
Testing the program and circuit
At this point you can upload the Arduino sketch from my original post. If successful, you shouldn’t really see much of anything happening.
Now the fun bit – open the serial monitor in the Arduino software and type the number 3, then press return. If everything works, 3 of your LEDs should light. Now type 1, 2, 4, 5 or 6. Each time the relevant number of LEDs should light.
The next step is to run the Python script that will drive those numbers – 1, 2, 3, 4, 5, 6 – from your email inbox rather than directly from your keyboard. Download the Python environment and the pySerial serial port extensions and install both following the instructions. Then simply run the Python script from my original post (you may have to change the COM6 value to another number depending on your PC, and you’ll have to enter your Gmail user and password) and, with a bit of luck, you should have the LEDs updating directly from the number of unread emails in your inbox. It’ll probably take a bit of fiddling to get it working, but if you get stuck please feel free to ask me in the comments.
Congratulations, if you’ve reached this point you’ve got the project 90% working. The chip we left out earlier is called an Optocoupler (aka Opto-isolator) like this and it’s job is to basically switch other stuff on and off. It does this using light, so there’s no electrical connection between the two devices (so, in theory at least, the clock can’t blow up the Arduino or vice versa).
If you want to finish the project, just pop in this chip where shown on the diagram and hook up the switch you want to open/close to the other side. In my case I used the wires going to the ‘demo’ button on the clock, but you could just as easily control a button/switch on almost any low voltage (battery powered) device.
Good luck, and please share your results!!!
Grant:
Nice hack, and thanks for the how-to write-ups.
One detail I can’t seem to find: how you actually hook up the serial connection? The Nano doesn’t have RS232, and many PCs / most Macs don’t have serial ports (only USB), so I’m a little puzzled how you did the serial connection.
I generally use an RS232 converter on the Arduino end and a USB-Serial cable on the Mac end, but it would be nice to eliminate the cost of those two pieces in deployed projects…
Thanks,
Larry
http://www.sector67.org
Madison, WI USA
LikeLike
@Larry – thanks for getting in touch.
My first experience of Arduino was with the Duemilanove (2009) and since with the Nano and Uno. All of these boards have built-in serial port emulation over USB.
With the Due and Nano it’s necessary to install the FTDI drivers to get the serial bit working and with the Uno it seems to be an automatic part of the Uno driver installation.
So… my setups always go like this:
1. Plug in the Arduino using a standard USB cable
2. If I’m using Windows, go into Device Manager, then open the Ports section. Where Arduino is listed it will have the virtual com port in brackets, e.g. Arduino Uno (COM 6)
…on a Mac or Linux there’s another way to find out which I can’t remember, but the principal is the same.
3. In my script, be it Python, Perl or Actionscript, plug in that COM port number and it just works as if it was a real COM port, no additional hardware required.
Hopefully that method will work for you too, but if not please let me know more and we’ll see if we can solve it together.
Grant
LikeLike
Grant:
Thanks for sketching out the FTDI and USB cable details. After I hit send, I realized it was likely something as you described but thanks for sketching out the details for the record and for less experienced Arduinoids…
Larry
LikeLike
My python script is giving the Following error:
Traceback (most recent call last):
File “C:/Python25/Hellow World.py”, line 5, in
ser = serial.Serial(‘COM2’, 9600)
File “C:\Python25\lib\site-packages\serial\serialwin32.py”, line 30, in __init__
SerialBase.__init__(self, *args, **kwargs)
File “C:\Python25\lib\site-packages\serial\serialutil.py”, line 260, in __init__
self.open()
File “C:\Python25\lib\site-packages\serial\serialwin32.py”, line 56, in open
raise SerialException(“could not open port %s: %s” % (self.portstr, ctypes.WinError()))
SerialException: could not open port COM2: [Error 5] Access is denied.
>>>
COM2 is the correct port and arduino is plugged in. Any ideas?
LikeLike
Update: I needed to run the script as I was plugging in the arduino.
LikeLike
@Peter – thanks for the update. Can I assume from this that you’ve got it working now? If so, congrats!
One question: is it always necessary for you to run the script immediately after plugging in the Arduino? If so it sounds like some other process on your machine is somehow opening the COM2 port and then keeping it… maybe some system monitor / firewall / AV software? Anyway, I guess if you’ve found a workaround that’s probably good enough.
Cheers,
Grant
LikeLike