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
[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
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="setup_button_wait_iph" id="1" x="53" y="18">
<field name="PIN">12</field>
<next>
<block type="zumo_motors_FNs" id="2" inline="true">
<field name="DIRECTION">right</field>
<value name="SPEEDA">
<block type="math_number" id="3">
<field name="NUM">125</field>
</block>
</value>
<value name="SPEEDB">
<block type="math_number" id="4">
<field name="NUM">125</field>
</block>
</value>
<next>
<block type="controls_if" id="5" inline="false">
<value name="IF0">
<block type="logic_compare" id="6" inline="true">
<field name="OP">EQ</field>
<value name="A">
<block type="grove_line_finder" id="7">
<field name="PIN">A5</field>
</block>
</value>
<value name="B">
<block type="inout_highlow" id="8">
<field name="BOOL">LOW</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="serial_print" id="9" inline="false">
<value name="CONTENT">
<block type="text" id="10">
<field name="TEXT">Front</field>
</block>
</value>
<next>
<block type="zumo_motors_FNs" id="11" inline="true">
<field name="DIRECTION">forward</field>
<value name="SPEEDA">
<block type="math_number" id="12">
<field name="NUM">200</field>
</block>
</value>
<value name="SPEEDB">
<block type="math_number" id="13">
<field name="NUM">200</field>
</block>
</value>
<next>
<block type="base_delay" id="14" inline="true">
<value name="DELAY_TIME">
<block type="math_number" id="15">
<field name="NUM">500</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</statement>
<next>
<block type="controls_if" id="16" inline="false">
<value name="IF0">
<block type="logic_compare" id="17" inline="true">
<field name="OP">EQ</field>
<value name="A">
<block type="grove_line_finder" id="18">
<field name="PIN">A2</field>
</block>
</value>
<value name="B">
<block type="inout_highlow" id="19">
<field name="BOOL">LOW</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="serial_print" id="20" inline="false">
<value name="CONTENT">
<block type="text" id="21">
<field name="TEXT">Back</field>
</block>
</value>
<next>
<block type="zumo_motors_FNs" id="22" inline="true">
<field name="DIRECTION">backward</field>
<value name="SPEEDA">
<block type="math_number" id="23">
<field name="NUM">200</field>
</block>
</value>
<value name="SPEEDB">
<block type="math_number" id="24">
<field name="NUM">200</field>
</block>
</value>
<next>
<block type="base_delay" id="25" inline="true">
<value name="DELAY_TIME">
<block type="math_number" id="26">
<field name="NUM">500</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</xml>
BlocklyDuino XML for Zumo 1.0 Sonar
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="setup_button_wait_iph" id="27" x="56" y="62">
<field name="PIN">12</field>
<next>
<block type="zumo_motors_FLs" id="63" inline="true">
<field name="DIRECTION">right</field>
<value name="SPEEDA">
<block type="math_number" id="64">
<field name="NUM">150</field>
</block>
</value>
<value name="SPEEDB">
<block type="math_number" id="38">
<field name="NUM">150</field>
</block>
</value>
<next>
<block type="controls_if" id="31" inline="false">
<value name="IF0">
<block type="logic_compare" id="32" inline="true">
<field name="OP">LTE</field>
<value name="A">
<block type="fourpin_ranger" id="82">
<field name="PIN">A4</field>
<field name="PIN2">A5</field>
</block>
</value>
<value name="B">
<block type="math_number" id="86">
<field name="NUM">7</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="serial_print" id="35" inline="false">
<value name="CONTENT">
<block type="text" id="36">
<field name="TEXT">Front</field>
</block>
</value>
<next>
<block type="zumo_motors_FLs" id="75" inline="true">
<field name="DIRECTION">forward</field>
<value name="SPEEDA">
<block type="math_number" id="76">
<field name="NUM">200</field>
</block>
</value>
<value name="SPEEDB">
<block type="math_number" id="77">
<field name="NUM">200</field>
</block>
</value>
<next>
<block type="base_delay" id="91" inline="true">
<value name="DELAY_TIME">
<block type="math_number" id="92">
<field name="NUM">500</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</statement>
</block>
</next>
</block>
</next>
</block>
</xml>