20 x 4 LCD’s, Pi’s and Sockets

Even though my life is filled with technology, I still consider myself a minimalist of sorts. Take, for example, the way I chose to display the things I want to track on the PiNet.

I could do it any number of ways. My method of choice is the 4-line, 20-character LCD display. It’s clean, simple and versatile. It provides what I need to see at a glance. Perfect.

To my way of seeing things, the real beauty in this is my ability to send whatever I want from any of the devices in PiNet to the LCDPi’s on the home network. So whatever it is I want to be regularly updated on, I can fairly easily show it on one or more of these little guys.

I currently have three of these stationed around the house. Each one uses some form of Raspberry Pi and I2C to talk to the display.

There is a simple 3D printed base for the Pi and box for the LCD. Held together with stainless steel hardware, the display can tilt to the optimum viewing angle.

I added a button (seen here sticking out the top of the display box) that triggers a shutdown routine for for a clean shutdown.

(Wow. I need to dust my desk.)

Here’s a quick video showing one of the LCDPi‘s in action (no audio, opens in a new tab).

All of the LCDPi‘s run a Python script called socketHost.py. This does what you might imagine, it listens to a predefined port and when it sees the right string come in, it responds appropriately to receive whatever is about to come.

The messages being handled in this use-case are short, so the code is pretty simple:

  • if statements filter received input. These are what I think of as ‘initiating‘ strings.
  • When the input matches one of the predetermined strings, the lines under that corresponding if statement are run.
  • socketHost.py then sets up and receives whatever block of data the transmitter sends, and hands it over to the wxDisplay.py script to be displayed.
  • Once the data is on the display, socketHost.py cycles around to listen again. Because this whole cycle takes place in less than a second, it is very rare to miss receiving an initiating string from one of the transmitters. Because this almost never happens, I don’t worry about it.
  • Brilliant sends out current weather stats every 60 seconds. So the display is refreshed at least that often.
  • DoorPi sends a notification when the garage door opens or closes. When that happens, wxDisplay.py flashes the LCD light three times and displays the data. When Brilliant updates the weather data, the display then gets “reset”.
  • PlayerPi runs MPD, the Music Player Daemon. This feeds audio through a DSP hat to the stereo amp in the living room. I use Cantata on the Windows PC, or MPD Remote on the Android phone to manage the playback.
  • A python module called ‘mpd’ provides ‘MPDClient’, which makes interfacing with MPD a breeze.
    • There is a 120-line script on PlayerPi called show_MPD_on_LCD.py that shoots out Artist, Album, Title and Year data whenever a change of status occurs in the playback.
    • show_MPD_on_LCD.py runs as a service on PlayerPi. It loops once a second or so polling mpdClient for the current status and title. It compares that to variables in memory, and when there’s a change in title or status, it saves that to the “state” pickle file.
  • The Python ‘pickle’ module is used to keep this status file written to the local LCDPi‘s filesystem.

It was a lot of fun to work through all of the educational and functional problems that stood between me and this finished project. Pushing the boundaries of what I know and what I can do with my hands and my mind are what make living worthwhile to me.

Lifelong Learning: another Thing That Works.

The OpenSCAD files for this build are here.

Print Friendly, PDF & Email

1 thought on “20 x 4 LCD’s, Pi’s and Sockets

Comments are closed.