Sunspot Home

more notes for a bad memory - - -

Using a Raspberry Pi Zero linked to my LAN to drive an 8x40 LED matrix

Scroll a message along the array to report greenhouse temperatures etc,

I could use an Arduino and an Ethernet board - but why bother when a Pi zero has so much spare power?

I connected 5 of these in line - they use MAX7219 driver chips - red only.

MAX7219 8x8 LED matrix

MAX7219 - Raspi

DIN(1) - MOSI (D11)
CLK(13) - SCK(D13)
LOAD(12) - SS(D10)
GROUND - GROUND

Take power for the display from the power source directly
I did not include 3.3 to 5 volt level shifters - it seems to work OK

Next time I would use a 4 in line strip that integrates 4 8x8 displays on one board.


And you can get them with the driver chip on the back - then build any x by y matrix.

SOFTWARE

This bash script will ping the Pi in the greenhouse that is generating the data that I want to display.
(I want to know that the displayed data is fresh)
The result goes into the PI Zero ramdisk for later use by the Blassic basic main program

#!/bin/bash

# /home/graham/8x40LEDmatrix/pingtest.sh

# -q quiet
# -c nb of pings to perform

ping -q -c2 192.168.0.88 > /dev/null

if [ $? -eq 0 ]
then
echo "ok" > /var/www/html/ramdisk2/pingtest.txt
else
echo "fail" > /var/www/html/ramdisk2/pingtest.txt
fi

This bash script grabs the data that the greenhouse Pi stores in it's own ramdisk and puts it into the Pi Zero ramdisk

#!/bin/bash

# /home/graham/8x40LEDmatrix/wget_pool_data.sh

wget -O /var/www/html/ramdisk2/4b0_potpounds_latest.txt http://192.168.0.88:8888/ramdisk2/4b0_potpounds_latest.txt
wget -O /var/www/html/ramdisk2/4b1_tmp36_pool-air_latest.txt http://192.168.0.88:8888/ramdisk2/4b1_tmp36_pool-air_latest.txt
wget -O /var/www/html/ramdisk2/4b2_panel_latest.txt http://192.168.0.88:8888/ramdisk2/4b2_panel_latest.txt
wget -O /var/www/html/ramdisk2/4b3_pool_latest.txt http://192.168.0.88:8888/ramdisk2/4b3_pool_latest.txt
wget -O /var/www/html/ramdisk2/i2c72temp_latest.txt http://192.168.0.88:8888/ramdisk2/i2c72temp_latest.txt

The python program, commandline.py, that accepts a text argument and scrolls it across the LED matrix

#!/usr/bin/env python
import max7219.led as led
import time
from max7219.font import proportional, SINCLAIR_FONT, TINY_FONT, CP437_FONT
import sys
device = led.matrix(cascaded=5)
device.brightness(15)

if len(sys.argv) > 1: device.show_message(str(sys.argv[1]) + " ", font=proportional(CP437_FONT))

This Blassic basic program does the following -

* ping the greenhouse Pi

* run the bash script that gets the data from the greenhouse Pi

* build a string to send to commandline.py to do the text scrolling

#!/usr/sbin/blassic

' /home/graham/8x40LEDmatrix/scroll_pool_data_fast.bas

LABEL StartAgain

SHELL "/home/graham/8x40LEDmatrix/pingtest.sh"
OPEN "/var/www/html/ramdisk2/pingtest.txt" FOR INPUT AS #1 : INPUT #1,pingtest$ : CLOSE #1
IF pingtest$ = "OK" THEN GOTO PingOK
IF pingtest$ = "fail" THEN GOTO PingFAIL

LABEL PingOK
PRINT "ping OK"
SHELL "/home/graham/8x40LEDmatrix/wget_pool_data.sh"

OPEN "/var/www/html/ramdisk2/4b0_potpounds_latest.txt" FOR INPUT AS #1 : INPUT #1,potpounds$ : CLOSE #1
OPEN "/var/www/html/ramdisk2/4b1_tmp36_pool-air_latest.txt" FOR INPUT AS #1:INPUT #1,poolair$:CLOSE #1
OPEN "/var/www/html/ramdisk2/4b2_panel_latest.txt" FOR INPUT AS #1:INPUT #1,panel$:CLOSE #1
OPEN "/var/www/html/ramdisk2/4b3_pool_latest.txt" FOR INPUT AS #1:INPUT #1,pool$:CLOSE #1
OPEN "/var/www/html/ramdisk2/i2c72temp_latest.txt" FOR INPUT AS #1:INPUT #1,i2c72temp$:CLOSE #1

PRINT "potpounds$ = ",potpounds$
PRINT "poolair$ = ",poolair$
PRINT "panel$ = ",panel$
PRINT "pool$ = ",pool$
PRINT "i2c72temp$ = ",i2c72temp$

pipath$ = "/home/graham/MAX7219examples/rm-hull/commandline.py"

pool$ = STR$(ROUND(VAL(pool$),1))
message$ = " pool " + pool$

poolair$ = STR$(ROUND(VAL(poolair$),1))
message$ = message$ + "_air " + poolair$

i2c72temp$ = STR$(ROUND(VAL(i2c72temp$),1))
message$ = message$ + "_garden " + i2c72temp$

potpounds$ = STR$(ROUND(VAL(potpounds$),1))
message$ = message$ + "_honey " + potpounds$

'message$ = message$ + " * Time $(date +'%d/%m %H:%M')"
message$ = message$ + "_Time $(date +'%H:%M')"
display$ = pipath$ + " " + CHR$(34) + message$ + CHR$(34)
SHELL display$

GOTO StartAgain

LABEL PingFAIL
message$ = "PING failed"
pipath$ = "/home/graham/MAX7219examples/rm-hull/commandline.py"
Print "ping failed"
display$ = pipath$ + " " + CHR$(34) + message$ + CHR$(34)
SHELL display$

GOTO StartAgain

SYSTEM

With thanks to rm-hull


Please email me if you want to swap notes

SUNSPOT HOME