You are on page 1of 9

Food

Living

Outside

Play

Technology

Workshop

Scratching with Arduino


by danjovic on February 23, 2013 Table of Contents Scratching with Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intro: Scratching with Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 1: Preparing Ground . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 2: The challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 3: Board Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 4: Testing the Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Step 5: Testing with Scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 2 3 4 5 7 8 9

http://www.instructables.com/id/Scratching-with-Arduino/

Intro: Scratching with Arduino


MIT has developed a fantastic visual programming language called Scratch . It is also an amazing learning tool for children, because it is simple, cute, and by providing interaction with the real world by a board called Scratch Sensor Board. This Instructable shows the development of a shield for Arduino that can interact with Scratch and replicates the functions of the Scratch Sensor Board Note: The present shield constitutes a so called 'derivative' from "Scratch Sensor Board", whose license can be found here . Further information about the original board can be found here For the Impatient: Final Arduino Sketch is here Printed Circuito Board is here (eagle ) Schematics are here (pdf / eagle )

Step 1: Preparing Ground


The first thing to do is read the documentation (here ) to find how do the Sensor Board interacts with Scratch. After some time reading we found that the Sensor Board communication occurs via RS-232 at a speed of 38400 baud. It is good, because Arduino already have a Serial Port which means less circuits to implement. The protocol between Scratch and Sensor Board constitutes of a ping pong mechanism. First Scratch application send a a data byte to the board then the board replies with sensor data. Nice. The request packet is simply a byte with the value 0x01, whilst the sensor data consists of 9 high byte / low byte pairs (i.e. 18 bytes) spaced in time by a 400us interval. The high byte / low byte pairs contains a 4 bit channel ID and a 10 bit Value. This is good, because if suits well with Arduino ADCs resolution. For the Scratch Board Release 1 firmware and Scratch release 1.1 and later, the mapping between channel ID and sensor type is given below: Channel / Sensor 0 / Resistance D 1 / Resistance C 2 / Resistance B 3 / button 4 / Resistance A 5 / Light 6 / Sound 7 / Slider 8-14 / Not Used 15 / Firmware ID (0x04) From the 16 possible channels we have 7 analog, 1 discrete (on/off), 1 dummy (firmware-id) and 7 spare (not used now; maybe in a future version).

Image Notes 1. Channel ID bits 2. stuff 3. stuff 4. Sensor data, LSBits 5. Sensor data, LSBits

http://www.instructables.com/id/Scratching-with-Arduino/

Step 2: The challenges


Extra Channel If you know Arduino well and paid attention to the last step, you might be noticed that Scratch expects to receive 7 analog readings, but a Stardard Arduino has only 6 channels. That's the first challenge. To accomplish that, the solution found was to implement a multiplex using a 4066 that is a quad bidirectional CMOS analog switch. One at a time each switch is activated and the correspondent ADC channel is read. The channels choose to be multiplexed were from the 'light' and 'sound' sensors, since they have stabilizing (filter) capacitors, which make changes in such channels to occur much slower than the switching. Of course, the switching scheme had to be tested before going on, but luckily, it worked very well!! DIYable Board A second challenge was to make this shield DIYable. It implies on a Single-Face board with as few jumpers as possible. To achieve the single face layout I have started by choosing the place of the connectors and the light and sound sensors. Then the association of the Arduino Pins with sensors, as well as the halves of the OPAMP halves and gates of the Analog Switches were experimented until the 'ratsnet' lines showed up aa bit clean. At the end the result was achieved with only 2 jumpers. (Note: The board available on the files has been further optimized and now only one jumper exists) To save space and simplify the layout 2 stereo jacks have been used instead of 4 from the original design . Printed Circuit Board is here (eagle ) Schematics are here (pdf / eagle )

Image Notes 1. Multiplexed output. Goes to the Analog Input 4 of Arduino 2. Each output activates a single switch. They shall not be activated simultaneously

Image Notes 1. This is the Arduino Severino Board, a Single face DIY version of Arduino PRO 2. CD4066 - Quad Bidirectional Analog Switch 3. Resistors used to provide VCC/2 for testing

http://www.instructables.com/id/Scratching-with-Arduino/

Image Notes 1. Two Stereo Jacks have been used to save space and ease the routing of the board

Image Notes 1. Light Sensor 2. Resistance Sensor Inputs 3. Slider 4. Analog Multiplex 5. Button 6. Sound Sensor and conditioning 7. Unused analog switches

Step 3: Board Construction


The prototype board had been built using the 'tone transfer method'. There are several instructables teaching how to do that. The board was etched using Ferric Chloride in a water bath to accelerate the reaction. Despite the potential of the Ferric Chloride to make a mess, I prefer to use it because the etching chemical reaction does not release gases. After corrosion the board was silver coated using TP-065E solution and then it was drilled. Then the components have been soldered starting by the resistors, then the capacitors, followed by the IC Sockets, After that the taller components have been soldered. Note: Due to a lack in local stock, the prototype received a different potentiometer. Using a multimeter all the connections have been tested. I always do that before powering things up because It saves us from a lot of trouble. For example I have found a short circuit caused by a track that was too close from the pads of two resistors, but it wasn't noticed on PCB drawing tool. (Note: The board available on the files already have this correction)

Image Notes 1. Electret Microphone 2. Light Sensor 3. Push Button 4. OPAMP 5. CD4066 Quad CMOS Bidirectional analog switch 6. Only 1 jumper (this image is from revised layout) 7. Slider Potentiometer 8. Jack for resistance channels A,B 9. Jack for resistance

Image Notes 1. No need to be populated. After all it is only a prototype 2. The local supplier stock ran out

http://www.instructables.com/id/Scratching-with-Arduino/

channels A,B

Image Notes 1. I have used another potentiometer since the stock of my supplier ran out 2. This jumper was removed in the version of the board available for download 3. Used an electrolytic here 0,33uf instead of a polyester cap, but no problem. 4. Photo Transistor (Light Sensor) 5. Electret Microphone

Image Notes 1. Equivalent to Lumbert 1509-3 stereo 3.5mm jacks

Image Notes 1. Assembled Board attached to an Arduino UNO Image Notes 1. After etching there was a short circuit here. The track were too close from the pads.

Step 4: Testing the Board


After the board assembled and checked it's time to test the individual functions before starting the develop the final sketch. This practice is called 'validation' and its objective is to reduce the amount of uncertainties and/or errors thus avoid having several problems at the same time to solve. The first tests have been performed on the Resistance Channels using the 'AnalogInOutSerial' example form Arduino IDE, where the line below was changed according the desired channel. const int analogInPin = A0 ; // Analog input pin that the potentiometer is attached to The resistance channels A, B, C, D are mapped to Arduino Analog inputs A0, A1, A2, A3 A cable with a couple of 100K potentiometers and a P2 Plug have been built to help performing such test. With 100K potentiometers the value shown on serial terminal shall vary between 0 and 930. Use the Serial Monitor from Arduino IDE, like in the example (Tools->Serial Monitor). The next test was the slider. Still using the 'AnalogInOutSerial' example, change the value of analogInPin to A5 const int analogInPin = A5 ; // Analog input pin that the potentiometer is attached to Since the Slider does not have a series resistor, the value shown on serial terminal shall vary from 0 to 1023.

http://www.instructables.com/id/Scratching-with-Arduino/

The next step is to perform the test on light and sound sensors, and first we are going to do this without involving the analog multiplexer. Then take out the 4066 and short circuit the pins 3 and 4 from the socket (remember to power off the Arduino before remove the IC). Yet using the 'AnalogInOutSerial' change the value of analogInPin to A4. const int analogInPin = A4 ; // Analog input pin that the potentiometer is attached to Now, point a flashlight to the sensor and check the values changing on serial terminal. The exact amount of change depends upon the sensitivity of the photo-transistor used. Now remove the short circuit from pins 3 and 4 and make a short between pins 8 and 9. Now speak close to the microphone and check that values printed om serial terminal (no need to change the value of analogInPin, since light and sound share the same ADC channel, remember?) Now we are going to test the multiplex. Remove the short circuit between pins 8 and 9 and reinstall the 4066 (remember to power off the Arduino before inserting the IC). Use this sketch to test the multiplex. Point a flashlight to the light sensor and speak close to the microphone while watching the values on the serial terminal. You should see both values changing accordingly. The last tests are the Button. As a starting point use the Button example from Arduino and change and check that the LED of the Arduino Board (connected to pin 13) shall go off when the button is pressed and shall be lit when the button is released. Now, use this sketch to perform an overall test of the board. It reads all the sensors and print the values on the serial terminal. Notice that up to now we have been using the standard 9600 bauds speed from the example sketches, but for the overall tests the speed must be changed to 38400.

Image Notes 1. 100K Potentiometer 2. P2 Stereo plug 3. 100K Potentiometer

Image Notes 1. Remember to change the baud rate. Image Notes 1. Short Circuit between pins 3 and 4 2. CD4066 out of the socket (and out of focus, as well)

http://www.instructables.com/id/Scratching-with-Arduino/

Step 5: Testing with Scratch


After checking that the Sensor Shield is working, it is time to load the Arduino board with the final sketch . This final sketch was built upon the "Serial Event" example from Arduino because it fits well with the ping pong (polling) mechanism of the Scratch application. Then Run Scratch application and then click on the 'sensors' tab at the upleft corner. Then, at the bottom left there shall be a control named Sensor. Right click on it and choose Select "show Watcher") At the up right corner of the screen, at the left of the yellow cat, a box with the sensor values shall appear. Right click on it and select the option "select Serial/USB Port" A list of the available serial ports shall appear. Chose the serial port where the Arduino Board is connected (you can see the port in the Device Manager of Windows). Now the sensor values shall be appearing. Play with them to check that everything is ok Now you can use the sensor values in the box and it is possible to use them for interacting with scratch. Now, use your new shield together with you imagination and... Scratch On!!

Image Notes 1. At the bottom left there shall be a control named "Sensor" Right Click on it 2. Click on the Show Observer

Image Notes 1. click on the 'sensors' tab at the upleft corner.

Image Notes 1. Use the Device Manager to see which is the COM Port of Arduino Image Notes 1. Use the option "select Serial/USB Port" 2. Right click anywhere in this box

http://www.instructables.com/id/Scratching-with-Arduino/

Image Notes 1. Now Choose the serial port in which Arduino is connected

Image Notes 1. With everything OK, the sensor values are displayed on the box 2. Now the sensor data is displayed here

Image Notes 1. Scratch On!! 2. Now I can feel the real world!

Related Instructables

Sous-vide Arduino Shield by sourjuice87

Multicolor lamp using Amarino shield (Photos) by buildcircuit

Make Amarino evaluation shield for AndroidArduinoBluetooth Experiments by buildcircuit

The Arduino DoAnything Shield by blinkyblinky

How to tweet from an Arduino using the wifi sheild by echoalex

The Arduino AA Undershield by Artificial Intelligence

http://www.instructables.com/id/Scratching-with-Arduino/

Advertisements

http://www.instructables.com/id/Scratching-with-Arduino/

You might also like