Pimoroni Servo 2040 Hardware¶
The Pimoroni Servo 2040 is a CircuitPython microcontroller board supporting 18 hobby servo outputs. Following are some preliminary notes on the device.
Reference Links¶
Technical Details¶
Powered by RP2040 (Dual Arm Cortex M0+ running at up to 133Mhz with 264kB of SRAM)
2MB of QSPI flash supporting XiP
18 sets of header pins for connecting 3 pin hobby servos
Supports higher voltage servos (up to 11V) *
6 addressable RGB LEDs/Neopixels
6 sets of header pins for connecting analog sensors
Onboard voltage and current sensing
Reset and BOOT button (the BOOT button can also be used as a user button)
USB-C connector for programming and power (3A max)
Screw terminals for supplying external power (with reverse polarity protection) (10A max continuous current)
QT (STEMMA QT/Qwiic) connector for breakouts
Measurements: 62mm x 42mm x 12mm (L x W x H, including connectors). The mounting holes are M2.5 and 2.7mm in from each edge.
Pin Configurations¶
Partial list from the schematic:
GPIO0 to GPIO17: servo outputs SERVO1 through SERVO18
GPIO18: six onboard NeoPixels
GPIO20: I2C_SDA for the Stemma connector
GPIO21: I2C_SCL for the Stemma connector
GPIO23: user switch input (also the BOOT switch)
GPIO22, GPIO24, GPIO25: ADC multiplexer channel
These pins are defined in the board module:
board.LED_DATA
board.SERVO_1 through board.SERVO_18
etc.
Sample Code¶
Direct downloads:
1# pim_servo_2040_demo.py
2
3# Demo for the Pimoroni Servo 2040 board.
4
5# import firmware modules
6import time
7import board
8import digitalio
9import neopixel_write
10
11# import the locally defined servo module
12import servo
13
14#================================================================
15print("Creating hardware interfaces.")
16
17# create hardware interfaces
18
19# NeoPixel array
20pixels = digitalio.DigitalInOut(board.LED_DATA)
21pixels.direction = digitalio.Direction.OUTPUT
22frame_buffer = bytearray(3*board.NUM_LEDS)
23
24# specify which servo pins to use
25pins = [board.SERVO_1, board.SERVO_2, board.SERVO_3, board.SERVO_4]
26
27# create a servo object for each pin
28servos = [servo.Servo(pin) for pin in pins]
29
30#================================================================
31def set_led(i, color):
32 if i < board.NUM_LEDS:
33 frame_buffer[i*3] = color[1] # green
34 frame_buffer[i*3+1] = color[0] # red
35 frame_buffer[i*3+2] = color[2] # blue
36 neopixel_write.neopixel_write(pixels, frame_buffer)
37
38#================================================================
39
40while True:
41 print("Starting main loop.")
42
43 # flash the sequence quickly
44 for i in range(board.NUM_LEDS):
45 print("Flashing LED", i)
46 set_led(i, (0, 0, 255)) # blue
47 time.sleep(0.1)
48 set_led(i, (0, 0, 0))
49
50 # move each servo in sequence
51 for i, s in enumerate(servos):
52 print("Moving servo", i)
53 s.write(90)
54 set_led(i, (0, 255, 0)) # green
55 time.sleep(0.5)
56 s.write(0)
57 set_led(i, (0, 0, 0))