Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Tuesday, 13 May 2014

Back to the Screen (Part 1: Text)

One of the cool things about Sniff is getting away from computer screens - we have screens everywhere, and we're bored of them. When I got my first computer we plugged it into the family TV, and I typed in the BASIC code to display my name on the screen. If you weren't "there", then its impossible to explain how big a deal that was. TV was the  only screen we had, and it was controlled by "the powers that be". To control what appeared on screen was incredibly subversive. It's not too big a leap to claim that those were the first steps in democratising video distribution, not just technically but politically.

The problem now however is the exact opposite - access to screens is ubiquitous. No kid makes it to Reception without having seen their name on a screen. That's why physical computing is important in getting people to engage with computers. The screens that made those old computers special make contemporary systems dull. To get people excited about something you need to show it to them NOT ON A SCREEN.

However sometimes you need to display some information, and you've considered every other option - LED's, buzzers, neoPixels? Say and Ask are quick and practical ways of getting info back to the programmer but they are SO DULL...

All is not lost though - even if you need to attach a screen it doesn't have to be a boring screen. The simplest screen you can attach is a text LCD. These can display text pretty nicely, are cheap and easy to use, and don't require plugging your system into a boring monitor.

The easiest way to use an LCD is to get a prebuilt shield or Arduino, and just plug it in.
These are pretty common, and provide a 16 column, 2 line display. As such they're perfect for displaying the results of experiments like the Hot Wheels Speed Trap.

make lcd device
make message string

when start
.set message to "hello"
.tell lcd to "show"

To display a message just assign it to the string message, and call "show". Messages appear on the bottom row, and scroll up.

Connecting an LCD directly like this is cheap and easy (on an Arduino), but more problematic on a Pi where GPIO pins are in short supply. It would be pretty easy to adapt the lcd device to work on Pi, but a better option is to use an LCD display with an attached i2c i/o expander.  I2c allows you to talk to lots of devices using only 2 i/o pins so these are both easier to hook up and leave more pins free for other things (though they're a little more expensive, and a bit slower).

Unfortunatly different manufacturers configure their boards slightly differently. If you find your's doesn't work, check its specification, and compare it to the first few lines of the file SNIFFDIR/lib/Xlcdi2c.c. The code is currently set up for a 20x4 display, connected with a Funduino expander board. Other boards are functionally identical, but need a few minor tweaks - I can only work with the hardware I have, so if you have a different board it would be great if you could send me the config data you used, and I'll add it in.

Once you're set up though, you can use the i2c lcd just as you would a regular display:

make i2c device
make lcdi2c device
make message string

when start
.set message to "hello"
.tell lcdi2c to "show"


LCD's are a great way to display data without putting it on a monitor, but for more bling (or impact if you prefer, but we know you mean bling) you need LEDs - the more the better.

The simplest form of LED display (other than an LED!) is a 7 segment display. You can buy them a digit at a time, but the problem is they use a lot of pins so to do anything useful you need a driver board. The simplest is the 7Seg for Pi which is totally trivial to use, and only requires 2 pins. If you need more digits then you need something like these. I've not got my hands on one yet, but they should be really easy to code for...
However 7 segments isn't enough to display text - for that we need either a 14 or 16 segment display. Sniff has a driver for these 14 segments displays, but its currently untested - I had to go and order the blue one which is out of stock. I'll blog it in detail when it arrives, but the basics should be pretty obvious by now:

make led14seg device
make message string

when start
.set message to "hello!"

.tell led14seg to "show"



For a REALLY impressive display you need an LPD8008 (or two). These are bitmap displays, but they're ideal for displaying BIG text. There's lots of info in the previous blog post (and it should work on Arduino and Pi).

While this isn't the most exciting post, that's really because its only part 1. I wanted to post about drawing graphics, but ran out of space... I'll cover graphics in parts 2 (and 3?).

No comments:

Post a Comment