Loving Google’s reasoning for doing this…
An excellent website for a variety of language, including the popular-on-the-Pi, Python.
Ever since going to the TechnoTeach in the Village where someone mentioned you could flash the onboard Status LED from the commandline I wanted to have a go. Instant hardware hacking without waiting for ‘bits’ to arrive.
There’s some guidelines here (ignore the first answer which says ‘not possible’ Those Who Can appear later in the thread. The gist is that it, by default shows the activity on the SD card, but you can override that and control it from GPIO pin 16.
echo none >/sys/class/leds/led0/trigger to turn off the default behaviour echo mmc0 /sys/class/leds/led0/trigger to turn it back on (although I haven't tested that yet!)
Once that’s done you can control it from the commandline using the following commands
echo 1 >/sys/class/leds/led0/brightness will turn the LED on echo 0 /sys/class/leds/led0/brightness will turn it off.
Or to flash it the following module and command will work:
modprobe ledtrig_heartbeat echo heartbeat >/sys/class/leds/led0/trigger
Having got that working to my immense amusement it was time to look at incorporating this into a program.
Python was what most of the examples were written in – something I’d never used. Happily the Raspberry Pi Users Guide was at hand (in Kindle form floating round the classroom on a couple of tablets) and that plus the sample code here was enough to get started.
Initial hurdle was to meddle withe GPIO you need to be running as root and the IDLE ‘Run module’ command doesn’t by default. Relaunching the editor from commandline with sudo sorted that bit.
I fiddled with the sample code to try out timing then started wondering about more uses. Flashing a Morse code seemed the obvious thing to try and since I only know two (BCN or STU for the Brecon and Strumble VORs!) I decided to try and make it flash the code for Brecon.
Things I instantly didn’t know…
How to write to the screen in Python (easy and guessable – print “Whatever”)
The timings for Morse (how much longer than a dot a dash is, how much space is between letters etc. (Wikipedia to the rescue there)
Things that worked well
It worked! and I tweaked it a bit to put some info on the screen as well.
I needed to comment the code heavily to not loose track of which letter I was on.
Stuff to improve /add
More realistic timing. It’s vvveerrryyy veeerryyy slow at the moment 1 second per dit.
Variables for the lengths of the ons and offs. At the moment I’ve coded each characters individually. Very inefficient!
More than one station!
Free text conversion into Morse sequences.
Find out if I can run those commandline setup and close down bits to make the LED accessible from within the program itself.
Code below (I learned about the WordPress shortcode wrapper for posting code without mangling it too!
We have to do this, right??? Volunteers to write an email/letter asking the factory please!
Loads of fun – and real problem solving and purposeful use when using the Pi to get the car to skid better than the human drivers could!
Should we ask for one of these??