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.

Posted in computers, ICT, Linux, Raspberry Pi, Raspbian | Tagged , , , | Leave a comment

Making a GoFreeRange internet printer with a Raspberry Pi

PLEASE NOTE THIS POST IS NOW OUT-OF-DATE. The Go Free Range printer is now at http://exciting.io/printer/ – I’ve not updated my Raspberry Pi code because my own thermal printer is broken, and will only spew out lines saying ‘CP437′ – if anyone knows of any possible fix, I’d be very grateful.

I love the idea of the Berg Little Printer, but it’s expensive: a self-contained box that lets you rip & read internetty stuff such as weather, messages, diary events, travel news, whatever anyone can think of. I already have a thermal printer I used for my Little Box of Poems, so I decided to make an open source GoFreeRange internet printer instead. The GoFreeRange printer normally uses an Arduino, but as I have the wrong kind of Arduino, I wanted to use a Raspberry Pi instead.

You can read more about little thermal internet printers in this Wired article from 2012.

Untitled

Here’s roughly how I did it (more details to follow):

  • I made a fresh Raspberry Pi SD card using the normal default Raspbian Wheezy disk image: http://www.raspberrypi.org/downloads
  • I got the Raspberry Pi on t’internet using a wifi dongle, setting it up using the GUI wifi tool on the desktop, and enabled SSH using the raspi-config tool so I could log into it from a computer with no keyboard or mouse connected to the Pi. I also used the raspi-config tool to expand the disk image to fill the SD card and update the system software. I did not get the Pi to boot into the graphical environment at startup, as I was going to be running it ‘headless’.
  • I powered up my thermal printer and connected it to the Raspberry Pi in the same way I did with The Little Box of Poems. I put the Raspberry Pi and printer in an old washing tablet box.
  • I followed Andrew Nicolaou’s instructions: https://github.com/andrewn/raspi-printer#readme - I changed the baud rate in cmdline.txt – this causes the Raspberry Pi to send its Linux boot messages to the printer as well as the video output. It’s a bit verbose – I got a yard of nerdy gubbins spewing out of my printer, but it worked. (You can disable this if you like, see below).
    Raspberry Pi boot screen text coming out of printer
  • Then, following Andrew’s instructions, I installed the python-serial library. I was a bit thrown about the bit where he says to save a file with your unique printer ID. I didn’t have one, and I didn’t know how to get one. It seemed like a bit of a catch-22, so eventually I just ran his printer.py script anyway.
  • I then went to this page on my desktop computer and made a note of the printer URL: http://printer.gofreerange.com/my-printer – somehow the file with my unique printer ID seemed to get made in the process. I did a test print – it worked!
  • Untitled

  • Then, having saved my printer URL in a notepad, I signed up for Printer Mail – http://printer-mail.herokuapp.com/. This means people can send messages to my printer by filling in a simple form on a web page. Brilliant!

I had a couple of kernel panics – the Pi rebooted itself without warning. Not sure why, need to investigate. I’d like to make the boot-up text a bit less verbose too.

As I’m running the printer script manually, I need to follow Andrew’s instructions on getting it to run automatically when you boot the Pi up, and get all the gubbins in a self-contained box.

People sending my printer messages from anywhere they can get on the internet all over the world is pretty damn cool, but other possible uses include waking up to a daily printed weather report and printing paper bookmarks customised for the book you’re reading. Or print out anything you star in Google Reader. What’s that you say? Oh well, you get the idea.

The Raspberry Pi version of the GoFreeRange printer doesn’t have a button – it just prints anything that’s sent it. I have a big red shiny button in my printer box that’s going spare, but I quite like the idea that no human intervention is required, it just squirts out… stuff.

I’ve been away from my printer all day, working a late shift. Quite excited to see what might be on it when I get home…

What’s next?! Excited… very excited.


I also signed up for the Printer Paint app – so you can draw me a picture on your computer and send it to my little printer. I love pictures appearing on my printer – send me one! http://printer-paint.herokuapp.com/send/blogmywiki

Incoming message from His Dudeness

Addendum:

I’ve now disabled serial port login on the Pi, to see if that helps with stability – following the instructions here: http://www.hobbytronics.co.uk/raspberry-pi-serial-port. I did this when I made the Little Box of Poems, and it seems like a good idea. You just comment out the last line of /etc/inittab, the one that reads
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
by putting a # (hash) at the start of the line. There are also instructions there on how to stop the printer spewing out all the Linux boot-up info when you turn the Pi on.

Post-script to the addendum

I had trouble getting the Python script to run at startup. This is quite important, because I want my little printer to just start working – and stay working – when I plug it in. I don’t want to have to log in by SSH to start the script running.

I couldn’t get the update-rc.d method to work, so instead I edited /etc/rc.local by typing
sudo nano /etc/rc.local
and adding the line
sudo python /home/pi/raspi-printer/printer.py
to it. This seems to work.

I've got pandas on my printer

Posted in Linux, Raspberry Pi | Tagged , , | 17 Comments

Dorothy Parker in Reverse

An unsuccessful attempt to get a book club to pick The Collected Works of Dorothy Parker as their next book reminded me that I once rewrote her short story ‘A Telephone Call’, swapping the genders to see if it still worked. I think it does.

PLEASE, God, let her telephone me now. Dear God, let her call me now. I won’t ask anything else of You, truly I won’t. It isn’t very much to ask. It would be so little to You, God, such a little, little thing. Only let her telephone now. Please, God. Please, please, please.

If I didn’t think about it, maybe the telephone might ring. Sometimes it does that. If I could think of something else. If I could think of something else. Maybe if I counted five hundred by fives, it might ring by that time. I’ll count slowly. I won’t cheat. And if it rings when I get to three hundred, I won’t stop; I won’t answer it until I get to five hundred. Five, ten, fifteen, twenty, twenty-five, thirty, thirty-five, forty, forty-five, fifty…. Oh, please ring. Please.

This is the last time I’ll look at the clock. I will not look at it again. It’s ten minutes past seven. She said she would telephone at five o’clock. “I’ll call you at five, darling.” I think that’s where she said “darling.” I’m almost sure she said it there. I know she called me “darling” twice, and the other time was when she said good-by. “Good-by, darling.” She was busy, and she can’t say much in the office, but she called me “darling” twice. She couldn’t have minded my calling her up. I know you shouldn’t keep telephoning them – I know they don’t like that. When you do that they know you are thinking about them and wanting them, and that makes them hate you. But I hadn’t talked to her in three days – not in three days.

I still heartily recommend the Penguin Collected Dorothy Parker. It’s a big book, but made of short stories. You can pick & choose, like sweets. Leave some of the poetry if you like. There will always be hard-centred, unloved ones left ignored, but you will also find some praline-filled iced gems, with a bittersweet aftertaste.

Posted in fiction, literature, nostalgia, relationships | Tagged , , , | 1 Comment

Maths is not an exact science

Recently I’ve been going through the peculiar hell that is the Teaching Agency maths skills test. Anyone who wants to be a teacher has to pass this, even if you just want to teach GCSE English. Everyone says ‘you’ll be fine’ – at least everyone who’s not tried to sit this test. It’s been made more rigorous, you see. It’s a pig.

There are 12 questions that are spoken, and by the time the voice has finished, you have a mere 18 seconds to type the answer, without using a calculator. The problems are not trivial or simple. After your time is up, it clicks over to the next question. You can’t go back and review an answer. And if you get one straight away (working in radio means I’m quite good at adding and subtracting time), you can’t click forward and use the time for a harder question. It’s torture. If you’re a masochist with time on your hands, you can try it yourself here: http://www.education.gov.uk/QTS/Numeracy/assessment_engine.html

An esteemed colleague has suggested that, if asked for feedback, I should say that I’d have enjoyed the mental maths section much more if the questions had been read in person by the Secretary of State for Education. Unfortunately, my opinion has not been sought.

The next part of the paper comprises 16 questions, mostly about interpreting visual representations of statistical data: tables, scatter graphs, bar charts, even pie charts (which I now know, thanks to @clogsilk, are evil).

60/365 Maths is not an exact science

The sample papers all include something most of you will never come across: the box and whisker diagram. I met one candidate at an interview whose boyfriend had a maths degree, and he’d never heard of them. But I got to grips with them, I thought I understood them… until I tried the sample question pictured above (in a book on passing the exam).

On the diagram, the box & whiskers tell us: the lowest mark was 25, the highest mark was 90, the median mark (the one in the middle when you line them all up) was 60, and the inter-quartile range is from 40 to about 73.

These facts are not in question. True or false answers are required. Maths is an exact science, right? Some people find comfort in numbers. Numbers are not like people. Numbers are reliable. They do not do mad things randomly, like push you in a canal, fail to call you back or tell you that green isn’t your colour.

My answers were TRUE, FALSE, TRUE.

The book said: FALSE, TRUE, TRUE.

I think the book is wrong. For the first statement, they say that a quarter of the pupils DIDN’T get over 70. Well, the upper quartile is about 73, so a quarter of them certainly got more than 73, and the last time I checked, 73 was more than 70. Okay, that quarter didn’t get any marks between 70 and 72, but they DID get more than 70.

The second one is a bit less clear, but I’m sure I’m right and the book is wrong. Bear with me here. We know the median is 60. This means if you line all the scores up in a row, 60 will be in the middle – or the two values either side have a mean value of 60. We’re not told how many pupils there are. If there’s an odd number of pupils, that means one pupil scored exactly 60, because they are in the middle (the median). This means that half the pupils scored 60 or less, but it’s false to say that half the pupils scored less than 60 – slightly fewer than half got less than 60.

Some may say I’m splitting hairs, some say it’s the words that are the problem here, not the numbers. But the words seem quite clear to me. It’s the cold, hard binary answers that are wrong.

Anyway, I passed my skills test. With a little help from my friends.

Posted in education | Tagged , | 5 Comments

Q: When is an A&E not an A&E?

31/365 Jeremy Hunt announcing downgrading of Lewisham Hospital

A: When it is closed to blue lights.

Lewisham A&E has not been reprieved. An A&E that does not admit blue lights, that takes the 75% of the less-seriously ill people who would have gone before, which refers the seriously ill to another hospital, is not an A&E. It is an urgent care centre with a different name.

I would like someone to stand up in the House of Commons and ask a simple, direct question (why do MPs so often ask long, multiple questions when a single inquiry would be so much more effective?): What, exactly, is the difference between the proposed downgraded A&E and the urgent care centre proposed by the Special Adminstrator?

It’s not always obvious that a condition is life-threatening. My wife was taken to Lewisham A&E – we didn’t know it at the time, but she had a ruptured ectopic pregnancy. This was quickly diagnosed by Lewisham A&E and she was rushed into theatre. She had lost 5 litres of blood when they opened her up. If she’d then been sent to Woolwich she’d have been dead by the time she got there.

Her first pregnancy was apparently straightforward. But when our eldest son was born, he was unexpectedly small and had a blood condition call polycythemia – he was rushed straight into neo-natal intensive care in Lewisham, just a couple of floors away from where he was born. He spent 2 weeks there and they saved his life. The pregnancy appeared to be normal, but we unexpectedly needed serious medical intervention.

Things are not always what they seem. You can’t always tell if a medical problem is serious until it’s too late.

Posted in children, family life | Tagged , , | Leave a comment