Things used in this project

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
Can be any version of Raspberry Pi
×1
09590 01
LED (generic)
×1
11026 02
Jumper wires (generic)
×1

Code

findIpMorse.pyPython
Shows the IP address of Raspberry Pi in morse code by toggling GPIO port 21 (BCM).
#!/usr/bin/env python
# Purpose: To toggle a GPIO port that shows IP address of your Raspberry Pi in morse code
# Useful for if you do not have a monitor to use with Pi


import RPi.GPIO as GPIO
import os
import subprocess
import time
import sys


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
LED = 21

GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.LOW)

def main():

    try:
        ip = ''
        time_start = time.time()
        # Constantly searching for valid IP address. Quits if not IP found within 5 minutes
        while ip == '':
            ip = subprocess.check_output("ifconfig | grep \"inet \" | grep Bcast | \
                cut -f2 -d\':\' | cut -f1 -d\' \'", shell=True)
            time_now = time.time()
            time_since_start = time.strftime('%M', time.localtime(time_now - time_start))
            if int(time_since_start) >= 5:
                sys.exit()
        # Initialize morse code variable and strip the ip of all newline characters and spaces
        morse = ''
        ip = ip.strip()
        for num in ip:
            morse += str2morse(num)
        # IP address is flashed in morse code after 3 preliminary flashes
        # IMPORTANT! Short HIGH = Dot (1), Long HIGH = Dash (0)
        # Example: 127 = 10000 11000 00111
        for i in range(3):
            GPIO.output(LED, GPIO.HIGH)
            time.sleep(2)
            GPIO.output(LED, GPIO.LOW)
            time.sleep(2)
        for value in morse:
            if value == '1':
                GPIO.output(LED, GPIO.HIGH)
                time.sleep(0.3)
                GPIO.output(LED, GPIO.LOW)
                time.sleep(1)
            else:
                GPIO.output(LED, GPIO.HIGH)
                time.sleep(1)
                GPIO.output(LED, GPIO.LOW)
                time.sleep(1)

    # If the user presses CTRL-C
    except KeyboardInterrupt:
        GPIO.output(LED, GPIO.LOW)
    finally:
        GPIO.cleanup()


def str2morse(number):
    '''
    This function takes a string input called number (which will only be
    numbers and a period and translate it to morse code
    Dot = 1
    Dash = 0
    '''

    if number == '0':
        return '00000'
    elif number == '1':
        return '10000'
    elif number == '2':
        return '11000'
    elif number == '3':
        return '11100'
    elif number == '4':
        return '11110'
    elif number == '5':
        return '11111'
    elif number == '6':
        return '01111'
    elif number == '7':
        return '00111'
    elif number == '8':
        return '00011'
    elif number == '9':
        return '00001'
    elif number == '.':
        return '10101'

if __name__ == '__main__':
    main()

Credits

Por q e
Aaron Marquez

Electrical Engineering student at SSU. I am interested in embedded systems, iOS app development, and 3D printing.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Test Your Internet Speed Using a Raspberry Pi + Ubidots
Easy
  • 233
  • 4

Protip

Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Chicken Coop Livestream
Easy
  • 2,242
  • 7

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

Raspberry Pi Shutdown / Restart Button
Easy
  • 5,103
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

3d printed case for a RaspPi 3, an Arduino and a 5" display
Easy
  • 280
  • 4

Full instructions

A simple and compact frame to mount a 5" monitor, a Raspberry Pi, an Arduino, and a battery, which is extensible for other sensors.

DIY Raspberry Pi Indoor Outdoor Webcam
Easy
  • 1,346
  • 6

Full instructions

Ever want to monitor your home but don't want to buy a $100 1080p webcam? Well I did, and you can too!

DYI hydroponics system powered by UniPi
Easy
  • 1,339
  • 10

Full instructions

DYI cloud connected hydroponics system powered by UniPi and Cloud4RPi

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog