Scratch Sensor - the Android Smartphone as a DAQ module
Scratch is an interpreted dynamic visual programming language. Being dynamic, it lets code be changed even as programs are running. It has the goal of teaching programming concepts to kids and teens and letting them create games, videos, and music. It can be downloaded for free and is being used at home and in a wide variety of in-school and after-school settings around the world.
Connections between Scratch and other programs are made using the Scratch networking protocol. With this feature turned on, Scratch automatically sends all broadcasts and values of global variables out to any program connected to it. That program can also send broadcasts and global variables into Scratch. The Scratch Sensor is an Android app that uses the Scratch networking protocol to turn the Android Smartphone into a DAQ module and sends its accelerometer and compass sensor information and broadcast two states (jump and walk) to Scratch.
Please use Scratch version 1.4 only and familiarise yourself with the Scratch program before proceeding.
- Download Scratch Sensor from the Android Market.
- Download the example Scratch project.
- Note your Computer IP Address. Click the Start icon in the Windows taskbar. Paste cmd /k ipconfig into the search bar and press Enter.
The screenshot shows the IP Address for the Wireless Network is 192.168.1.2.
- Load the example Scratch project. A Remote sensor connections enabled dialog should appear. Click OK. Click the green flag to Start.
- Start Scratch Sensor on your Android smartphone. If your smartphone wifi is not enabled, you need to enable it now. Enter your Computer IP Address that you obtained earlier. Press the Connect Button. You should see a Connected status.
- Hold the Android Smartphone in an upright position. When you rotate the phone, the direction value should change. The sprite faces only left and right due to the sprite setting (see Scratch programming).
- When the phone is moved up and down, the jump message is broadcast.
- When the phone is moved side to side, the walk message is broadcast.
Start from Scratch
- Start a new Scratch project. The following is intended for those familiar with Scratch and its programming environment.
- Get a sensor block and enable remote sensor connections
- Start the Scratch Sensor app on the Android Smartphone. Your wifi should be connected and the Computer IP Address should be correct.
On the sensor block you can now select acceleration x, y and z values as well as direction.
- To receive the walk and jump broadcast message, place the Control->when I receive block. Enter either walk or jump.
Q: I am getting a connection error.
A: Check the IP address. It may change when the router is powered down or reset. Also the Remote sensor connections in Scratch must be enabled before you click Connect in the Scratch Sensor App.
Q: Is the source code available?
A: Yes, it is available from github.com/emantpl/scratch-sensor