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.

Monday, 2 May 2016

A bigger screen for you Microbit (max7129)

While the Microbit's built in "screen" is great fun its a little limited... 5x5=25 pixels, which was great for our compass, and spirit level, and there's a fun snake game in the Sniff/examples/Microbit folder, its just a little bit frustrating. What if we could move up to something with a little more real estate:

The easiest way to do that would be an 8x8 led matrix. That may not sound like a lot more, but 8x8 is 64 pixels - more  than 2.5 times as many. Now in principle you could try and wire up one of these from scratch, but you need 16 pins to do it... instead get a board with a max7129 chip on it

These cost about £1.50 and are really easy to connect. They use 5 pins: GND, VCC (power - 5V or 3V is fine), Din, Clk and CS. Now if you read the previous post on using SPI some of those should sound familiar. However as this is an output device, there's no reason for it ever to talk back to the "master", so we don't need a MISO. As there's only one data pin now they've labeled it Din, rather than MOSI. So just connect up to the SPI pins CLK->13, Din->15. Remember you can use any pin you like for CS, but D16 is a good choice. Now to use it in Sniff just make a device:

make spi device
make display maxMatrix device D16
make displayX number
make displayY number

make displayColor number

When I've made the device I've specified the CS pin. If this looks little like what we had when we made the microbitDisplay device then it should. All the commands we used to draw on the 5x5 built in screen work exactly the same on the larger 8x8 display:

when start
.set displayColor to 000
.tell display to "clear"
.
.set displayColor to 000
.set displayX to 1
.set displayY to 1
.tell display to "move"
.set displayX to 8
.set displayY to 8
.tell display to "draw"

There's no need to call "tick" like we did on the microbitDisplay as the hardware handles that this time. Otherwise you just need to tweak your code to make use of the extra pixels.

You might notice that the maxMatrix board has pins on the top as well as the bottom... They're outputs, and if you connect them to another identical board they'll act as a single large display. In fact Sniff will let you connect up to four boards to make a screen which is 8 high and 32 wide (though you probably shouldn't try powering  that from the microbit). Now our original scrolling text is a giant message board!


No comments:

Post a Comment