ExplorerHAT

Adding a display to your Explorer HAT Pro


The Explorer HAT Pro is a great little expansion board which sits on top of the Raspberry Pi GPIO header. It gives you 4 LEDs, touch buttons, digital out- and inputs, analog inputs, a motor driver and a small breadboard on top, so you have an elegant basis to perform some GPIO experiments.

Picture of a Explorer HAT attached on my RPi
The case is one of the excellent PiPow cases, also from Pimoroni; you can find the cases and the Explorer HAT here in their store: Pimoroni Shop

Unfortunately, the HAT uses up almost all GPIO pins and it lacks a display (so far at least; maybe the guys from Pimoroni can add some OLED in the future ?).
So you might come up with the idea to add one of those inexpensive 1602-LCDs, but of course without using too much pins.

Instead of connecting the LCD directly to the explorer hat, we add a shift register 74hc595 in between. Using that, we need only three pins to write data to the 74hc595, which then shifts the data to the LCD. As i don't need them otherwise, i will be using the TX, RX and PCM pins from the explorer hat pro for this purpose.

Wiring connections to the 74hc595:

pin 1 (Q1) to LCD pin 6 (E)
pin 2 (Q2): to LCD pin 11 (D4)
pin 3 (Q3) to LCD pin 12 (D5)
pin4 (Q4) to LCD pin13 (D6)
pin 5(Q5) to LCD pin14 (D7)
pin 6, pin 7 N/C
pin 8 to GND
pin 9 N/C
pin 10 (MR) to 5V
pin 11 (SH_CP) to PWM
pin 12 (ST_CP) to RX
pin 13 (OE) to GND
pin 14 (DS) to TX
pin 15 (Q0) to LCD pin 4 (RS)
pin 16 to 5V



Here is the layout:



I'm using two 5k Poti's for adjusting the backlight intensity and the contrast.

Beware: the TX socket on the Explorer HAT is connected to the RX GPIO pin from the Raspberry Pi and vice versa! (at least on my board)
 So if you want to output something at TX, you have to use GPIO BCM 15, for RX use BCM 14!


Now up to the software: All we need here is the wiringPi library from Gordon Henderson[wiringPi library]. Follow the instructions on his site to install the wiringPi library on your RPi. We will also need the python-wrappers for wiringPi, which can be found here: https://github.com/Gadgetoid/WiringPi2-Python.
The wiringPi library already has extensions for the LCD and also for the shift register, so we just need to put in the right pin values to access the LCD through the shift register:

#!/usr/bin/python
#
# short example to access a LCD with a HD44780 controller througha shift register 74hc595
#  (c)  2015 Frank Seliger
#

from wiringpi2 import *
from subprocess import *
from time import sleep, strftime
from datetime import datetime

wiringPiGpioSetup() #use wiringPi pin scheme

#assign values to 595's pins
pinBase = 100
RS =  pinBase + 0
E =   RS + 1
DB4 = E + 1
DB5 = DB4 + 1
DB6 = DB5 + 1
DB7 = DB6 + 1

# Pi's pin out using GPIO scheme
dataPin, clockPin, latchPin = 15, 18, 14

#                          pin @ Q0, num pins used, SER    , SRCLK   , RCLK
sr595Setup (pinBase , 6 , dataPin, clockPin, latchPin)

# Now, let's handle the HD44780 ...
# RS, E, DB4, DB5, DB6 and DB7's signals are coming out of the 595
lcd = lcdInit (2, 16, 4, RS, E, DB4, DB5, DB6, DB7, 0,0,0,0)
lcdHome(lcd)
lcdClear(lcd)
lcdPosition(lcd, 0, 0)
lcdPuts(lcd, "Hooray !")
lcdPosition(lcd, 0, 1)
lcdPuts(lcd, "HAT-LCD working")

sleep(5)

cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"

def run_cmd(cmd):
        p = Popen(cmd, shell=True, stdout=PIPE)
        output = p.communicate()[0]
        return output

while 1:
    lcdClear(lcd)
        ipaddr = run_cmd(cmd)
        lcdPosition(lcd, 0, 0)
        lcdPuts(lcd, datetime.now().strftime('%m-%d  %H:%M:%S'))
        lcdPosition(lcd, 0, 1)
        lcdPrintf(lcd, '%s' % ( ipaddr ) )
        sleep(2)


And here is the result:





No comments:

Post a Comment