Have you ever connected your Raspberry Pi to a new Ethernet cable but don’t have a monitor to see its new IP address? Or maybe you don’t want to connect a monitor, keyboard, and mouse to search for the IP address when you don’t plan on using any of the three?
Morse Code
This project will run a Python script on startup that grabs the IP address of your Raspberry Pi and outputs it to a GPIO port through Morse code. Morse code is a method of transmitting text, numbers, and punctuation through on-off tones, lights, or 1’s and 0’s. They are transmitted as short and long “dits” and “dahs” or “dots” and “dashes“.
NOTE: You will need a monitor and/or ssh capabilities to load the code and configure your Pi to run it on startup.
Step 1
Download and/or modify the findIpMorse.py code. Line 51 and 56 has the delays between each dot and dash. You can change these lines if the delay is too short or too long. Place the file somewhere on your Pi.
The Code
The way the program runs is it flashes an LED three times to let the user know that it is running. After the three flashes the Pi then starts transmitting the IP address in Morse code. This includes periods! See video below for an example. The program will run for five minutes continuously searching for an IP address, if none is found then the program terminates.
Step 2
Next you need to create a launcher script that will run every time you turn your Pi on. In this launcher script there is a command that is running the python code. Open terminal in your Pi and type cd to go to your home directory. Next type:
nano launcher.sh
In your newly created file type the following:
#!/bin/shcdcd /home/pathToFile/
sudo python findIpMorse.py
cd
Replace “pathToFile” to the correct path that leads to the directory where findIpMorse.py program is located. For example, my findIpMorse.py file is in a folder on my homepage called “IPFolder” so I would do:
cd /home/Desktop/IPFolder/
Now exit and save the file with CTRL-X, y, then ENTER. Use this command to make the file executable:
chmod +x launcher.sh
Step 3
Next you need to configure your Pi to run findIpMorse.py on startup. Go to the terminal on your Pi.
Before you do that, in terminal navigate to your Desktop (or anywhere) and create a folder called “logs” and a file inside that folder called “cronlog“.
mkdir logs
touch cronlog
This will help you figure out what goes wrong if the program doesn’t run when you turn on your Pi.
Next, type:
sudo crontab -e
Next add this line to the bottom of the file and save it (CTRL-X, y, ENTER):
@reboot sh /pathToFile/launcher.sh >/pathToDesktop/logs/cronlog 2>&1
Replace “pathToFile” with the correct path to the directory where your launcher script is and also replace “pathToDesktop" with the correct path to the directory where your logs directory is located. This line runs the launcher script on startup and also outputs any errors to the cronlog which you can open and view to see if there are any errors or messages.
Step 4
The Pi should be ready to run the code now. This project doesn’t require a lot of setup for the hardware. Just one LED, a breadboard, a resistor, wires, and your Pi.
I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish.ACCEPTCheck Privacy Policy
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.