PyRasp

Robotics modules and the Pico IO shield

The pilot hardware is a Raspberry Pi Pico on a Keyestudio KS3017 Pico IO shield. The shield does not change the Pico's pins: it brings them to labelled G / V / S headers so a module can be plugged in without a breadboard.

In the simulator the Pico is shown mounted on the shield, with eight G/V/S module headers around it. Wire a module's S to the header's signal pin, its V to a 3.3 V or 5 V header pin, and its G to a ground header. Those header nets are the same nets as the Pico GP pads, so Pin(13) sees a module on S1 exactly as it would on the real shield.

HeaderSignalHeaderSignal
S1GP13S5GP20
S2GP16S6GP21
S3GP12S7GP26
S4GP18S8GP27

The 3.3 V headers are V33_1–V33_4; the 5 V headers are V5_1–V5_4. G1–G8 are ground. Choose the V header that matches the module, and set the physical shield's selector to match.

Power and the voltage selector

The KS3017 has a 3.3 V / 5 V selector for the module rail.

  • 3.3 V modules — line sensor, obstacle sensor, PIR, DHT11, OLED, potentiometer, button: use 3V3. Their signal outputs are safe for a Pico GPIO.
  • 5 V modules — servos, the HC-SR04, NeoPixel strips: use 5 V from VBUS. Their signal still has to be safe for the Pico:
    • HC-SR04 ECHO is 5 V. Divide it with 1 kΩ + 2 kΩ before the GPIO, or use a 3.3 V-safe module.
    • A 5 V servo's signal input usually accepts 3.3 V, but power the servo from 5 V, never from 3V3.
  • Common ground is not optional. Every module's G and the Pico's GND must meet, even when the module has its own supply.

Check the selector before plugging anything in. A 3.3 V module fed 5 V, or a 5 V signal into a GPIO, can damage the part or the Pico. The simulator warns and then damages the pin in the same way.

The module set

ModuleSignal behaviourPico connectionFirst problem
LED modulelit when SIG is highSIG → GP13, G → GNDFirst blink
Traffic lightred/yellow/green, shared groundthree GPIOsTraffic light
Button moduleOUT high while pressed (pull-down fitted)OUT → GP12, V → 3V3Button mirror
Active buzzerbeeps while poweredGP13 (piezo) or through a transistor (magnetic)Buzzer button
Potentiometer0–3.3 V on the wiperW → GP26Pot → LED brightness
LDR modulevoltage falls in lightAO → GP26Night light
Servo0.5–2.5 ms pulse → angleSIG → GPIO, V → 5 VServo sweep
HC-SR04ECHO pulse width is distanceTRIG S5, ECHO S6 (divide)Print the distance
Line sensorOUT high over a dark lineS2, V33, G1Line sensor → LED
Obstacle sensorOUT high when something is closeS2, V33, G2Obstacle stop
PIROUT high on motionS2, V5, G1PIR alarm
Joysticktwo pots + buttontwo ADC pins + GPIOJoystick → two servos
6812 RGB stickone data line, GRB bytesS4, V5, G1Colour the stick
DHT11temperature and humidityGP15, V33, G2Temperature and humidity
OLEDSSD1306 over I²CSDA GP4, SCL GP5Write on the OLED

The line and obstacle sensors are comparator modules: the IR emitter and receiver produce an analogue reflection, and the trimmer sets the trip point. The Pico sees only a clean digital HIGH or LOW, which is why Pin(16, Pin.IN) is enough.

The twelve-problem robot unit

Work through these in order. All twelve are in the catalogue; the joystick problem uses two potentiometers, which is what is inside the module.

  1. Blink the on-board LED — Pin('LED'), no wiring.
  2. Traffic light — three outputs and a timed sequence.
  3. Button mirror — one input, one output.
  4. Pot → LED brightness — ADC and PWM.
  5. Pot → servo angle — map a voltage to a pulse width.
  6. Print the ultrasonic distance — time_pulse_us.
  7. Distance alarm — closer means faster beeping.
  8. Line sensor → LED — read a comparator output.
  9. Obstacle stop — stop a motor when the path is blocked.
  10. PIR alarm — motion turns on a warning.
  11. Joystick → two servos — two ADCs, two PWM outputs.
  12. Parking sensor — ultrasonic + buzzer + warning LED.

A line follower's first test

from machine import Pin
import utime

sensor = Pin(16, Pin.IN)
while True:
    print("line" if sensor.value() else "floor")
    utime.sleep_ms(50)

Move the module across black tape. If it never changes, check the 3V3 supply, the G/V/S order, and the trimmer. The simulator's line feed is the trimmer's decision; on real hardware, adjust the trimmer until the module's indicator LED changes at the line edge.

An obstacle stop

from machine import Pin
import utime

sensor = Pin(16, Pin.IN)
in1, in2, ena = Pin(20, Pin.OUT), Pin(21, Pin.OUT), Pin(22, Pin.OUT)
in2.off()
while True:
    if sensor.value():       # something is close
        in1.off()
        ena.off()
    else:
        in1.on()
        ena.on()
    utime.sleep_ms(20)

The obstacle module's OUT is already 3.3 V, so no divider is needed. The L298N's motor supply is a separate 5 V feed; the Pico only drives the logic inputs and ENA.

A parking sensor

The HC-SR04 needs a 10 µs trigger pulse and returns a pulse whose width is twice the travel time. Sound travels about 58 µs per centimetre at room temperature, so:

distance_cm = time_pulse_us(echo, 1, 30000) / 58

The reference program in the catalogue beeps and lights a red LED below 20 cm. With a real HC-SR04, divide ECHO down to 3.3 V before the Pico. With the 3.3 V-safe module, connect it directly.

Troubleshooting the shield

What you seeLikely causeFix
Module has no powerV/G swapped, or the rail selector is offCheck G/V/S order; measure V against G
Sensor always reads 1Input floating, or pull-up left onUse Pin.IN with a real driven signal; don't add a pull unless the module needs one
Servo jitters or browns outServo powered from 3V3Move V to 5 V (VBUS); share ground only
Pico resets when the motor startsMotor current sharing the Pico supplySeparate motor supply; common ground
HC-SR04 gives 0 or a timeoutECHO not divided, or TRIG pulse too short1 kΩ + 2 kΩ divider; 10 µs trigger
OLED stays blackSDA/SCL swapped or address wrongSDA GP4, SCL GP5, address 0x3C

Problems: Line sensor → LED · Obstacle stop · PIR alarm · Parking sensor