The Digital Sandbox (DS) is a creation that came about as a combination between the best features of the PicoBoard, DangerShield, and the Lilypad Protosnap Development Board. We combined the best of these three great introductory learning platforms to create a single board that has several commonly used peripheral devices – LEDs, RGB, slider, button, and a variety of sensors.
Each of the sensors that are currently on the PicoBoard (slider, button, light, and sound) are also on this board. We thought it would be great to replicate the PicoBoard firmware to work on this device.
First, we need to upload firmware to the digital sandbox so that it mimics the same packet information as on the PicoBoard. The original C code for the PicoBoard is available on GitHub, but this code does not work directly in the Arduino programming IDE.
We ported this code base over and made a few adjustments based on the difference of pin configurations on the digital sandbox.
This code reads all of the sensors on the Digital Sandbox, creates data “packets” emulating the PicoBoard, and sends this over to your computer – to be read in by Scratch.
PicoBoard Arduino Code
Copy-paste this code into your Arduino IDE. Or, if you have the codebender plug-in, connect up your digital sandbox and click “Run on Arduino.” Select either Lilypad w/ ATMega328 as your board type or Digital Sandbox (if you are using our version of Arduino).
Scratch is an amazing platform for teaching an introduction to programming. It uses simple color-coded blocks that snap together to create programs or “scripts.” It is designed with kids in mind, but the features and functionality of Scratch are extensive enough for you to create your own data-logging dashboards, arcade-style games, or full-length animations. Once you’ve uploaded the “Picoboard Arduino Code,” the Digital Sandbox will work identically to the PicoBoard in Scratch.
As of the writing of this tutorial, Scratch 2.0 does not fully support the PicoBoard. We suggest using Scratch 1.4 until the full PicoBoard extensions are implemented, tested, and rolled out with Scratch 2.0.
To use the PicoBoard Sensor Blocks, click on the blue Sensing Palette:
At the very bottom of the list, there are two blocks that we can use. One is (slider sensor value) and the other one is a boolean/logic block < sensor button pressed ? > All of the sensors on the PicoBoard (Digital Sandbox) return a value from 0 to 100. It is a scaled value where 0 V ==> 0 and 5 V ==> 100 in the Scratch environment.
To help us get started, I like to just make a real quick and simple test script using just these four blocks:
Connect / assemble these blocks into a simple program like this:
Test it out!
Click the green flag and see what happens. The color of Scratch the cat should change as you move the slider back and forth. You should see the cat change from Orange –> Yellow –> Green –> Blue.
It seems like we’re missing some of the colors. A little digging into the documentation on Scratch shows that the set color effect block operates on a scale of 0 - 200. So, to get the full range, we need to multiply the sensor value by 2. Grab a multiply block from the math operators:
Then, re-assemble the blocks so that it looks like this:
Click the green flag and try it again! How many colors does Scratch go through now?
Play around with other effect options and features. You can tie these to any of the sensors on the PicoBoard (Digital Sandbox) – Slider, Light, or Sound. We tied the temperature to the Resistance-A sensor - which is also a range of values from 0 to 100.
Using the temperature scale on the Digital Sandbox is pretty simple - it does require a little math, though. Looking at the datasheet on the temperature sensor on this board TMP36 can be daunting, but what we care about is this:
“The TMP36 is specified from −40°C to +125°C, provides a 750 mV output at 25°C, and operates to 125°C from a single 2.7 V supply.” and “Both the TMP35 and TMP36 have an output scale factor of 10 mV/°C.”
The TMP36 outputs a voltage that varies linearly with the temperature. Because it is linear, we can start with our favorite equation from Algebra I – the general equation for a line:
y = mx + b
Temp = (slope) * (voltage) + b
The proportionality (ratio) between voltage and temperature is 10 mV/°C, but we want our slope in units of °C/mV. So, if we take the reciprocal of 10 mV/°C, this is 0.1 °C/mV. It’s the same proportion, and it has the correct units. That’s our slope!
The intercept point requires a little math. Using the information that says “provides a 750 mV output at 25°C,” we can find the intercept point.
25 °C = (0.1 °C/mV)(750 mV) + b
25 °C = 75 °C + b
-50 °C = b
Temp (°C) = (0.1 °C/mV) * (voltage in mV) - 50 °C
In Scratch, the voltage is scaled from 0 to 100. So – let’s see how this works:
Temp = (0.1 °C/mV) * (voltage in Scratch/100)*(5000 mV) - 50 °C
Looking at this, I see a lot of decimals, multiplication by 1000’s and divide by 100s. It seems like we should be able to simplify this. First, let’s simplify the divide by 100 and multiply by 5000.
Temp = (0.1 °C/mV) * (voltage in Scratch*(50 mV) - 50 °C
Next, multiply the 0.1 by the 50 and simplify to:
Temp = (voltage in Scratch*(5 °C) - 50 °C
And, in Scratch – this looks like:
Sample Scratch Script
We created a little sample script to show all of the features all in one example. Feel free to use this, take parts of it, or re-mix it into your own new program. It changes the sprite based on the light input, the slider value, and the sound level.
The sprite will also walks back and forth if you flip the slide switch to the ON (1) position and will change color (and play a sound) when you push the button. Play around with this example. We’re sure you’ll come up with other fun ideas too!
Click here to download a copy of the file to run on your own computer.
The DigitalSandbox Picoboard is a great start to programming and interacting with sensors, but it only allows you to read input values into Scratch and it does not allow for us to control actuators or affect OUTPUTS.
If you’re interested in extending this to more than just reading sensors, try Scratch4Arduino or ArduBlock. We have an entire series of activities and experiments built around Ardublock using the Digital Sandbox here.