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.
Hello: Thank you for your “3π+ 2040 robot Arduino Library”. I have encountered some problems in using it recently. Can you provide some suggestions, thank you! The description of the problem is as follows:
OS: windows 10
It looks like the Pico C SDK in your configuration expects pwm_init() to take a different set of arguments from the one on my machine
We appear to be running the same version of the Arduino IDE, version 2.1.0
Can you bring up the Boards Manager in the Arduino IDE and check to see if you have the same version of the Arduino Mbed OS RP2040 Boards installed? I have version 4.0.2, the latest available, installed on mine.
Thanks for the additional information. I will take a look at a few more things on my end to see if I can reproduce the problem you are hitting. I have an idea of what might be going on.
I reproduced your problem after I removed a pre-release version of the Arduino Mbed board package that I had manually installed on my machine for another project.
Thanks for bringing this issue to my attention. I will try to get you a fixed version soon.