Servo and motor control with Raspberry Pi Pico, CircuitPython, and Wukong 2040 breakout board

ELECFREAKS Wukong 2040 is a multifunctional breakout board designed for Raspberry Pi Pico. It is equipped with interfaces for four DC motors, up to twelve servos, a buzzer, A\B buttons, RGB “rainbow” lights, a Reset button, etc… The board can be powered by a single 18650 3.7V LiPo battery and integrates a power management IC that monitors the battery level and can also charge the battery via a USB charger. Battery life is typically 60 minutes per charge but can last over 120 minutes depending on the load.

 

ELECFREAKS Wukong 2040 Breakout Board For Raspberry Pi Pico

Wukong 2040 key features and specifications

Description of the Wukong 2040 interfaces

Wukong 2040 specifications

Specifications and dimensions of the Wukong 2040 Expansion Board for Raspberry Pi Pico

Wukong 2040 EF02054 Raspberry Pi Pico Breakout boardThe Wukong 2040 breakout board for the Raspberry Pi Pico can control up to four DC motors and up to 12 servo motors as shown in the diagram below.

Wukong 2040 Connection DiagramPinout diagram of the Wukong 2040 board

Raspberry Pi Pico Wukong 2040 pinout diagram

Getting started with the Wukong 2040 and Raspberry Pi Pico using CircuitPython

Board and host preparation

The Wukong 2040 breakout board can be used with the Raspberry Pi Pico, which we’ll use here, or the Raspberry Pi Pico W board, and uses one 18650 battery for power. We went with 2,200mAh battery for this tutorial/review.

Wukong 2040 Raspberry Pi Pico 18650 LiPo battery

The Raspberry Pi Pico board supports C/C++, MicroPython, CircuitPython, and other programming languages. We’ll go with CircuitPython as it is an easy-to-use programming language and we can download the UF2 firmware from the official website.

Raspberry Pi Pico CircuitPython

Once we have downloaded the firmware, we can press and hold the BOOTSEL button to enter flashing mode.

Wukong 2040 Raspberry Pi Pico Boot buttonThen we can connect the Raspberry Pi Pico to the computer using a USB cable and release the BOOSEL button on the Raspberry Pi Pico board. The board should show up as “RPI-RP2” drive.

RPI-RP2

Now drag the previously downloaded UF2 file to the “RPI-RP2” drive and once the installation is complete, the “RPI-RP2” drive will disappear and the “CIRCUITPY” drive will appear in its place. That means we have successfully installed the CircuitPython firmware.

Raspberry Pi Pico CircuitPy

We’ll use the Thonny Python IDE for programming which can install on Windows, Linux, macOS, or even run from a Raspberry Pi SBC. Once the installation is complete, open Thonny, then click on the “Run” menu and select “Configure interperter”.

Thonny Configure Interpreter

In the “Interperter” window:

  1. Click to select “CircuitPython(generic)”
  2. Click “OK” to complete the setup.

Thonny CircuitPython

Using the A and B buttons on the Wukong 2040

Now that your board and host computer are ready we can start programming the board. We’ll start with the buttons. Push button A is connected to GPIO 18 of the Raspberry Pi Pico board and Push button B is connected to GPIO 19.

Wukong 2040 Raspberry Pi Pico Buttons A/ BThe code sample below if the A button is pressed, the LED on the Raspberry Pi Pico board will turn on, or if the B button is pressed, the LED on the Raspberry Pi Pico board will turn off.

Programming the buzzer

Let’s now play with the buzzer connected to GPIO 9

Wukong 2040 Raspberry Pi Pico Buzzer

The code below generates a sine wave to play sound through the buzzer after button A is pressed:

Wukong 2040 RGB LED control

The Wukong 2040 board also comes with two RGB LED (WS2812B) connected to GPIO 22 of the Raspberry Pi Pico board.

Wukong 2040 RGB LEDWe’ll use Adafruit’s Neopixel library to program the RGB LED  with CircuitPython. Once the neopixel.py library is downloaded, we can copy it to the “lib” directory of the “CIRCUITPY” drive.

neopixel.pyThe code below changes the color of the two RGB lights in an infinite loop.

DC motor control test with Raspberry Pi Pico and Wukong 2040

Let’s now connect four DC motors to the M1-4 ports of the Wukong 2040 which are themselves wired to the Raspberry Pi Pico as follows:

  • Port M1 is connected to GPIO20 and GPIO21
  • Port M2 is connected to GPIO10 and GPIO11
  • Port M3 is connected to GPIO12 and GPIO13
  • Port M4 is connected to GPIO14 and GPIO15

Wukong 2040 Raspberry Pi Pico DC Motors

We’ll need another library to program the DC motor controller with CircuitPython: adafruit_motor. Copy the adafruit_motor folder to the “lib” directory of the “CIRCUITPY” drive.

Adafruit Motor library circuitpythonThe motor control code sample for Raspberry Pi Pico below sets the speed of the four DC motors by adjusting the frequency of the pulse signal (PWM). We can create basic movement functions of motor rotation, forward, backward, left turn, right turn, motor stop, etc… The test program instructs the motors to go forward for 5 seconds, then stop all motors for 1 second, then reverse for 5 seconds, then stop all motors for 1 second, and so on in an infinite loop.


The board can also be installed into a proper robot with four wheels such as the mecanum wheel-powered robot shown below.

Raspberry Pi Pico Wukong 2040 Motor Control

Raspberry Pi Pico Wukong 2040 Motor Control CircuitPython

Raspberry Pi Pico Servo control with CircuitPython

There are 12 input/output interfaces on the Wukong 2040 board (GPIO: 0, 1, 2, 3, 4, 5, 6, 7, 8, 26, 27, 28), which can be used to drive small servos. In this experiment, we will connect one servo motor to channel 0.

Raspberry Pi Pico Servo Wukong 2040

The test program below makes the servo motor rotates from 0 degrees to 180 degrees, and then from 180 degrees to 0, repeating the cycle in an infinite loop.

Driving an I2C OLED display with CircuitPython

The Wukong 2040 breakout board for Raspberry Pi Pico has a built-in I2C interface (GP16, GP17) that can drive an OLED display, and we’ll use one with 128×64 resolution in this review.

Wukong 2040 I2C OLED display

In order to program an OLED display with CircuitPython we’ll use two more libraries from Adafruit: adafruit_ssd1306.py and adafruit_framebuf.py. Copy both files to the “lib” directory in the “CIRCUITPY” drive.

adafruit framebuf ssd1306 CircuitPython Libraries

 

The code sample below fills the screen, then draws a horizontal line, a vertical line, a circle, and a square to the OLED:

Conclusion

The Wukong 2040 breakout board for Raspberry Pi Pico can be used to extend the capabilities of the Pico board with the DC motor and servo control connection especially interesting to build robots such as a mecanum wheel-powered robot. While the Wukong 2040 Breakout Board for Raspberry Pi Pico can be programmed with many languages, CircuitPython based on the Python language is easy to use. The included 18650 battery holder also makes it convenient for powering your project, and the ability to charge the battery directly from the Wukong 2040 is also a plus.

I would like to thank ELECFREAKS for sending us the Wukong 2040 breakout board for Raspberry Pi Pico. It can be purchased for $9.90 on ELECFREAKS store.

This tutorial is a translation of the original review on CNX Software Thailand.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
5 Comments
oldest
newest
jamez
jamez
1 year ago

Why not just stick the 2040 on board? and get rid of those huge connectors…

Konstantin Kim
1 year ago

Where is link to “wheel-powered robot” ?

Guy fauquembergue
Guy fauquembergue
1 year ago

I am trying to use the wukong RP2040 with a Pico W and a circuitpython web server but it seems weird to setup the webserver with circuitpython there is examples in microptyhon. Nothing in circuit python. I would appreciate to find an example on how to drive motors with micropython. Best regards.

Guy Fauquembergue
1 year ago

Hi I have downloaded the latest circuitpython uf2 8.xx and cannot make a web server to drive the wukong product ipaddress and wifi modules are missing in the core modules.
Could you help thanks in advance

Boardcon Rockchip and Allwinner SoM and SBC products