Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Visual Zumo Programming with BlocklyDuino


#1

If you’re looking for a visual programming environment to work with Arduino & Zumo, I’d recommend BlocklyDuino. github.com/gasolin/BlocklyDuino
This post is part show & tell, part breadcrumbs for anyone else who wants to contribute. Sorry for the length of the post, I ran out of attachments.
I’m trying to teach my kids programming with Zumo robots. I’ve tried Ardublock, Minibloq & Modkit.
If I could mix them all up and take the best of them I would, but ended up using BlocklyDuino because the code was easy for me to modify web-based code & create exactly the blocks I needed. Note that as of this writing, my pull request is not accepted into the master, so you may want to pull a copy here if you’re in a hurry. I hope to not maintain my fork.
github.com/EricSKennedy/BlocklyDuino

I have two zumos, a 1.0 with a sonar distance sensor, and a 1.2 with four IR sensors for eyes. I’d recommend sonar as easier to work with, but it may be because I’m buying cheap sensors. If you look at the code, you’ll note I do not have anything in for sensing the sumo ring border - I currently lack a ring and want to stick with tested code.
Attached for your entertainment are details & files for two different Zumo robots.
I flipped the left motor on my 1.0 zumo, so you’ll find that I created a full set of BlocklyDunio blocks for the direction-following challenged. I do not believe these will work with the 32U4, but feel free to send me a 32U4 if you’d like the blocks made :smiley:

[code][attachment=2]BD_SonarEyesFL.jpg[/attachment]
[attachment=1]IR-Eyes-BlocklyDuino.jpg[/attachment]
[attachment=0]Zumo-Robots.JPG[/attachment]
The code is also included, you’ll need to save it to an INO or XML file to read it into the Arduino IDE or BLocklyDuino Load XML

INO for IR Zumo 1.2
const int buttonPin = 12;
int buttonState = 0;
void WaitForButton (){
buttonState = digitalRead(buttonPin);
while(buttonState == HIGH) {buttonState = digitalRead(buttonPin);}}

void right()
{
analogWrite(9,125);//Motor A speed
analogWrite(10,125);//Motor B speed
digitalWrite(7,HIGH);//turn DC Motor B (right) move clockwise
digitalWrite(8,LOW);//turn DC Motor A (left) move anti-clockwise
}

void forward()
{
analogWrite(9,200);//Motor A speed
analogWrite(10,200);//Motor B speed
digitalWrite(7,LOW);//turn DC Motor B (right) move clockwise
digitalWrite(8,LOW);//turn DC Motor A (left) move clockwise
}

void backward()
{
analogWrite(9,200);//Motor A speed
analogWrite(10,200);//Motor B speed
digitalWrite(7,HIGH);//turn DC Motor B (right) move anticlockwise
digitalWrite(8,HIGH);//turn DC Motor A (left) move anticlockwise
}

void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
WaitForButton();
delay(5000);

pinMode(7,OUTPUT);//directionPinA
pinMode(8,OUTPUT);//directionPinB
pinMode(9,OUTPUT);//speedPinA
pinMode(10,OUTPUT);//speedPinB

pinMode(A5, INPUT);
Serial.begin(9600);

pinMode(A2, INPUT);
}

void loop()
{
right();
if (digitalRead(A5) == LOW) {
Serial.print(“Front”);
Serial.print("\t");
forward();
delay(500);

}
if (digitalRead(A2) == LOW) {
Serial.print(“Back”);
Serial.print("\t");
backward();
delay(500);

}

}

INO for Sonar Zumo 1.2

const int buttonPin = 12;
int buttonState = 0;
void WaitForButton (){
buttonState = digitalRead(buttonPin);
while(buttonState == HIGH) {buttonState = digitalRead(buttonPin);}}

void right()
{
analogWrite(9,150);//Motor A speed
analogWrite(10,150);//Motor B speed
digitalWrite(7,LOW);//turn DC Motor B (right) move clockwise
digitalWrite(8,LOW);//turn DC Motor A (left) move anti-clockwise
}

const int pingPinA4 = A4;
const int sensorPinA5 = A5;

long PingA4()
{
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(pingPinA4, LOW);
delayMicroseconds(2);
digitalWrite(pingPinA4, HIGH);
delayMicroseconds(2);
digitalWrite(pingPinA4, LOW);
// A different pin is used to read the signal from the PING))): a HIGH
long microseconds = pulseIn(sensorPinA5, HIGH);
return microseconds / 74 / 2;
}

void forward()
{
analogWrite(9,200);//Motor A speed
analogWrite(10,200);//Motor B speed
digitalWrite(7,HIGH);//turn DC Motor B (right) move clockwise
digitalWrite(8,LOW);//turn DC Motor A (left) move clockwise
}

void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
WaitForButton();
delay(5000);

pinMode(7,OUTPUT);//directionPinA
pinMode(8,OUTPUT);//directionPinB
pinMode(9,OUTPUT);//speedPinA
pinMode(10,OUTPUT);//speedPinB

pinMode(pingPinA4, OUTPUT);
pinMode(sensorPinA5, INPUT);

Serial.begin(9600);

}

void loop()
{
right();
if (PingA4() <= 7) {
Serial.print(“Front”);
Serial.print("\t");
forward();
delay(500);

}

}

BlocklyDuino XML for IR Zumo 1.2

12 right 125 125 EQ A5 LOW Front forward 200 200 500 EQ A2 LOW Back backward 200 200 500

BlocklyDuino XML for Zumo 1.0 Sonar

12 right 150 150 LTE A4 A5 7 Front forward 200 200 500 [/code]



#2

Hello.

Thank you for sharing your modified version of the BlocklyDuino that you got to work with your Zumos. Hopefully, in the future, BlocklyDuino could add full support for the Zumo. It would be a useful tool for beginners.

- Amanda


#3

Zumo looks cool, but I have yet to buy/play with it. I have played with BlocklyDuino, and I just wanted to let you know that there are several versions of it available from different development groups. Seems different groups are evolving the language in different directions. So, if the one you are using does not have particular blocks for what you are trying to do, Google “BlocklyDuino” and look for another version to check out and see if they have the features you need. As of Dec, 2016, there’s a couple site with what I call “Basic Vanilla” BlocklyDuino, and a couple more with a version I call the “Grove Edition”, then there is the French “Technologies College” version, which seems to have been recently expanded and includes blocks for a wide variety of tasks beyond what even is offered in BlocklyDuino Enhanced. The French version seems to be maybe a bit unstable now, but soon should be a great version to play with, The BlocklyDuino Enhanced version is by a Tunisian educator. He has since come out with a version for the NodeMCU board, a ESP8266 SoC with WiFi capabilities, This version is called TUNIOT (for TUNisia Internet Of Things) and it includes a bunch of new code blocks that enable you to write WiFi based client and server scripts. There’s a series of YouTube videos about it at this URL:

Cool stuff for those just getting started programming Arduino and NodeMCU WiFi MCU boards.