Hello I just got an Arduino Board for Christmas and I found a program
that uses the Nintendo Wii Nunchuck with the Ardino board here:
http://scratchconnections.wik.is/User:Sburlappp/Emulating_a_ScratchBoard_with_an_Arduino
Here is a simpler version that makes the Arduino act like the scratch board's button and resistance inputs
without the Nunchuck. Right now only the button and inputs A-D work.
You need to install resistors on each Arduino input, just like the original Scratch board has. Otherwise the
values will float around. See the schematic diagram here to add resistors to your Arduino:
http://info.scratch.mit.edu/Sensor_Board
Open the Arduino Editor and copy the code.
// Program Name: ArduinoBoard // Version: 0.6 // Author: Rai and Mike McKenzie // Description: A program that simulates a Scratch board using // an Arduino. This version reads the button and // inputs A-D. // // // Based on Relay Wii Nunchuck status to Scratch // By Mike Donovan // //============================================================================ #include <Wire.h> void ScratchBoardSensorReport(int sensor, int value) { Serial.print( B10000000 | ((sensor & B1111)<<3) | ((value>>7) & B111), BYTE); Serial.print( value & B1111111, BYTE); } void setup() { Serial.begin(38400); pinMode(4, INPUT); } void loop() { // Format output for ScratchBoard emulation // sensor=0-7, value=0-1023 (rescaled by Scratch to 0-100) // 0="A", 1="B", 2="C", 3="D", // 4="Slider", 5="Light", 6="Sound", 7="Button" ScratchBoardSensorReport(0, analogRead(1)); ScratchBoardSensorReport(1, analogRead(2)); ScratchBoardSensorReport(2, analogRead(3)); ScratchBoardSensorReport(3, analogRead(4)); ScratchBoardSensorReport(4, 0); ScratchBoardSensorReport(5, 0); ScratchBoardSensorReport(6, 0); ScratchBoardSensorReport(7, digitalRead(4)?1023:0); // Let Scratch catch up with us delay(30); }
Thanks,
Rai
Offline
Hi mako34,
I've got your answers!
Q. Why do you use wire.h
A. I thought it was needed. My program is based on Mike Donovan's program
which had it so I left it in. It may not need wire.h.
Q. Is there a twi?
A. TWI = Two Wire Interface. No, it doesn't use this.
Q. What do you connect on pin 4? (input?) what about scl (pin 5 on the twi?)
A. Digital pin 4 is the Scratch board button. It's set to an input.
Analogue pin 4 is one of the input resistors. It's like the Scratch
board input D.
Q. What about if I want to connect a led?
A. The Scratch board only supports inputs, so you can't send outputs to
control a LED. My program can only simulate a Scratch board.
I would like to use the Scratch Lego Wedo plugin to somehow control
other types of outputs besides the Wedo.
Thanks,
Rai
Offline
Hello,
Koji Yokokawa (ykoubo) made another ScratchBoard with Arduino.
http://www.yengawa.com/scratch_arduino
It works fine too.
And I added WeDo function to his board. Here it is.
Breadboard version
http://twitpic.com/xm3sh
Shield version
http://twitpic.com/xo9ff
Video
[url]http://www.ustream.tv/recorded/3855360
This board is a hybrid of ScratchBoard and WeDo. So I can control motor by slider value or other sensor inputs. However WeDo protocol is not open at this time. So I needed to extend Scratch by Smalltalk source code 1.4.
Cheers,
Kazuhiro Abe
Last edited by abee (2011-11-18 00:12:45)
Offline
Thank you for your Scratchboard Arduino. It looks like the best Scratch Board emulator I have never seen before. It is very brilliant because it is not using Processing code.
But when I run it for the first time, the scratchboard watcher does not showing static value. All of the sensor value always randomly moving between 0 - 50 points! It is very strange because I still didn't connect my arduino to other sensor or slider or anything else!
Can you explain that situation?
And one question again, are you willing to share the code of ScratchBoard-WeDo based on Arduino? It seems biggest improvement of embedded design that could make my dream about Scratch Robotics comes true.
Thank you very much.
Iwan Suryolaksono
Offline
Are there any way to stabilize sensor reading? Maybe by adding some resistors or another tricks? It is very unstable and I cannot make useful program with the randomness value of analog input reading from Arduino.
Thanks
Iwan S.
Offline
Hello, iwansuryo,
Unstable value of unconnected pin is a characteristic of Arduino.
Check the following document.
http://www.arduino.cc/en/Tutorial/DigitalPins
This also means however, that input pins with nothing connected to them, or with wires connected to them that are not connected to other circuits, will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.
So you need to pull-up (connect to Vcc) or down (connect to GND) these pins.
BTW, I uploaded my custom Scratch image file and Arduino sketch file.
http://squeakland.jp/abee/tmp/SensorBoardWithMotor.zip
Extract it and put SensorBoardWithMotor.image and changes to the folder that you installed Scratch 1.4. Then drag and drop SensorBoardWithMotor.image to Scratch.exe (if you use Windows).
Also you need to upload SensorBoardWithMotor.pde to your Arduino. I use pin3 for motor power, pin4 and pin7 for motor direction. Change them for your motor driver IC and environment. I use TA7291P as a motor driver.
http://kousaku-kousaku.blogspot.com/200 … 7291p.html
(written in Japanese but you can see the pictures.)
I think other motor driver ICs or bridge circuits can be used instead of it.
Cheers,
Kazuhiro Abe
Last edited by abee (2011-11-18 00:14:06)
Offline
Thaaaaank you so much Mr Abee. You are very very generous. It is the biggest step in Scratch Development I have never seen before. I hope that I can fully implement your product for our school curriculum.
Iwan Suryolaksono
Offline
Wow, fancy high tech stuff in here O.o
Offline
I've managed to implement arduino scratchboard properly. Said Mr. Abee is true, that all the sensors reading will only stable after being given a pull-up or pull-down resistor. Then I tried to apply the motor driver schematic using Toshiba TA7291P, just like http://kousaku-kousaku.blogspot.com/2008/06/arduino-dcta7291p.html. I have upload the Arduino code and change the image file with yours.
But everytime I make enable remote sensor connections and then select the right USB/serial port (in my Computer COM 3), the motor always run at full speed, even before I am running any program, and then after a while, the connection is closed. I can run your demo Scratch program and my own program with motor blocks, but it is rare can happened! Because more often is the motor rotating quickly every time the correct port selected and I can not stop it in whatever ways!
Please help me, Mr. Abe. This is very strange. I have tried to change connection of pin 8 of motor driver from external battery to 5V arduino (opwer from USB) and the result is the same.
Right now I am using Seeeduino which is 100% compatible with Arduino Diecimila. I have run many Arduino code before without problem.
Thank you very much.
Iwan Suryolaksono
Offline
I don't know what is your applet folder and file .changes used for. There are many files in your applet folder. But I do not use that folder and that .changes files. Do they have any functions?
I am also worried because every time Scratch connected to the Arduino, then suddenly the motor spinning very fast and make a feedback current. I think that's what causes the connection immediately disconnected from the computer because it responded with motherboard's protection against feedback current.
Iwan Suryolaksono
Offline
Hello, iwansuryo,
It seems there may be some miss connections. I don't know what kind of motor and power supply you used, but usual motor uses hundreds mA current and Arduino cannot provide it. If this current run through your Arduino, the built-in polyswitch (resetable fuse) shutdown the circuit.
To separate problems, could you test a simple circuit that described on kousaku-kousaku? It isn't related Scratch and my works. If it doesn't work fine, the problem may be a primitive.
My custom Scratch image doesn't support automatic port detection. Because I use motor signals instead of PicoBoard identifier.
And .changes file is a source code of Smalltalk. It is used for developers. So you can remove it if you don't modify Smalltalk code.
Cheers,
Kazuhiro Abe
Offline
I am using Lego like motor and have successfully controlling it with 5V and 3V3 power directly from Arduino with just transistor TIP120 as a motor driver. It runs smoothly and I can control it on one way direction with potentiometer without problem!
It is for the very first time I am using Toshiba motor driver. Ok, I will test simple circuit from kousaku immediately.
Thank you very much.
Offline
dogdog wrote:
Hello I just got an Arduino Board for Christmas and I found a program
that uses the Nintendo Wii Nunchuck with the Ardino board here:
http://scratchconnections.wik.is/User:Sburlappp/Emulating_a_ScratchBoard_with_an_Arduino
Here is a simpler version that makes the Arduino act like the scratch board's button and resistance inputs without the Nunchuck. Right now only the button and inputs A-D work.
Hi! I wrote that original sample code, I'm glad you found it useful!
As others have pointed out, the Wire.h part was just for the Wii Nunchuck, you don't need it for your simpler version.
The protocol is very simple, and explained in the Scratch source code. Unfortunately, it's input-only, but I've been looking at the WeDo code lately, and that may hold more promise.
Offline
I just posted a library that does all of this which I wrote from Scratch using the protocl spec for the sensorboard.
http://scratch.mit.edu/forums/viewtopic.php?id=37092
The reason I made this library was to make it as simple as possible for the beginner to interface the Arduino to Scratch.
Remember WeDo is proprietory and I don't think Lego would like people hacking their protocol. I poked around in their DLL and from what I could gather (I am by no means an expert at hacking dlls) it seems like they are using USB HID to carry the protocol. I could be wrong but this would technically rule out the possibility of using Arduino to emulate the Wedo protocol anyway, because the Arduino actually uses a USB based "Virtual Com Port" via the FT232RL.
It would be nice if the official Scratch image would support output to the same serial port as the sensor board natively without having to make changes to the image. This would go a long way to building educational tethered applications buy simply using the motor blocks. Output is possible using the Gogoboard Protocol though but I still like the simplicity of the enabling and using the motor blocks.
Offline
I connected LEGO 8883 motor to my Arduino with LEGO 8886 cable.
http://twitpic.com/1zj98k
This motor is compatible with the motor that is included WeDo kit. I can control it by motor blocks in motion category.
So I call it "IDo" or "YouDo".
Offline
I think all of our problem on connecting Arduino to Scratch has been answered with S4A (More info: http://seaside.citilab.eu/scratch/arduino). I have successfully running many code with it. S4A is more powerful than Lego Wedo. It can be very useful for robotic education. We have to explore it first. And maybe it could become open project to develop S4A more comprehensive so that a new kind of gadget could be realized by young children.
Iwan Suryolaksono
Offline
I agree. S4A is a good solution of physical computing for kids.
However sometimes WeDo and/or PicoBoard emulator by Arduino is still useful.
Because there are many projects and curriculum for them. And PicoBoard emulator can be used with original Scratch image. (Catenary and Modkit is another good solution.)
Anyway it's good that we can choose tools by objective.
Kazuhiro Abe
Offline
What pins do I put the resistors in? I got Scratch to think it was the Pico, but how do I do anything with it when I can't even send any signals?
Offline
I don't know if anyone looks at this anymore, but you can easily communicate in binary serial fashion with the motor on and motor off blocks, and control like 100 outputs! as for inputs, that's a bit harder...
If you want more info about this, just contact me at:
nathansaint1@gmail.com
Offline