Step 1: Mail Light Parts
- a USBmicro U421 USB interface
- a ULN2803 driver
- a bit of circuit board
- 8 LEDs
- 8 330 ohm resistors
- a small plastic box
- 8 LED mounting rings (optional)
- wire-wrap wire for point-to-point circuit connections
- a small 4-40 machine screw
- an aluminum bar
- solder, solder flux
Various tools are appropriate and include (but are not limited to):
- a screwdriver
- a nutdriver (for the connection to the back of the monitor)
- a soldering iron
- a 4-40 tap (if you tap the bar - optionally use a nut)
- a vise with a brake for bending
- drill and bits for plastic box holes and hole in bar
- flush cutter
Step 2: Plastic Box
Step 3: Inside of Box
Step 4: Altering the Plastic Box
The idea is to get that bit of plastic out of the way. Snipping it off was rough, but worked well. The the rough remainder was carefully sliced away.
Step 5: Drilling Holes
Mounting rings are optional. The LED's holes can be sized right to work without the rings.
Step 6: Printed Circuit Board (PCB)
Step 7: Cleaning the PCB Copper
Step 8: Cut the PCB to Fit
Step 9: Adding Components
Step 10: PCB From Under
The LEDs that I picked for the project are each a unique color. I’ll assign an email account to an LED that will flash on each side of the box.
The LEDs are easy to mount in a 1/4″ hole when these little mounting rings are correctly employed.
Step 11: LEDs Mounted in Box
With the LEDs in place, and the PCB navigated onto all of the LED leads, the LEDs are then soldered in place.
Step 12: Soldering Connections
The USBmicro site had a guideline for driving an LED from the output pin of a U401 or U421. Extending that to use a ULN2803 for this project was easy. One of the app notes at USBmicro also has a ULN2803 driving LEDs and relays. Both schematic fragments are pictured below to serve as a guide.
Step 13: Testing the Electronics
The finished eMail Light electrical hardware is assembled and tested with the output test application from USBmicro.com.
Step 14: Mointing the Mail Light
The bar needed a short 1″ section bent. This I did by putting the bar in a vise brake.
The bent section of the aluminum bar will be screwed to the plastic box.
On the bent 1″ section of the bar I tapped a #4-40 hole. One half of the plastic box – the half without parts – will have a little hole in it for the screw. I also drilled holes of appropriate size and spacing on the long part of the aluminum bar for mounting on the back of my LCD monitor.
The plastic box half was tightly attached to the aluminum bracket and then the box was reassembled.
Mounted under my monitor and plugged in to USB, I was able to use the USBmicro output test application to verify that the regular LEDs were visible from a sitting position at my desk, and that the super-bright LEDs facing “back” were easily visible in my lab.
Step 15: REALBasic Software Development
The goal of the software that I created was to connect to four different email accounts and monitor them for the presence of email. If email was found, a specific LED associated with that account should blink. The LED blinking rate should be changeable, the rate at which the email accounts are polled should be changeable, and the program should hide as a tray icon until needed.
Each of the four accounts has a quarter of the main window with a few text areas for account information. The quarter is pictured below.
Step 16: Software Details
Each account has a connect button for enabling that account. When connected, the email account is scanned for email. To the right of the connect button is a visual indicator that will blink in unison with the LED. To the right of that is a text field that shows the number of messages that are on the server of that account.
The box marked “server” should contain the server address. Something like “pop.flintstone.com”. This would need to be the right server for your email account. Below that is the name that you use to log in to your account. It might be “fred” or it might need to be “email@example.com”. Under that is the box for your password. It is a field that shows up as asterisks. My password happens to be: ******* :-)
Under the password field is a box that contains the rate, in minutes, that the email address is queried. Below that are two connection status boxes.
The other three email addresses are repeated.
To the lower right of the main window there is a box for the blink rate in 1/100 of a second. A value of 50 is a 1/2 second blink rate. Above that is a button to exit the program.
On the upper right of the main window is a button to hide the main window. A double-click on the program’s tray icon will expose this main window again. Everything keeps running with the main window hidden.
When the program is run, it needs to build up a tray icon and set that tray icon to a graphic (in this case called cg4) that is included with the project: (see pic)
When the program is closed, that icon needs to be removed from the tray: (see pic)
The app tray object itself has only the task of making the main window visible when the user double-clicks on the tray icon: (see pic)
The hide button on the main window just makes the main window not visible: (see pic)
When the main form is made visible for the first time that the program is run, the U421 USB interface is discovered and the defaults for the program are loaded. Communication with the U421 is done through a DLL that is opened by REALbasic when the function inside that DLL is defined. The code first declares the three functions needed (and creates a return value for the function call) before using the functions: (see pic)
USBm_FindDevices is the first call to USBm.dll. It searches the PC’s USB bus for U401 and U421 devices. In this simplified example code the true/false return code is not used. Non example code would want to process the return values for error. Port A of the U421 is set to output with this call: USBm_DirectionA(0, &HFF, &HFF). The 0 assumes that there is only 1 (indexed to 0) USBmicro device on the bus. If there were more, then additional code would be necessary to address the correct device. See the USBmicro information in the On-line Development Notebook (ODN) for all of the port direction command information.
Once the direction is set to output, all lines are turned off (0) to disable the LEDs: (see pic)
After that a file called “maildata.txt” in the same folder/directory as the executable maillight.exe is searched for. Again, in a program other than example code, more code should exist to handle errors such as the file not being found.
The file contains text information that is read into the text boxes in the main window. The first line of the file should contain the server name for Email 1, the second line should have the user name, etc. The last line has the LED blink rate. The comments in the code show the format: (see pic)
The file is opened and each line read into appropriate text boxes: (see pic)
The LED blink rate is the last of the edit field elements that are loaded on start up by loading this file. Changing the values in the text fields after the file is loaded is also possible by editing those boxes.
Step 17: Intermission
Step 18: More Software
The simplest component is the timer that goes out to get mail every couple of minutes. There is a timer for each of the four mail accounts. When the timer times out, it simply calls the pop3 object and tells it to connect:
After the connection is established, the pop3 object prints that status in the first status box. After it connects, then a login is attempted. When the login is successful, the number of messages that are on the server is counted:
The pop3 object counts the number of messages on the server and displays that number. If the number is 0, then a boolean variable is set to false. If there is 1 or more messages, then that variable is set. That variable determines that the LED will be blinking. After counting the number of messages, the pop3 object disconnects and clears the status text:
The timer that checks for mail doesn’t run until the connection is made for the fist time with the press of the connect button. When the button is pushed, the server, user name, and other data is passed to the pop3 object and a connection invoked. The timer is started (for next email checking time) and the button is changed from a connect button to a disconnect button:
If that same button is clicked after it has been toggled to be a disconnect button, then the pop3 object is disconnected from the server (if still connected), the timer is turned off, status cleared, the LED blinking is disabled, and the button again becomes a connect button:
This isn’t an email program – you don’t get to read the email that you have with this program – you are just notified that you have email waiting on your server. After you are notified that you have email, you would go get those emails with your email program. The LED will likely still be blinking after you get the email with the other program. Clicking the button to disconnect and reconnect will start another check and discover that your email had been cleared.
The LED blinking routine is actually the longest of all of these functions. When the blink timer times out, the USBmicro DLL stuff is defined. The value for the LED port of the U421 (port A) is set to 0 before accumulating the status of the email accounts:
The blink timer toggles the graphic indicator (and eventually the LED) on and off every other time that the timer times out. A boolean variable is flipped from true to false every other time. When false, the indicator is off. When true the indicator is on if there has been a message detected. And if the indicator is on, then LEDval is set to turn on a bit for turning on a specific LED:
The first LED on the front and the first LED on the back are turned on with the value of &H11. The 2nd LEDs with the value of &H22, the third with a value of &H44, the 4th with &H88.
Once these values are all combined, then the value is sent to port A ov the U421:
Download the REALbasic project and the executable code: eMailLights Project and program.
To set this up for your email, edit the maildata.txt file to include your four (or fewer) email settings. When you run the program, these settings are loaded. You can leave the password as a blank line if you don’t like having a password in this file.
Click connect on all of the accounts that you will use to start the mail checking process. Click hide to hide the window to the tray icon. Recover the main window by double clicking on the tray icon.
When the program discovers an email in the accounts that it checks, the visual indicator will flash. If you have built the Mail Light hardware, then you will see flashing LEDS.
There is a lot of flexibility in the LEDs/lights that you can put together for this project. Originally I had planned to put a stack of ping pong balls on the top of my monitor to light up with some LEDs. This looked great in a dimly lit room and in the evening. But with my office window open, the ping pong balls just were not light enough against the open window to see from my lab.
Code could be changed to do more than just light LEDs. You could attach an LCD display to the U421 that would display, in text, the number of emails that are in each account. The U421 could directly drive a pair of seven-segment LED displays. You could use multiple U421 with a combination of hardware designs.