I always wanted to build something cool and fun for my daughter (6 years old) with a raspberry pi but didn't really have an idea where to start until one day she was in my office, I had the raspberry on my desk with a sense hat but it was not plugged in and she asked me what this is so I plugged in the Raspberry and the Sense hat lit up and filled the screen with a rainbow.
This led me to my first idea of what to build for the raspberry to get my daughter interested. Enable her to write some text and send it to the raspberry's sense hat display!
Writing things to the sense hat
This is a very simple script assembled for the sense hat howto and some stackoverflow input, didn't really write anything in python so far but it works for demo purposes.
It just reads the content of a file and sends it to the display, before doing that it gets some random value to pick a color of the text.
What we need now is some way to get a text value into this
demofile.txt for the python script to send it to the sense hat.
The "web interface"
Ok calling this small sinatra script a web interface is a bit overkill.
since I will be running this script as root (yeah I know ...) I want to bind it to port 80 and it must of course bind to
0.0.0.0 otherwise we won't reach it from outside. Now what's left is the view.
This masterpiece now is the view for this little project.
Here's how it works, if you run the python script it will loop infinitely, read the content of the text file and send the content to the display. The sinatra app will give you an input field. If submitted it will dump the content into the text file which will be read by the python script and sent to the display.
Be aware that running this as root and dumping things via system call is very dangerous.
Now in order to start it on boot, create this little shell script and add it to cron like this
it should at startup print the IP it got, but in my first tests it was blank, might be due to the fact that the script started before the raspberry managed to pull an IP from the DHCP Server.
Now boot up the raspberry and have fun!