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

Setting Up Your Pi Cap on the Raspberry Pi 1, 2 or 3
Easy
  • 64
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi 1 A+/B+, Raspberry Pi 2 or Raspberry Pi 3.

Setting Up Your Pi Cap on the Raspberry Pi Zero
Easy
  • 72
  • 2

Protip

Follow this tutorial to set up your Pi Cap with a Raspberry Pi Zero.

Secure Simple Remote Access for Camera Viewing
Easy
  • 2,001
  • 8

Full instructions

Turn your RPi into a full featured camera with remote access, end2end encryption, and easy user enrollment.

PiCorder
Easy
  • 3,606
  • 14

Full instructions

A simple Pi-based camcorder using the very nice HyperPixel touchscreen from Pimoroni.

RPi Serial Console Automation using Arduino
Easy
  • 234
  • 3

Full instructions

A follow-up article to "One Button Restart of a Stalled Raspberry Pi": 3 digital pins provide 8 separate functions that can be called.

Run uTorrent on Raspberry Pi
Easy
  • 467
  • 2

Protip

Step-by-step instruction of running uTorrent on Raspberry Pi 2 using ExaGear Desktop.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login