I have spent the last week porting Pololu’s 3pi+ 32U4 Arduino Library to the 3pi+ 2040. Pololu’s MicroPython library for the 3pi+ 2040 was also referenced during the creation of this port as well. This initial Unofficial RP2040 port is now complete and version 0.1.1 can be found at 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 3pi+ 2040. The list of supported classes includes:
- Pololu3piPlus2040::ButtonA
- Pololu3piPlus2040::ButtonB
- Pololu3piPlus2040::ButtonC
- Pololu3piPlus2040::Buzzer
- Pololu3piPlus2040::Encoders
- Pololu3piPlus2040::OLED
- Pololu3piPlus2040::Motors
- Pololu3piPlus2040::LineSensors
- Pololu3piPlus2040::BumpSensors
- Pololu3piPlus2040::IMU
- Pololu3piPlus2040::RGBLEDs
- Pololu3piPlus2040::ledYellow()
- Pololu3piPlus2040::readBatteryMillivolts()
Here is an example of Pololu’s BumpSensorTest.ino example ported to the RP2040:
#include <Pololu3piPlus2040.h>
BumpSensors bumpSensors;
Buzzer buzzer;
OLED display;
RGBLEDs leds;
void setup()
{
bumpSensors.calibrate();
display.clear();
display.gotoXY(0, 1);
display.print("Bump me!");
leds.set(FRONT_LEFT_LED, GREEN, 0);
leds.set(FRONT_RIGHT_LED, RED, 0);
}
void loop()
{
bumpSensors.read();
if (bumpSensors.leftChanged())
{
leds.setBrightness(FRONT_LEFT_LED, bumpSensors.leftIsPressed() ? 31 : 0);
if (bumpSensors.leftIsPressed())
{
// Left bump sensor was just pressed.
buzzer.play("a32");
display.gotoXY(0, 0);
display.print('L');
}
else
{
// Left bump sensor was just released.
buzzer.play("b32");
display.gotoXY(0, 0);
display.print(' ');
}
}
if (bumpSensors.rightChanged())
{
leds.setBrightness(FRONT_RIGHT_LED, bumpSensors.rightIsPressed() ? 31 : 0);
if (bumpSensors.rightIsPressed())
{
// Right bump sensor was just pressed.
buzzer.play("e32");
display.gotoXY(7, 0);
display.print('R');
}
else
{
// Right bump sensor was just released.
buzzer.play("f32");
display.gotoXY(7, 0);
display.print(' ');
}
}
}
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.