Skip to main content

Scratch+Arduino

Arduino ScratchBoard Emulator

Scratch+Arduino

Arduino ScratchBoard Emulator はMITで作られた子ども向けプログラミング環境Scratchに手軽なマイコンボードArduinoをつなげて遊ぶためのArduinoプログラムです。

Arduino ScratchBoard Emulator is a program to play Scratch (programming environment for children by MIT) connected with Arduino (open source computer board). 

 

デモ動画 「Arduino ScratchBoard Emulator」YouTube

Demo Movie "Arduino ScratchBoard Emulator" on YouTube

 

道具のインストール | Install the tools

まずは、ScratchとArduinoの開発ツールをダウンロードしましょう。どちらもインターネットから誰でも無料でダウンロードできます。

First, download the tools of Scratch and Arduino. Both of them are downloadable from Internet for free. 

Arduino IDEの使い方は「Arduino のはじめかた」を参考にしてください。

One of a good starting point for Arduino IDE is "Arduino Tutorial Lesson 1" at ladyada.net

 

Arduinoの準備 | Setup of Arduino

つぎに、Arduinoにプログラムを書き込みます。

Next, upload the program to Arduino. 

このプログラムはScratchからUSB経由で受け取ったトリガーメッセージに対応してセンサー値を返すというものです。ScratchBoard(別名PicoBoard)というIOボードのプロトコルを使っています。

This program return a sensor value corresponding to the trigger message from Scratch via USB. 

阿部さんによりモーター(出力)を使えるようにしてあります。モーターブロックを使うにはArduinoスケッチに加えてScratch側も変更があり、Scratch.imageの代わりにSensorBoardWithMotor.imageを使って実行します。これを使うにはモーターだけでなく、モータードライバーを使った回路が必要です。例えば以下を参考にしてください。その際、ピン番号は後述のものに適宜変更してください。

建築発明工作ゼミ2008: Arduino 小型DCモータ/TA7291P

 

以下にモーターを使うのに必要なファイルがすべては入ったパッケージを置いておきます。

 

ScratchBoard Emulator であそぶ | Play ScratchBoard Emulator

Scratchを起動して、Scratch+Arduinoのスケッチを書き込んだArduinoをUSBでつなぎます。そして、Scratchの「調べる」カテゴリの「センサーの値」のブロックを長押しすると出るメニューで「ScratchBoard監視板を表示」を選択するとステージにScratchBoardの値が表示されます。

Start Scratch and connect the Arduino which uploaded the Scratch+Arduino sketch to your PC with USB. Then hold pressing the 'sensor value' block in the category 'Sensing' until the menu appeared and select 'Show ScratchBoard Watcher'. You will see the values of ScratchBoard on the stage.

表示された監視板が「オン」になっていたり値がすべて「0」だったら、監視板を長押しして「シリアルかUSBのポートを選択」メニューを選びます。ポート名一覧からArduinoのポートを選択してください。監視板に「オン」と表示されて値が激しく変化し始めたら通信が出来ています(何も接続していないのに値が変わるのは空気中に電気的なノイズがあるからです)。

If the title of the ScratchBoard Watcher was 'off' or the values were all '0', press and hold to get the menu and select 'select serial/USB port'. Select the port of Arduino from the port name list. When the watcher title turn to 'on' and displays changing numbers, the connection is established. Electronic noise in the air causes to change the value of the opened pins.

ScratchBoard Watcher and select port menu

Arduinoのアナログインプットにセンサなどを接続して値の変化を確認してください。直値の0-1024を0-100に換算しています。ScratchBoard上の名前とArduinoのピン番号の対応はつぎのようになっています。

Check the values are changed by connected a sensor to an analog input pin on the Arduino. The values are converted from the real value 0 - 1024 to 0 - 100. The name on the ScratchBoard corresponds to pin numbers on the Arduino with this table.

Scratch Analog Input Pin
スライダー (slider) 0
明るさ (light) 1
音 (loudness) 2
抵抗A (resistance A) 3
抵抗B (resistance B) 4
抵抗C (resistance C) 5
抵抗D (resistance D) 5 (Cと同じ値 (same value as C))

 

Scratch Digital Input Pin
ボタン 2

 

Scratch Digital Output Pin
モーターのパワー(PWM) 11
回転こちら向き(制御信号1) 4
回転あちら向き(制御信号2) 7

 ここまで来れば、あとはScratchのふつうのブロックとしてセンサーの値を使えます。「調べる」カテゴリの「センサーの値」を動きや音の数値に、「ボタンが押された」を制御の判断に使ってプログラムを組んで遊んでみましょう。

モーターを使うときは「動き」カテゴリの末尾に自動的に追加される「モーターをオンにする」などのブロックを使ってください。これらのブロックが表示されないときは、「編集」メニューから「モーターのブロックを表示する」を選んでください。

 

ScratchBoardを使ったScratchの遊び方はこちらが参考になります。 → 「Picoboard ためしてみよう

Read "Instruction of PicoBoard" to play Scratch with ScratchBoard. 

 


Similar Entries