I was on the market to learn something new. Luckily, there was a nice site online boasting about a RPi set up of sorts for pushing Morse Code via GPIO to a LED.
I jumped in.
Now, I have a board. The BeagleY-AI is the board. It is from beagleboard.org and has a TI chip on it called the Quad-core 64-bit Arm Cortex-A53 CPU that I will be using from Linux and Python3.
Anyway, if you have time to look over their familiar form factor and processing capabilities, you can find more at the listed online link here: https://www.beagleboard.org/boards/beagley-ai
Now, I set up a random LED, red, and a resistor. The resistor needs to be able to handle 3.3v at about 4mA. If we look online, we can find a good bit of data on how to understand what is needed to supply the right ohm resistor for our circuit. Let us look here: https://learn.sparkfun.com/tutorials/resistors/all
Now, if we know our forward voltage and maximum forward current like with this red LED, we can make an assumption...
This assumption would be:
R = resistor
Vs = forward voltage
Vf = maximum forward current
If = our allowed current
So, something like this: R = (Vs - Vf) / If
So, R = (3.3v - 1.8v) / 0.004 = R
R = 1.5 / 0.004 = R
R = 375 ohms
So, a resistor of about 375 ohms should have that LED shinning bright. Also, look to this data from the link from sparkfun.com.
When sizing out a current-limiting resistor, look for two characteristic values of the LED: the typical forward voltage, and the maximum forward current. The typical forward voltage is the voltage which is required to make an LED light up, and it varies (usually somewhere between 1.7V and 3.4V) depending upon the color of the LED. The maximum forward current is usually around 20mA for basic LEDs; continuous current through the LED should always be equal to or less than that current rating.
and...
VS is the source voltage -- usually a battery or power supply voltage. VF and IF are the LED's forward voltage and the desired current that runs through it.
For example, assume you have a 9V battery to power an LED. If your LED is red, it might have a forward voltage around 1.8V. If you want to limit the current to 10mA, use a series resistor of about 720Ω.
So, when we are making decisions on LEDs and resistors, datasheets and not generic datasheets win in the end. Always know what you are dealing with currently (no pun intended).
So, back to fun:
1. Once you have reviewed the Sparkfun site and the BeagleBoard site, flash an image to your BeagleY-AI.
2. There is a nice bb-imager that one can use or use your favorite image writing tool.
3. Once the image has been written, plug in your LED and resistor to an unpowered board. Remember, make your circuit beforehand and then once the circuit is completed, we can then apply power to the board.
4. So, the circuit is a simple one. GPIO to the anode of the LED. The resistor to the cathode of the LED and then the remaining side of the LED goes to GND on the BeagleY-AI.
5. Now, I did a little research about Morse Code. It is interesting. Morse, the fellow it is named after, was not too brilliant with computers for his time (supposedly). He may have not even been that well educated but... He produced the correct cipher of it all to have it all named after him. Anyway...if you have time, look up Morse Code. There is a long history of use cases and ideas involving this specific code.
Now...
Look here: https://github.com/silver2row/remorse
That is my link online for testing Morse Code with the LED and a GPIO pin from the BeagleY-AI. Do you see what works? Do you see what you would change? What works? What does not work?
A-Okay...my favorite script is the smashed together python3 source in the morse.py file which is now found here below:
#!/usr/bin/python3
# Testing Motors Again
# Dictionary from https://www.cl.cam.ac.uk/ and ideas
import gpiod
from time import sleep
CODE = {' ': ' ',
"'": '.----.',
'(': '-.--.-',
')': '-.--.-',
',': '--..--',
'-': '-....-',
'.': '.-.-.-',
'/': '-..-.',
'0': '-----',
'1': '.----',
'2': '..---',
'3': '...--',
'4': '....-',
'5': '.....',
'6': '-....',
'7': '--...',
'8': '---..',
'9': '----.',
':': '---...',
';': '-.-.-.',
'?': '..--..',
'A': '.-',
'B': '-...',
'C': '-.-.',
'D': '-..',
'E': '.',
'F': '..-.',
'G': '--.',
'H': '....',
'I': '..',
'J': '.---',
'K': '-.-',
'L': '.-..',
'M': '--',
'N': '-.',
'O': '---',
'P': '.--.',
'Q': '--.-',
'R': '.-.',
'S': '...',
'T': '-',
'U': '..-',
'V': '...-',
'W': '.--',
'X': '-..-',
'Y': '-.--',
'Z': '--..',
'_': '..--.-'}
def dot():
gpio8.set_value(1)
sleep(0.2)
gpio8.set_value(0)
sleep(0.2)
def dash():
gpio8.set_value(1)
sleep(0.6)
gpio8.set_value(0)
sleep(0.2)
def text_to_morse(text):
morse_code = ''
for char in text.upper():
morse_code += CODE.get(char, '') + ' '
return morse_code.strip()
def morse_to_text(morse):
text = ''
morse_words = morse.split(' ') # Split by triple spaces for words
for word in morse_words:
morse_chars = word.split(' ')
for char in morse_chars:
for key, value in CODE.items():
if value == char:
text += key
break
text += ' '
return text.strip()
gpio8 = gpiod.find_line("GPIO14")
gpio8.request(consumer="BeagleY-AI", type=gpiod.LINE_REQ_DIR_OUT, default_val=0)
try:
while True:
inp = input('What shall we send...?\n')
for letter in inp:
for symbol in CODE[letter.upper()]:
if symbol == '-':
dash()
elif symbol == '.':
dot()
else:
sleep(1)
sleep(1)
text = inp
morse = text_to_morse(text)
print(f"Text: {text}")
print(f"Morse: {morse}")
translated_text = morse_to_text(morse)
print(f"Translated: {translated_text}")
except KeyboardInterrupt:
gpio8.set_value(0)
pass
print("Hey...done for now?\n")
That works or it may work? Who knows really? Have you actually seen your LED blink in the dot-dash format and did you decipher it yet?
We have breaks in the source due to our imported time.sleep module. So, we sleep but what is what? Can you tell?
The GPIO does light the LED in sequence but do our dashes and dots line up to retrieve visually our Morse Code? If not, why? Is so, where do you think it lines up?
Seth
P.S. If you have time and you are loving Morse Code and the BeagleY-AI board(s) for programming and computing, please reply and let me know what you think.
Comments