My port of the 3π+ 2040 robot Arduino Library is now complete

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.

4 Likes

Version 0.1.2 (3rd alpha release) of the 3π+ 2040 robot Arduino Library is now available.

Version history

  • 0.1.2 (2023-4-8): Third alpha release from community with a few updates:
    • Moved Pololu3piPlus2040::BumpSensors::BumpSide up in namespace to Pololu3piPlus2040::BumpSide.
    • Simplify LineSensors API to remove sensorValues out parameter.
    • Added RGBLEDs::get() and RGBLEDs::getBrightness() methods to match recent MicroPython library updates.
    • Simplified and fixed a few bugs in my C implementation of the RGBLEDs::hsv2rgb() method.
    • Remove buzzer click upon device reset.
    • Fixes to BumpSensors class constructor and documentation for read() method.
  • 0.1.1 (2023-4-4): Second alpha release from community with Motor & Buzzer PWM fixes.
  • 0.1.0 (2023-4-4): Initial alpha release from community.

Work has started on a 0.2.x branch which leverages Pololu’s 3π+ 2040 C Library where possible.

1 Like

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


The detailed error message:
C:\Users\Han\Documents\Arduino\libraries\Pololu3piPlus2040\src\Pololu3piPlus2040Buzzer.cpp: In member function ‘void Pololu3piPlus2040::Buzzer::playFrequency(unsigned int, unsigned int, unsigned char)’:
C:\Users\Han\Documents\Arduino\libraries\Pololu3piPlus2040\src\Pololu3piPlus2040Buzzer.cpp:54:21: error: invalid conversion from ‘pwm_config*’ to ‘uint {aka unsigned int}’ [-fpermissive]
pwm_init(sliceNo, &config, false);
^~~~~~~
C:\Users\Han\Documents\Arduino\libraries\Pololu3piPlus2040\src\Pololu3piPlus2040Buzzer.cpp:54:35: error: cannot convert ‘bool’ to ‘pwm_config*’ for argument ‘3’ to ‘void pwm_init(uint, uint, pwm_config*, bool)’
pwm_init(sliceNo, &config, false);
^

exit status 1

Compilation error: exit status 1

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.

Thank you for your quick reply, the version information is shown in the figure below

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.

Thanks for your help and best wishes

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.

@gis81576, it should now be fixed. You can try downloading and installing the updated .ZIP for my library. Let me know how it goes.

Thanks again for reporting the issue. Much appreciated.

-Adam

Hi Adam: Thank you very much for your help, currently the library is working fine on the Arduino IDE, thank you again, best wishes.

1 Like