Scratch & Python

Learn how to use our Python/Scratch listener to control your robot via Scratch


Oveview

Scratch can be used to control SMARS robots, however there are a few caveats: Only Scratch 1.4 can send messages to external devices, and sensing isn’t working yet (but will be soon!).

Scratch

There are 3 parts: The SMARS Quad itself, a computer running Scratch 1.4 and the SMARS Raspberry Pi Zero running the Python ScratchListener.py program. The ScratchListener program listens out for broadcast messages from the computer running Scratch 1.4. These messages can be:

   
WalkForward The robot will walk forward a couple of steps
WalkBackward The robot will walk backward a couple of steps
TurnLeft The robot will turn left
TurnRight The robot will turn right
Stand The robot will stand up
Sit The robot will sit down

Get the Code

On the raspberry pi, type:

git clone https://www.github.com/kevinmcaleer/smars

Run the scratch listener Python program

To Run the scratchlistener.py on the SMARS raspberrypi zero, type:

cd smars

python ScratchListener.py

A prompt will ask for the IP address of the computer running the Scratch Script, don’t fill that out just yet (or it will report an error about the host refusing the connection)

Run Scratch

Run Scratch 1.4 on a computer (and this doesn’t have to be the SMARS raspberry pi)

Load the Scratch SMARS Demo Program

Load the Scratch SMARS Demo program

Scratch

Type IP Address

Type the IP address of the computer running scratch 1.4 into the ScratchListener.py program

Scratch

Run the script

Click run on the Scratch program, that’s the litte green flag icon.

Control the SMARS

Control the SMARS quad in Scratch using the keys W, S, Up arrow, Down arrow, Left arrow, Right arrow

Controlling a SMARS Quad Robot with Scratch and Python.