Introduction: Morse Code Using Raspberry Pi and LED!
This will get you started with the GPIO pins on the Raspberry Pi, using an API, and, of course, blinking morse code! After you have completed this tutorial, you can for example learn all morse code characters, blink your IP address at startup or blink "Hello, world"!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Material You Will Need
To follow this tutorial, you will need:
1x Raspberry Pi (obviously)
2x Wires (it is best to use jumper wires to connect to the GPIO pins)
1x Resistor from 270 to 330 Ohm
You will get all of this at your hardware store. If you don't find everything, try looking for a different hardware store or buy it online on sites such as Amazon.
Step 2: Building the Circuit
So, now that you have all of the necessary material, let us get to building the actual circuit. First, you have to understand how a breadboard works. A breadboard is used to prototype actual circuits and it is very versatile. On the breadboard, the inside lines connect horizontally and the outside lines, which are called power lines, are connected vertically. If you are confused about the connections, check out the picture with the arrows.
Now that you understand how a breadboard works, let us start:
1. Have a look at the circuit diagram I made.
2. Strip the ends of two pieces of wire (if you have normal wire, not jumper wire).
3. Arrange one end of each wire on both of the inside lines of the breadboard. The left side will be negative and the right positive.
4. Put one end of the resistor on the left (negative) side and make sure it is on the same horizontal line as the stripped end of the soon-to-be negative wire.
5. Put the other end a few holes further down (vertically), on the same horizontal line as your LED will be.
6. Stick it in! Stick the short leg of the LED on the same horizontal line (on the same side) as the end of the resistor and stick the longer leg in another hole across the gap.
7. Put the soon-to-be positive wire on the same horizontal line as the long leg of the LED. Note, right (positive) side of the gap.
8. Boot up your Raspberry Pi
9. Connect the negative wire (left side) to one of the Ground pins (have a look at the image for your respective Raspberry Pi GPIO header)
10. Connect the positive wire (right side) to the Pin #1 to test if your circuit works.
11. The LED will blink! Success! If not, make sure you wired everything correctly and, if it still does not work, ask for help in the comments.
12. Connect your positive wire to GPIO18. We will use this GPIO pin to turn the LED on and off for use with morse code.
13. Don't fret if you did not follow along with everything I said, I have a nice photograph of the finished circuit just for you (look in the Photos)!
Note: If you were wondering about the photos on the Raspberry Pi end, I used some old plastic tube over the wire to make it fit securely onto the RPi headers. Something like a cheap DIY jumper wire!
Step 3: Now for Some Morse Code...
So, we now have successfully made our circuit with our trusty old breadboard and now it is time to dive into the world of morse code! Let us start, shall we?
1. SSH into your Raspberry Pi. To do this:
On Windows: Download and install Putty for Windows. Input the IP address of your Raspberry Pi and, as default, the port for SSH is 22. Finally, click connect and then input the password (standard password is "raspberry").
On Linux: In a terminal, type "ssh -l pi ". Don't be alerted when it asks you to add the host key of the remote host, just type yes, and then input the password (standard password is "raspberry").
2. SSH'd into your Raspberry Pi, type "gpio" to check if the GPIO shell program is there.
3. Clone my Git repository. To do this, type "git clone https://github.com/fabiensonpar/Morse_code_RPi"
4. Change the directory to Morse_code_RPi. Type "cd Morse_code_RPi"
5. Take a look at sample.c. Type "nano sample.c". Here you can see, well documented, all the functions necessary to setup the gpio shell script and blink numbers. You can also blink IP addresses with the additional help of blinkperiod()!
6. If you want to, you can change the number or the character array to be blinked in morse code. But don't forget to adjust the number of digits (the second argument of "blinknumber()") if you want to change the number!
7. Press Ctrl-X to exit nano.
8. Compile the sample with "gcc -o sample sample.c".
9. Run the sample with "./sample"! So exciting, right?
10. Now, my friend, write down the dots (0.5 seconds long), dashes (1.5 seconds long) and at pauses (1.5 seconds long), begin a new line or write "/".
11. Finally, reference the dots and dashes with the chart above. I know, I know you don't need the chart because you're a pro, am I right?
12. Think of all the cool things you could do with this. For example, you could make your Raspberry Pi automatically blink its IP address or blink "Hello, world" at startup! That would be very cool!
I hope you liked my tutorial and have learned something impressive!
Gangnamstyle137 signing out.