This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-01-01 18:04:41

dogdog
Scratcher
Registered: 2007-10-12
Posts: 70

Using an Arduino Board as a Scratch Board.

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.

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

 

#2 2010-01-05 20:47:58

mako34
Scratcher
Registered: 2010-01-05
Posts: 5

Re: Using an Arduino Board as a Scratch Board.

hi, dogdog
A question about this,
why do you use wire.h
is there a twi? 
what do you connect on pin 4? (input?) what about scl (pin 5 on the twi?)

also, what about if I want to connect a led?
thank you
wink

Offline

 

#3 2010-01-06 22:29:42

dogdog
Scratcher
Registered: 2007-10-12
Posts: 70

Re: Using an Arduino Board as a Scratch Board.

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

 

#4 2010-01-13 22:10:08

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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

 

#5 2010-01-16 03:30:05

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#6 2010-01-16 09:25:28

mako34
Scratcher
Registered: 2010-01-05
Posts: 5

Re: Using an Arduino Board as a Scratch Board.

Hi this is great,, tnx

Offline

 

#7 2010-01-17 10:05:17

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#8 2010-01-18 01:04:50

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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

 

#9 2010-01-18 04:34:52

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#10 2010-01-18 06:59:03

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

Thank you.
There are many scrachers who has talent. I only put the last piece on their great works.
I'd like to know your school curriculum. I hope you share it for all.

Cheers,
Kazuhiro Abe

Offline

 

#11 2010-01-18 07:51:11

Ace-of-Spades
Scratcher
Registered: 2010-01-08
Posts: 1000+

Re: Using an Arduino Board as a Scratch Board.

Wow, fancy high tech stuff in here O.o


11110010100011010100011010101000100011011011001010111100101000110101000110101010001000110110110010101111001010001101010001101010100010001101101100101011110010100011010100011010101000100011011011001010
110101010010001010101010101010101010101010100110101010010101010010101001101011010101010010101010101

Offline

 

#12 2010-01-23 03:50:10

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

Korean HelloBoard is also based on Arduino.
http://scratch.mit.edu/projects/picxenk/853363
http://helloboard.piny.cc/
http://vidovit.tumblr.com/post/348230238/a-short-introduction-of-helloboard

Offline

 

#13 2010-01-24 03:58:30

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#14 2010-01-24 05:58:37

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#15 2010-01-24 07:42:09

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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

 

#16 2010-01-24 10:07:16

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#17 2010-06-02 14:32:45

sburlappp
Scratcher
Registered: 2009-05-07
Posts: 2

Re: Using an Arduino Board as a Scratch Board.

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

 

#18 2010-06-02 16:02:10

zageek
Scratcher
Registered: 2010-04-05
Posts: 3

Re: Using an Arduino Board as a Scratch Board.

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

 

#19 2010-06-25 00:05:19

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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

 

#20 2010-08-12 23:16:58

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

I shared my slide of today's self-organized session of Scratch@MIT, "How to make your own WeDo" at 493 on 3PM. http://bit.ly/bvcbrx

Offline

 

#21 2010-10-29 01:49:30

iwansuryo
Scratcher
Registered: 2008-05-16
Posts: 29

Re: Using an Arduino Board as a Scratch Board.

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

 

#22 2010-11-02 13:29:08

abee
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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

 

#23 2011-11-04 17:27:20

cocolover76
Scratcher
Registered: 2011-10-09
Posts: 500+

Re: Using an Arduino Board as a Scratch Board.

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?


http://i.imgur.com/HfEPZ.gifhttp://i.imgur.com/pvKb6.png

Offline

 

#24 2012-01-09 14:56:16

james7878
New Scratcher
Registered: 2012-01-09
Posts: 1

Re: Using an Arduino Board as a Scratch Board.

Thank you for sharing this post

Offline

 

#25 2012-04-14 17:10:28

Nathanator1416J
Scratcher
Registered: 2012-02-21
Posts: 100+

Re: Using an Arduino Board as a Scratch Board.

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


http://wiki.scratch.mit.edu/images/Ptp.gif PEPPERTREE  Productions (PtP)
Tourmaline Scientific Research Programs

Offline

 

Board footer