Find IP Address via Morse Code

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?

gaming-bot

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“.

 gaming-bot

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/sh
cd
cd /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.

Read More: Find IP Address via Morse Code


About The Author

Ibrar Ayyub

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.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top