Following on from the inspiration provided by Michael at MitchTech, who described a Physical Email Notifier using the RPi, latterly picked up by the good folks at Adafruit, I mixed in some Morse ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Morse_Gmail.py | |
m0xpd | |
December 2012 | |
""" | |
import feedparser, time, sys | |
import RPi.GPIO as GPIO | |
""" Dictionary for Morse Characters... """ | |
morse={'a':'01','b':'1000','c':'1010','d':'100','e':'0','f':'0010','g':'110', | |
'h':'0000','i':'00','j':'0111','k':'101','l':'0100','m':'11', | |
'n':'10','o':'111','p':'0110','q':'1101','r':'010','s':'000','t':'1', | |
'u':'001','v':'0001','w':'011','x':'1001','y':'1011','z':'1100', | |
'0':'11111','1':'01111','2':'00111','3':'00011','4':'00001', | |
'5':'00000','6':'10000','7':'11000','8':'11100','9':'11110', | |
'.':'010101',',':'110011','?':'001100','/':'10010','@':'011010',' ':'','(':'',')':''} | |
# Adjust Morse Speed by changing DitLength ... | |
DitLength=0.1 # (seconds) | |
DahLength=3*DitLength | |
# Set Up the GPIO... | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setwarnings(False) | |
GPIO.setup(11, GPIO.OUT) | |
GPIO.output(11, False) | |
# a few function definitions... | |
def SendDit(Length): | |
""" Sends a Dit...""" | |
KeyDown(Length) | |
Last_Element="dit" | |
return Last_Element | |
def SendDah(Length): | |
""" Sends a Dah...""" | |
KeyDown(Length) | |
Last_Element="dah" | |
return Last_Element | |
def SendSpace(Length): | |
""" Wait for inter-element space...""" | |
time.sleep(Length) | |
return | |
def KeyDown(Length): | |
""" Keys the TX """ | |
# set the output to Key Down... | |
GPIO.output(11, True) | |
time.sleep(Length) | |
# clear the output ... | |
GPIO.output(11, False) | |
return | |
# Insert your Gmail account details here... | |
USERNAME="xxx" | |
PASSWORD="xxx" | |
# Main Operating Loop... | |
while True: | |
response=feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom") | |
unread_count=int(response["feed"]["fullcount"]) | |
for i in range (0,unread_count): | |
name=response["items"][i].author | |
first_name=name[0:name.find(" ")] | |
for j in range (0,unread_count): | |
full_name=response["items"][j].author | |
name=full_name[0:full_name.find(" ")] | |
for i in range(0,len(name)): | |
morse_character=morse[name[i].lower()] | |
for element in range(0,len(morse_character)): | |
if morse_character[element]=="0": | |
junk=SendDit(DitLength) | |
SendSpace(DitLength) | |
else: | |
junk=SendDah(DahLength) | |
SendSpace(DitLength) | |
SendSpace(DahLength) | |
time.sleep(1) | |
time.sleep(60) |
You saw earlier how this can flash an LED or key a transmitter. You could use the same open-collector interface to switch a buzzer / sounder to let you hear the Morse.
The code uses a neat feature of Python (and other languages too, for all I know) to make the mapping between alphanumeric characters and their Morse representation: "Dictionaries". These were a new discovery for me yesterday - makes learning new programming languages actually worthwhile!
I generate a string of 0's and 1's for each Morse character; 0 for a dit and 1 for a dah. The rest is pretty self-explanatory.
You'll need to edit the code to insert your username and password - I don't want you reading my emails!
The code tries to announce only the first name of the sender (by searching for the first space in the "author" field). If there isn't such a space, it will just encode the entire author string as Morse - even including the new "ac" bigraph for "@".
As well as trying to get "GISTS" running on this post, I also uploaded both the Gmail Notifier and the iambic keyer Python code to a site for your easy downloading convenience...
The Gmail notifier is available here
The iambic keyer is available here
Enjoy!
...-.- de m0xpd