Colin O'Dell
Published © MIT

Binary IP Address Display for Raspberry Pi

Using a Unicorn pHAT we can easily display the IP address in binary when the Raspberry Pi boots!

EasyShowcase (no instructions)1 hour1,005
Binary IP Address Display for Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
Unicorn pHAT
Pimoroni Unicorn pHAT
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

ip.py

Python
import socket 
import time 
import unicornhat as unicorn 

# From http://commandline.org.uk/python/how-to-find-out-ip-address-in-python/ 
def getNetworkIp(): 
   s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
   s.connect(('google.com', 0)) 
   return s.getsockname()[0] 

# Prepare the Unicorn pHAT display
unicorn.set_layout(unicorn.PHAT) 
unicorn.rotation(0) 
unicorn.brightness(0.5) 

# Obtain our IP address and split it into the 4 components ("octets")
ip = getNetworkIp() 
octets = ip.split('.') 

# Render the binary representation for each octet
y = 0 
for octet in octets: 
 bits = '{0:08b}'.format(int(octet)) 
 x = 0 
 for b in bits: 
   if int(b): 
     unicorn.set_pixel(x, y, 0, 0, 128) 
   x += 1 
 y += 1 

# Render the display
unicorn.show() 

# Keep the LEDs lit for 30 seconds
time.sleep(30) 

Credits

Colin O'Dell

Colin O'Dell

1 project • 34 followers
Lead Web Developer at Unleashed Technologies. Author of league/commonmark. Conference speaker. Arduino enthusiast.

Comments