16-299: Getting started with the Elegoo Balancing Robot Lab (rp2040 version)


Setting up the Arduino Integrated Development Environment (IDE).

1) I assume you have some sort of computer (PC: Mac, Windows, or Linux).

2) Please charge the battery on the robot fully. This makes the battery happier.

3) We need to get the programming environment (Integrated Development Environment (IDE)) from Arduino, which runs on your computer. Download the latest version of the Arduino IDE (2.3.4 as of Feb 2025) onto your computer. In the green area on the right you can pick Windows, Linux, or Mac.

4) Helpful info is available. Googling "how to use Arduino" or searching for it on Youtube will get you many tutorials and helpful videos.

5) We are using the Nano RP2040 Connect which is not the default in the IDE. We need to load information about that type of board (mbed) once from the board library. More information on the Arduino IDE board manager.

5a) After installing the Arduino software, trying running it (Type arduino to a command line in linux, or just click on the Arduino icon in all OSes) with the Arduino on the robot connected to your computer with the USB cable that comes with the robot.

5b) If there is a box saying "Arduino Nano RP204..." you are probably all set.

5c) If there is a box saying "Select Board" you will need to select a board.

5d) Either the software will recognize what you have, which you confirm by clicking on it.

5e) Or you will have to indicate the exact type of board. Search for 2040, click on the line with "Mbed", and then click OK

5f) Say yes to download the board package

5g) You should see

5h) On linux (ubuntu) you should type the following to a command line
sudo /home/$USER/.arduino15/packages/arduino/hardware/mbed_nano/4.2.1/post_install.sh

6) Sometimes the Arduino IDE gets confused about ports. Unplugging and plugging in the USB cable (at the laptop connector) sometimes fixes that. Otherwise, check out the Tools menu and look at the Port entry. "DFU" and "dfu" are bad selections, on linux look for something starting with /dev/tty.




Getting some software to test

Download 16299.zip and put the contents in your top level Arduino directory. This results in (on linux):

~/Arduino$ ls
libraries    test_motor           test_picoencoder  test_voltage
test_button  test_multicolor_led  test_servo

~/Arduino$ ls libraries
PicoEncoder  WiFiNINA
      

Two libraries are already loaded: PicoEncoder for reading the encoders and WiFiNINA for special RP2040 functions.

To run these programs, click on File, Open, and then the program name to load it into a new instance of the arduino window. Click the right arrow to compile and download it to an Nano RP2040 connected with a USB cable. Start a serial monitor (tools menu) at 2000000 baud to see the output.

test_multicolor_led: Most basic test, independent of the controller board. Cycle the multicolor LED through red, green, and blue continuously. Note that the usual basic test, the blink program, doesn't work on our setup because I am using the D13 pin for one of the encoder lines.

test_button: Test the black button on the middle of the front edge on the controller board. The multicolor LED is green when it is not pushed, and turns red when it is pushed.

test_voltage: Reads the battery voltage (USB-provided voltage if no battery is attached).

test_picoencoder: Test the PicoEncoder library reading the encoders.

test_motor: Test driving the motors (need the wheels off the ground, which is easily achieved by putting the robot upside down).

test_servo: Use the encoders and the motors to implement a simple servo (need the wheels off the ground, which is easily achieved by putting the robot upside down).