Scratching With Arduino

Embed Size (px)

Citation preview

  • 7/29/2019 Scratching With Arduino

    1/9

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

    Food Living Outside Play Technology Workshop

    Scratching with Arduinoby 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 ...............................................................................................................

    http://www.instructables.com/member/danjovic/?utm_source=pdf&utm_campaign=titlehttp://www.instructables.com/tag/type-id/category-workshop/http://www.instructables.com/tag/type-id/category-technology/http://www.instructables.com/tag/type-id/category-play/http://www.instructables.com/tag/type-id/category-outside/http://www.instructables.com/tag/type-id/category-living/http://www.instructables.com/tag/type-id/category-food/
  • 7/29/2019 Scratching With Arduino

    2/9

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

    Intro: Scratching with ArduinoMIT 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 providininteraction 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 bocan be found here

    For the Impatient:

    Final Arduino Sketch is herePrinted Circuito Board is here (eagle )Schematics are here (pdf /eagle )

    Step 1:Preparing GroundThe 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 SerPort 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 repliewith 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 interva

    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 / Sensor0 / Resistance D1 / Resistance C2 / Resistance B3 / button4 / Resistance A5 / Light6 / Sound7 / Slider8-14 / Not Used15 / 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 Notes1. Channel ID bits2. stuff3. stuff4. Sensor data, LSBits5. Sensor data, LSBits

    http://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/ScratchBoard_Tech_InfoR2.pdfhttps://www.dropbox.com/s/aw4z9pvb5q1rljh/Sensor_Shield.schhttps://www.dropbox.com/s/8j5okcff4fwlw52/Sensor_Shield.pdfhttps://www.dropbox.com/s/kga1x0hqd0gxgcl/Sensor_Shield.brdhttps://www.dropbox.com/s/5mtug8norf2kj9b/SensorShield.inohttp://info.scratch.mit.edu/Sensor_Boardhttp://info.scratch.mit.edu/sites/infoscratch.media.mit.edu/files/file/ScratchBoardLicense.txthttp://www.picocricket.com/picoboard.htmlhttp://scratch.mit.edu/
  • 7/29/2019 Scratching With Arduino

    3/9

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

    Step 2:The challengesExtra 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 6channels. 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 activaand 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 toccur much slower than the switching.

    Of course, the switching scheme had to be tested before going on, but luckily, it worked very well!!

    DIYable BoardA 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 witsensors, 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 thresult 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 Notes1. Multiplexed output. Goes to the Analog Input 4 of Arduino2. Each output activates a single switch. They shall not be activatedsimultaneously

    Image Notes1. This is the Arduino Severino Board, a Single face DIY version of ArduinoPRO2. CD4066 - Quad Bidirectional Analog Switch3. Resistors used to provide VCC/2 for testing

    https://www.dropbox.com/s/aw4z9pvb5q1rljh/Sensor_Shield.schhttps://www.dropbox.com/s/8j5okcff4fwlw52/Sensor_Shield.pdfhttps://www.dropbox.com/s/kga1x0hqd0gxgcl/Sensor_Shield.brdhttp://www.picocricket.com/picoboard.html
  • 7/29/2019 Scratching With Arduino

    4/9

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

    Image Notes1. Two Stereo Jacks have been used to save space and ease the routing of theboard

    Image Notes1. Light Sensor2. Resistance Sensor Inputs3. Slider4. Analog Multiplex5. Button

    6. Sound Sensor and conditioning7. Unused analog switches

    Step 3:Board ConstructionThe 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 itbecause 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 solderNote: 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 founshort 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 Notes1. Electret Microphone2. Light Sensor3. Push Button4. OPAMP

    5. CD4066 Quad CMOS Bidirectional analog switch6. Only 1 jumper (this image is from revised layout)7. Slider Potentiometer8. Jack for resistancechannels A,B9. Jack for resistance

    Image Notes1. No need to be populated. After all it is only a prototype2. The local supplier stock ran out

    http://www.adilmarti.com.br/verProduto.php?idProduto=52&consulta=0&k=1
  • 7/29/2019 Scratching With Arduino

    5/9

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

    channels A,B

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

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

    Image Notes1. After etching there was a short circuit here. The track were too close from thepads.

    Image Notes1. Assembled Board attached to an Arduino UNO

    Step 4:Testing the BoardAfter 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 accordithe 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->SeriMonitor).

    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.

  • 7/29/2019 Scratching With Arduino

    6/9

    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 andshort 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-transistoused.

    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 samADC 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

    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 shousee 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 13shall 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 usthe standard 9600 bauds speed from the example sketches, but for the overall tests the speed must be changed to 38400.

    Image Notes1. 100K Potentiometer2. P2 Stereo plug3. 100K Potentiometer

    Image Notes1. Short Circuit between pins 3 and 42. CD4066 out of the socket (and out of focus, as well)

    Image Notes1. Remember to change the baud rate.

    https://www.dropbox.com/s/jvasqk73htbkr99/TestePlaca.inohttps://www.dropbox.com/s/ewgo03h1uvmv1c3/TesteMultiplex.ino
  • 7/29/2019 Scratching With Arduino

    7/9

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

    Step 5:Testing with ScratchAfter 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 Notes1. click on the 'sensors' tab at the upleft corner.

    Image Notes1. At the bottom left there shall be a control named "Sensor" Right Click on it2. Click on the Show Observer

    Image Notes1. Use the option "select Serial/USB Port"2. Right click anywhere in this box

    Image Notes1. Use the Device Manager to see which is the COM Port of Arduino

    https://www.dropbox.com/s/5mtug8norf2kj9b/SensorShield.ino
  • 7/29/2019 Scratching With Arduino

    8/9

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

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

    Image Notes1. With everything OK, the sensor values are displayed on the box2. Now the sensor data is displayed here

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

    Related Instructables

    Sous-videArduino Shield

    by sourjuice87

    Multicolor lampusing Amarinoshield (Photos)

    by buildcircuit

    Make Amarinoevaluationshield forAndroid-Arduino-Bluetooth

    Experiments by

    buildcircuit

    The ArduinoDoAnything

    Shield by

    blinkyblinky

    How to tweetfrom an Arduinousing the wifi

    sheild by

    echoalex

    The Arduino AA

    Undershield by

    ArtificialIntelligence

    http://www.instructables.com/member/Artificial%20Intelligence/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/Artificial%20Intelligence/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-AA-Undershield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-AA-Undershield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-AA-Undershield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/echoalex/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-to-tweet-from-an-Arduino-using-the-wifi-sheild/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-to-tweet-from-an-Arduino-using-the-wifi-sheild/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-to-tweet-from-an-Arduino-using-the-wifi-sheild/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-to-tweet-from-an-Arduino-using-the-wifi-sheild/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/How-to-tweet-from-an-Arduino-using-the-wifi-sheild/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/blinkyblinky/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-DoAnything-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-DoAnything-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-DoAnything-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/The-Arduino-DoAnything-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/buildcircuit/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Make-Amarino-evaluation-shield-for-Android-Arduino/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/buildcircuit/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Multicolor-lamp-using-Amarino-shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Multicolor-lamp-using-Amarino-shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Multicolor-lamp-using-Amarino-shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Multicolor-lamp-using-Amarino-shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Multicolor-lamp-using-Amarino-shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/member/sourjuice87/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Sous-vide-Arduino-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Sous-vide-Arduino-Shield/?utm_source=pdf&utm_campaign=relatedhttp://www.instructables.com/id/Sous-vide-Arduino-Shield/?utm_source=pdf&utm_campaign=related
  • 7/29/2019 Scratching With Arduino

    9/9

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

    vertisemets