NHL Bedside Hockey Light and LCD

778

9

3

Published

Introduction: NHL Bedside Hockey Light and LCD

Introduction

The "NHL Light" is for hockey fans who want to follow their team, but cannot watch every game. It's best feature is that it simulates a goal score with a hockey horn (custom to your team), and light.

In addition to the hockey horn and light, the "NHL Light", has a display that provides current, or most recent game's score, game time or time of next game, and current date and time.

The "NHL Light" runs on a simple list of parts, that is easy to assemble electronics, and code that is freely available.

Features

  1. Webpage based configuration for selecting your team and wifi
  2. Plays light and horn when your team scores (even when you are the away team)
  3. Plays sound to announce beginning of the game
  4. Plays a sound to announce conclusion of the game
  5. Provides time and date of next game, if no game in progress.
  6. Displays the current game time and period, if game is in progress.
  7. Displays current date and time.

Step 1: Step 1: Assemble Your Parts

Here is a parts list.
  1. Raspberry Pi W*
    1. Amazon
    2. I prefer to get mine from Microcenter, but can be found online for less at other places.
    3. $10
  2. SD Card (4gb minimum)*
  3. speaker - Amazon - ~$2 *
  4. amp - PAM8403* - Amazon - ~$1 each
  5. light - Amazon - ~$5
  6. Case - $1*
    1. Michael's
    2. I recommend small wooden craft case from Michael's craft store, but will leave to you!
  7. I2C 2004 LCD - $3-7
    1. Amazon
    2. The code supports 3 types of LCD's, but I2C 2004 is the one I have settled on as best value and size. (SSD1306 is also possible)
  8. 2 transistors - 2N2222A- Amazon
  9. Misc Wires / solder12V
  10. power supply - Amazon
  11. 12V -> 5V buck converter - Amazon

*There is flexibility when it comes to selecting this part.

NOTE: You can start on most of this project with just your raspberry Pi, while you wait for other items to ship.

Step 2: Step 2: Wiring and Electronics

  1. Assemble Light
    1. The wiring for the light is to run 12 + to the light.
    2. Run negative from the light through one of the transistors.
    3. The emmetter of the transistor goes to ground.
    4. The collector of the transistor goes to the Raspberry Pi.
  2. Assemble sound
    1. Run right or left sound from PI to the amp
    2. Run +5V to the amp
    3. Run amp ground to the 2nd transistor.
    4. Run the emmetter of the 2nd transisitor to ground
    5. Run collector of the transistor to the Raspberry Pi
  3. Assemble wiring to the PI
  4. This is the pinout instructions for the PI (some of these are configurable via the JSON)
    1. LCD
      1. 3 - SDA
      2. 5 - SCL
      3. 5 - VCC (+5)
    2. AMP 8 (GPIO 14)
    3. Light 10 (GPIO15)
    4. Sound Right - GPIO 18

Step 3: Step 3: Operating System Software Setup

  1. Prepare the Raspberry Pi W
    1. The rasberry pi must be running a recent version of Raspbian (or other Debian).
    2. Recommended to follow these instructions: https://hackernoon.com/raspberry-pi-headless-inst...
    3. Be sure to include wifi wpa_supplicant file.
    4. Put ssh file on the sdcard to allow ssh access.
  2. Prepare the 3rd party software:
    1. I've automated this process to pull all needed 3rd party tools, but feel free to run these manually, and review to make sure no steps fail.
    2. Download and run the following script:

      https://github.com/wga22/nodejs/blob/master/nhl/mi...

Here is a breakdown of what the installation script for setting up the operating system does. It is best to run these lines manually, so you can watch for errors.

Script Header:

#!/bin/sh -e
#can be called via #curl -sL https://raw.githubusercontent.com/wga22/nodejs/ma... | sudo -E bash - # TODO: automate this script with something like: curl -sL https://raw.githubusercontent.com/wga22/nodejs/ma... | sudo -E bash - # TODO: setup wifi # TODO: setup passwd and authorized keys # notes: https://raw.githubusercontent.com/wga22/nodejs/ma...

Update software at the OS level:

#apt-get stuff
(apt-get update && apt-get -y upgrade) > /dev/null apt-get dist-upgrade -y #General Dev apt-get install -y git build-essential python-dev python-pip python-smbus libasound2-dev nodejs # GPIO apt-get install -y raspi-gpio python-imaging python-smbus libasound2-dev #networking apt-get install -y bridge-utils hostapd dnsmasq apt-get clean -y

Networking setup. Part of the goal here was to allow system to be configured via an access point, to connect to your own wifi, but this has not been fully tested as of yet. Currently recommended to use the wpa_supplicant method for setting up wifi.

#networking setup
echo nhllight > /etc/hostname #TODO: fix the /etc/hosts #TODO: setup br0 mkdir /etc/hostapd/ # note: other setup is done via the config files and shell pulled down as a part of the update

Update Node and node libraries

#update node
cd /tmp export nodeversion=8.9.0 #wget https://nodejs.org/dist/v7.4.0/node-v7.4.0-linux-... #wget https://nodejs.org/dist/v7.4.0/node-v7.4.0-linux-... wget https://nodejs.org/dist/v7.4.0/node-v7.4.0-linux-... tar -xvf node-v${nodeversion}-linux-armv6l.tar.xz cd node-v${nodeversion}-linux-armv6l rm -f *.md rm -f LICENSE cp -R * /usr/local/ rm -R /tmp/node-v${nodeversion}-linux-armv6l rm /tmp/node-v${nodeversion}-linux-armv6l.tar.xz #TODO: make sym link for node binary? apt-get remove -y --purge npm node nodejs

#Node setup
mkdir /opt/nhl mkdir /opt/nhl/logs mkdir /opt/nhl/horns mkdir /opt/nhl/node_modules/

#update Node #install node dependencies into the nhl directory export NODE_PATH=/usr/local/lib/node_modules

#HACK - TODO - fix that lame wont install globally cd /opt/nhl npm install lame # lame, is lame, wont install globally cp -R /opt/nhl/node_modules/lame $NODE_PATH npm install speaker #wont install globally cp -R /opt/nhl/node_modules/speaker $NODE_PATH npm install i2c-bus #wont install globally cp -R /opt/nhl/node_modules/i2c-bus $NODE_PATH npm install oled-i2c-bus #wont install globally cp -R /opt/nhl/node_modules/oled-i2c-bus $NODE_PATH npm install lcd #wont install globally cp -R /opt/nhl/node_modules/lcd $NODE_PATH npm install lcdi2c #wont install globally cp -R /opt/nhl/node_modules/lcdi2c $NODE_PATH

npm install oled-font-5x7 #wont install globally cp -R /opt/nhl/node_modules/oled-font-5x7 $NODE_PATH

npm install onoff #wont install globally cp -R /opt/nhl/node_modules/onoff $NODE_PATH

#npm install pm2 #wont install globally #cp -R /opt/nhl/node_modules/pm2 $NODE_PATH #npm install express #wont install globally #cp -R /opt/nhl/node_modules/express $NODE_PATH

# any global modules npm install express body-parser child_process pm2 -g

Pull latest code:

#pull git code
cd /opt/nhl #JSON is one time creation wget --no-cache -O /opt/nhl/nhl_config.json https://raw.githubusercontent.com/wga22/nodejs/ma... #wget -O /opt/nhl/NHL_work.js https://raw.githubusercontent.com/wga22/nodejs/ma... #call automated script to install everything else for NHL curl -sL https://raw.githubusercontent.com/wga22/nodejs/ma... | sudo -E bash -

Download the horns!

#pull horns
cd /opt/nhl/horns curl -sL https://raw.githubusercontent.com/wga22/nodejs/ma... | sudo -E bash -

update the Raspberry pi config files - - might need to change for your system

#config file updates
#add sound cp /boot/config.txt /boot/config.txt.bak printf '\ndtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4' >> /boot/config.txt #turn on i2c printf '\n\ndtparam=i2c1=on\n' >> /boot/config.txt printf '\n\ndtparam=i2c_arm=on\n' >> /boot/config.txt

#TODO: is this needed?
cp /etc/modules /etc/modules.bak printf '\ni2c-dev\ni2c-bcm2708\n' >> /etc/modules

amixer cset numid=1 #TODO: set volume, 60%?

Automate the automation, such as bootup and code updates:

# update rc.local
# NOTE: moving the file, because standard one includes an "exit" in last line, so cannot simply append mv /etc/rc.local /etc/rc.local.bak touch /etc/rc.local chmod u+x /etc/rc.local printf '#!/bin/sh'> /etc/rc.local printf '\n /etc/bootup_nhl.sh > /tmp/rclocal.log' >> /etc/rc.local printf '\n exit 0' >> /etc/rc.local

#TODO: need to add something to do the regular software updates weekly like this
# Maybe just copy this file directly down to the rc.weekly folder? rm /etc/cron.weekly/nhl_updater printf '#!/bin/sh\ncurl -sL https://raw.githubusercontent.com/wga22/nodejs/ma... | sudo -E bash -' > /etc/cron.weekly/nhl_updater chmod u+x /etc/cron.weekly/nhl_updater

Misc stuff, like setting timezone:

ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

# update environment variable with node_path cp /etc/environment /etc/environment.bak printf '\nexport NODE_PATH=/usr/local/lib/node_modules\n' >> /etc/environment #TODO: define this for node self.ipaddress = process.env.NODEJS_IP; #TODO: self.port = process.env.NODEJS_PORT || 80;

Utilize PM2 for node server setup:

#TODO: test setup PM2
cd /tmp/ npm install -g pm2 pm2 startup cd /opt/nhl pm2 start NHL_work.js --node-args="--max_old_space_size=100 expose-gc" pm2 start webserver.js --node-args="--max_old_space_size 100M" pm2 save pm2 startup exit 0

Step 4: Step 4: Update the JSON Configuration

Setup your JSON configuration file for the team you prefer, etc.
This file is located in /opt/nhl GO CAPITALS! config JSON file

The software uses a JSON file to configure the hardware and team you're following. The team can be set through the webserver that will be running, but hardware setup needs to be set manually:

{ "myteam": "WSH",
"debug":"1" , "output": "lcd", "light": {"type":"multiled", "gpio":["10","13"] }, "amp": {"gpio":"14"}, "lcdaddress" : "0x3F", "lightid" : "22" }

Here is an explanation of each possible value:

  • myteam: this is the 3 letter code of the team you wish to follow
  • debug: Possible values are 1 (true) or 0 (false), and will control how much logging is written out.
  • output: this is the method by which scores/details are to be shown. Possible values are:
    • lcd: this is the 2004 lcd
    • console: this will write only to the terminal (for running command line)
    • oled: support for SSD6404 oled display
  • light: there are two types of lights supported
    • alarm:this will drive a single GPIO for turning on/off a transistor
    • multi-led:supports a multicolor, or multiple leds
    • none: no light attached
  • amp: this is the GPIO that drives the transistor for the amp

Share

    Recommendations

    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest

    3 Discussions

    What type of lag are we looking at? Whats great about the budweiser goal light is that its near instantaneous. Are you just hitting nhl.com for live scores and looking for a change? I want to tie this into my ambi-light setup, my other alternative is hacking open my goal light glass from budweiser.

    1 more answer

    Hi - I am using the NHL JSON API (see the code for specifics). When I know it is during a game, I hit it each minute. So yes, worst case the horn takes 59 seconds to fire from actual score. But the point of the device, to me, is to let me be a part of the games, when I have other stuff going on, and cannot even be bothered to put the game on in the background. I also like that it reminds me when a game is beginning, who they are playing, and just let's me keep up with the score.

    I'd be happy to help out more, and welcome you using my code for your own project. I tried to externalize all the main items, and could even implement a new function for the display.