Character LCD

Review the wiki page at http://wiki.minnowboard.org/Projects/Maker_charLCD for hardware requirements and setup.

The pins for power, ground, and the potentiometer should be self-explanatory. The additional pins are used for the following purposes:

LCD pin 4: Register select - This pin determines what we're passing to the character display. If it's set to LOW, the instruction register is selected for writing flags such as ones to clear the display and set the starting location. If it's set to HIGH, the data register is selected for reading and writing data to the display itself.

LCD pin 6: Enable - This pin needs to be set to HIGH before we can read or write data.

LCD pins 7 through 14: Data - These pins are the 8-bit bi-directional data bus we write the data to. However, we only use 4 of them to preserve pins on the MinnowBoard. We can do this by writing the first 4 bits normally, writing a set of zeros, and then writing the next set.


In [ ]:
# Get all the libraries we need
from pyDrivers.ada_lcd import *
from subprocess import *
from time import sleep, strftime
from datetime import datetime

# Create an instance of the LCD display
lcd = ADA_LCD()

# This complicated command will do a few things:
# 1) Get the network information for the network interface eth0
# 2) Find the lines where inet information is present
# 3) Delete everything but the second element of each line
# 4) Cut everything after the '/' character
 # 5) Edit the stream so that only the first line is left 
cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1 | sed -n '1,1p'"

# This function uses the Python subprocess module to run our command
def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output

# In this infinite loop, run the command and update each second
while 1:
    lcd.clear()
      # Get the address right now
    ipaddr = run_cmd(cmd)    
      # Using some Python functions, we'll get the current data and time,
      # making sure to have the '\n' at the end to go to the next line
    lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n'))
      # On the second line, print our current IP
    lcd.message('IP: %s' % (ipaddr))
    sleep(1)