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, 16 June 2015

Sniff and the Picoboard

Working with the Arduino and Sniff makes it really easy for older children to plug together sensors, gather data and control motors. With a bit of planning, making sure you have the right parts and some pre-wired cables, you can make it so projects can be just plugged together.

However there's still a certain level of care and attention required that can make it harder of kids at younger age groups. That's why the lego Wedo is such a great tool - its about as kid friendly as it gets! It works with Scratch, so you can start with that, and then use the same hardware in Sniff.

The other common hardware used with Scratch is the Picoboard. It's provides a slider, a button, light and sound sensors, and 4 analog inputs for use with other resistive sensors (banana piano's and such). Now you can use that board with Sniff too. The code to use it is pretty simple:


make picoboard device
make picoSlider number
make picoLight number
make picoSound number
make picoRa number
make picoRb number
make picoRc number
make picoRd number
make picoButton boolean

when start
.forever
..tell picoboard to "update"
..if picoButton
...say join "Slider:" [picoSlider]
..wait 0.1 secs

Setup the board device, and create variables for each of the sensor inputs. Telling the board to "update", reads the values from all of the sensors. In this case we print out the position of the slider whenever the button is pressed down.

Before you run it you may need to help Sniff find the board. On Unix it should be found when you run setup. On Windows you need to tell it the com port that you want to use. Run setup as normal, then in the shell type something like:

export ARDUINODEV=COM3

depending on what com port your board is using.

All good, but what can we do with it?

Some guys I work with are involved with the LearnOMeter project. It's not a crazy idea: record environmental data from classrooms, try and find correlations with student progress. The gadget they built looks amazing. It's got a fancy 3d printed case, and measures a whole range of stuff, but I can't help feeling they've got a bit off track. The device is expensive, complex and hasn't collected a whole lot of data. Lets see if we can do better using a picoboard!

The board already has a light and a sound sensor. These aren't (as far as I know) calibrated in any meaningful way, so we can't say exactly how loud or how bright the room is, but we can track changes, which I think is far more interesting: how does noise level track through the day, as we engage in different activities? it doesn't matter exactly how loud it is - we just want to know about louder and quieter times.

We can use the picoboards external inputs to add additional sensors, provided we can find components who's resistance changes with the thing we want to measure. The easiest thing to add is another light sensor - a light dependant resistor (LDR) costs pennies, so I hooked one up across input A and pointed it out the window. That way I can see the relationship between outdoor brightness, indoor brightness and other factors. Does it get noisier when children can see a sunny playground outside?

Temperature is equally easy - we just need a Thermistor (again pennies on eBay - we can even get a waterproof one and use it to measure all sorts of things).  We just hook them up to the picoboard crocodile clicks and off we go!

For each of these we want a nominal resistance of around 10K to be compatible with the picoboard. We could do some maths to calculate the actual resistance of the component, and convert that into an actual lux/temp/RH value but its probably best to just log the data, and worry about it later.



make picoboard device
make picoSlider number
make picoLight number
make picoSound number
make picoRa number
make picoRb number
make picoRc number
make picoRd number
make picoButton boolean

make clock nativeClock device
make clockValue string

make fileSystem nativeFile device
make fileData string
make fileOK boolean

when start
.set fileData to "pico.csv"
.tell fileSystem to "startWrite"
.forever
..tell clock to "getDate"
..set fileData to clockValue
..set fileData to join fileData ","
..
..tell clock to "getTime"
..set fileData to join fileData clockValue
..set fileData to join fileData ","
..
..tell picoboard to "update"
..set fileData to join fileData [picoSlider]
..set fileData to join fileData ","
..set fileData to join fileData [picoLight]
..set fileData to join fileData ","
..set fileData to join fileData [picoSound]
..set fileData to join fileData ","
..set fileData to join fileData [picoRa]
..set fileData to join fileData ","
..set fileData to join fileData [picoRb]
..set fileData to join fileData ","
..set fileData to join fileData [picoRc]
..set fileData to join fileData ","
..set fileData to join fileData [picoRd]
..
..say fileData
..tell fileSystem to "writeString"
..
..wait 10 secs

This also gives us a chance to use the nativeClock and nativeFile devices (Sniff devices that include the word "native" mean they're running on a regular computer, which already knows how to handle that hardware so we don't need to - for example we could attach our own time keeping hardware, but the PC already has it build in).

To write a file we set fileData to the name of the file and "startWrite". From then on we can load a line of text into fileData and save it to that file with "writeString".

We use nativeClock to get the time and date, and join them together separated by commas. We then go on to add the values of the Slider, light, sound, and each of the resistance inputs. When we've made a full line of text we write it out, wait 10 seconds and go round again.

You'll note we record the slider position, even though that isn't going to tell us much about the actual environment... well part of the original spec for the learnometer was that it would be used to correlate "successful classroom outcomes" with environmental factors. There was lots of discussion about what exactly that meant, and how it could be recorded, but here's a simple solution. Someone moves the slider. If they're comfortable and happy they move it up, if they're not then they move it down. Who that someone should be and how often they need to move it I leave to the learnometer team, but we've got a mechanism when they figure it out.

Assuming you've got a picoboard and a computer, our version of the Learnometer costs about £1, and KS2 and above can build one in a few minutes. While it may not be as accurate, or complete, we could log data in hundreds of schools within a few weeks!

The data is written out in a format known as "csv", which means it can be loaded into any spreadsheet program. Lets go collect some data and I'll see what I got in a future blog.

No comments:

Post a Comment