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.

2 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