Please follow the instruction from Adafruit to prepare your RGB LCD Shield.
http://learn.adafruit.com/adafruit-16×2-character-lcd-plus-keypad-for-raspberry-pi
After essambling your Adafruit LCD Shield kit and downloading all the necessary requirements to run it with I2C.
A few complaints about 0x20 address cannot be accessed via I2C. Make sure you change your bus number in all python code referencing the bus from 0 to 1 if you are using Wheezy 512MB Raspberry.
You can try this code to display your Raspberry Pi IP address. Modify code supplied by Adafruit called LCDtest.py by adding IP reading capabilities.
cp LCDtest.py LCDIP.py
sudo nano LCDIP.py
#!/usr/bin/python
from time import sleep
from Adafruit_I2C import Adafruit_I2C
from Adafruit_MCP230xx import Adafruit_MCP230XX
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
import smbus
import socket
# initialize the LCD plate
# use busnum = 0 for raspi version 1 (256MB) and busnum = 1 for version 2
lcd = Adafruit_CharLCDPlate(busnum = 1)
# clear display
lcd.clear()
# hello!
lcd.message(“Adafruit RGB LCD\nPlate w/Keypad!”)
sleep(1)
# first loop, just changes the color
lcd.backlight(lcd.RED)
sleep(.5)
lcd.backlight(lcd.YELLOW)
sleep(.5)
lcd.backlight(lcd.GREEN)
sleep(.5)
lcd.backlight(lcd.TEAL)
sleep(.5)
lcd.backlight(lcd.BLUE)
sleep(.5)
lcd.backlight(lcd.VIOLET)
sleep(.5)
lcd.backlight(lcd.ON)
sleep(.5)
lcd.backlight(lcd.OFF)
sleep(.5)
def getifip(ifn):
import socket, fcntl, struct
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(sck.fileno(),0x8915, struct.pack(‘256s’, ifn[:15]))[20:24])
print socket.gethostbyname(socket.gethostname())
my_ip = getifip(‘wlan0’)
print my_ip
while 1:
if (lcd.buttonPressed(lcd.LEFT)):
lcd.clear()
lcd.message(“Red Red Wine”)
lcd.backlight(lcd.RED)
if (lcd.buttonPressed(lcd.UP)):
lcd.clear()
lcd.message(“Sita Sings \nthe blues”)
lcd.backlight(lcd.BLUE)
if (lcd.buttonPressed(lcd.DOWN)):
lcd.clear()
lcd.message(“I see fields\nof green”);
lcd.backlight(lcd.GREEN)
if (lcd.buttonPressed(lcd.RIGHT)):
lcd.clear()
lcd.message(“Purple mountain\n majesties”);
lcd.backlight(lcd.VIOLET)
if (lcd.buttonPressed(lcd.SELECT)):
lcd.clear()
lcd.message(“My wlan0 IP is:\n%s” % my_ip)
print “My wlan0 IP is:\n%s” % my_ip
lcd.backlight(lcd.ON)
Save and exit, then run it
sudo python LCDIP.py
Click the shield’s ‘select’ button to display the IP address like this.
[post_view]
3 thoughts on “Displaying your Raspberry IP address on Adafruit RGB LCD 16×2 Shield”
Comments are closed.
Wouldn’t it be better to use python’s netifaces library to get the ip?
Can you give us code example?
I found it here: http://stackoverflow.com/questions/6243276/how-to-get-the-physical-interface-ip-address-from-an-interface