Adding an LED to the internet printer

Adding an LED to my little Internet printer

Sometimes I’m not sure if my little Raspberry Pi-powered GoFreeRange internet printer is actually working or not – the Raspberry Pi is hidden inside the box, and you can’t usually see the onboard LEDs. Today I thought my printer had been quiet – it turned out the mains plug had fallen out. So I decided to add an LED that lights up when the Python script that makes the printer work starts running, and which can be fitted to the top of the soap box. (I know there are lights, and even a button, on the original Arduino-powered GFR printer, but I’m not sure what they do).

I connected the GND pin (pin 6) on the Raspberry Pi to a breadboard (via the black wire in the photo), so the GND pin can be shared by the thermal printer and the LED. I connected GND back to the printer (with the orange wire).

I connected the GND rail on the breadboard to a 330 ohm resistor (all I had) to the short leg of an LED.

Then I connected the long leg of the LED to a GPIO pin on the Raspberry Pi – pin 7 (GPIO 4) – that’s the red wire in this photo.

I added this code near the top of the printer.py Python script, just after all the other import commands:

import RPi.GPIO as GPIO
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.HIGH)

This then lights an LED when the Python script starts running. It doesn’t, of course, necessarily tell me it’s stopped running, but at least I know there’s power to the Pi and the script has started at least once since it booted up.

This probably commits all kinds of crimes against coding and electronics – advice and suggestions for improvements are most welcome!

The next step is to get an LED to light when it polls for new stuff to print, or when stuff is incoming – perhaps a different colour LED for incoming data? Though stuff coming out of the printer is usually a pretty big clue that there’s incoming data, so I’m not sure exactly how useful that would be. I might also see if I can get the button to shut the Pi down so it can be safely unplugged.

Polling blinking

Here’s how I got the LED to blink when the code is polling for new content. I added the following lines near the top of the printer.py script:

import RPi.GPIO as GPIO
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.LOW)

The last line isn’t probably necessary, but it was useful for me when testing to get the script to turn the light off when it started up.

I then modified the last section of the printer.py code so it read like this:

while(True):
GPIO.output(7,GPIO.HIGH)
checkForDownload()
GPIO.output(7,GPIO.LOW)
time.sleep(pollingTimeoutSecs)

This causes the LED to blink momentarily when it polls for new data, so I know the script is running.

This entry was posted in computers, ICT, Linux, Raspberry Pi, Raspbian and tagged , , , . Bookmark the permalink.

Leave a Reply