I recently ported Pololu’s Zumo 32U4 Arduino Library to the Zumo 2040. The initial Unofficial RP2040 port is now complete and version 0.1.0 can be found in the following repository on GitHub:
It includes all of the functionality found in the 32U4 version with the addition of support for the addressable RGB LEDs found on the Zumo 2040. The list of supported classes/functions includes:
- PololuZumo2040::ButtonA
- PololuZumo2040::ButtonB
- PololuZumo2040::ButtonC
- PololuZumo2040::Buzzer
- PololuZumo2040::Encoders
- PololuZumo2040::OLED
- PololuZumo2040::Motors
- PololuZumo2040::LineSensors
- PololuZumo2040::ProximitySensors
- PololuZumo2040::IMU
- PololuZumo2040::RGBLEDs
- PololuZumo2040::ledYellow()
- PololuZumo2040::readBatteryMillivolts()
Here is an excerpt of Pololu’s BorderDetect.ino example ported to the Zumo 2040:
#include <Zumo2040.h>
#define QTR_THRESHOLD 300
#define REVERSE_SPEED 200
#define TURN_SPEED 200
#define FORWARD_SPEED 200
#define REVERSE_DURATION 200
#define TURN_DURATION 300
OLED display;
ButtonA buttonA;
Buzzer buzzer;
Motors motors;
LineSensors lineSensors;
void waitForButtonAndCountDown()
{
ledYellow(1);
display.clear();
display.print("Press A");
buttonA.waitForButton();
ledYellow(0);
display.clear();
// Play audible countdown.
for (int i = 0; i < 3; i++)
{
display.gotoXY(3, 0);
display.print(3-i);
buzzer.playNote(NOTE_G(3), 200, 15);
delay(1000);
}
display.gotoXY(0, 0);
display.print(" GO! ");
buzzer.playNote(NOTE_G(4), 500, 15);
}
void setup()
{
waitForButtonAndCountDown();
}
void loop()
{
if (buttonA.isPressed())
{
// If button is pressed, stop and wait for another press to
// go again.
motors.setSpeeds(0, 0);
buttonA.waitForRelease();
waitForButtonAndCountDown();
}
lineSensors.read();
if (lineSensors.rawSensorValues[0] < QTR_THRESHOLD)
{
// If leftmost sensor detects line, reverse and turn to the
// right.
motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
delay(REVERSE_DURATION);
motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
delay(TURN_DURATION);
motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
}
else if (lineSensors.rawSensorValues[LINE_SENSOR_COUNT - 1] < QTR_THRESHOLD)
{
// If rightmost sensor detects line, reverse and turn to the
// left.
motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
delay(REVERSE_DURATION);
motors.setSpeeds(-TURN_SPEED, TURN_SPEED);
delay(TURN_DURATION);
motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
}
else
{
// Otherwise, go straight.
motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
}
}
If you happen to try it out, please let me know what issues you encounter so that I can try to fix them and further improve the library. Thanks ahead of time for any feedback you throw my way.
