An image of the un-cased RaspberryPi
Hardware Projects Raspberry Pi

RaspberryPI plus LEDBorg plus = Fun with Lights

||||| 0 Like |||||

So, now my Raspberry Pi us up and running there are several questions as to what I can learn with it. One brilliant add on is called the “LEDBorg” by a British Company PiBorg.

This is simply a three colour LED you can control from the Pi’s GPIO pins. It plugs in over the top of the pins and is simple to use. I won’t cover setup and configuration – for that please see

Using the LEDBorg with Gmail and

Now you have your device all setup and configured head over to the original source for this information : Pete Taylor).

Some Changes to Pete’s Code

Pete’s code is an excellent starting point, but what more can you do?

import imaplib
import email

#connect to gmail

mail = imaplib.IMAP4_SSL('')

typ, data =, 'ALL')
for num in data[0].split():
    typ, data = mail.fetch(num, '(RFC822)')
typ, data =, 'ALL')
ids = data[0]
id_list = ids.split()

# get most recent email id
# Any Emails? 
if id_list:
    latest_email_id = int( id_list[-1] )
    for i in range( latest_email_id, latest_email_id-1, -1):
        typ, data = mail.fetch( i, '(RFC822)')
    for response_part in data:
        if isinstance(response_part, tuple):
            msg = email.message_from_string(response_part[1])
    varSubject = msg['subject']
    varFrom = msg['from']
    varFrom = varFrom.replace('<','')
    varFrom = varFrom.replace('>','')
    if len( varSubject ) >35: # Subject to large - turn the light off
        varSubject = '000'
else: #No Emails so turn the light off
    varSubject = '000'

#print the subject to test

print varSubject

#output the subject to the ledborg

LedBorg = open('/dev/ledborg', 'w')
del LedBorg
#Remove used emails from mailbox
typ, data =, 'ALL')
for num in data[0].split():, '+FLAGS', 'Deleted')

This can be downloaded/forked on Gist –

I have added the following extra features to the pre-existing code

1) Added If Else loop to check for empty mailbox and turn LED off if no emails
2) Added Section to empty mailbox after using them

So, this will run every 1 minute check for the latest email and light up the appropriate colour. If there are no emails, it will turn the light off for you.

Future Additions

When I get time I will be adding some extra features that will only turn the light off if you have seen it (an email switch can be sent) and if you have multiple alerts since you have last flagged the emails, it will flash all colours as needed (Flash/Fade)

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.