๐งช 1-Sensor Direct Bring-Up Hookup (Single Sensor Only)
The simplest way to start: connect 1 optical mouse sensor directly to your Pico 2WH using 6 Female-to-Female Dupont wires.
๐ 1-Sensor Exact Pinout Table (Desk Orientation Point of Truth)
| Sensor Physical Pin # | Sensor Silkscreen | Pico Header Location | Pico Physical Pin # | Wire Color | Function & Notes |
|---|---|---|---|---|---|
| Pin 1 (Top) | VCC | LEFT Row (3V3_OUT) | Pin 36 | ๐ด Red | 3.3V Power from Pico (Do NOT connect to Pin 37) |
| Pin 2 | MIS | RIGHT Row (GP4 RX) | Pin 6 | ๐ต Blue | Master In Slave Out (Data from Sensor) |
| Pin 3 | MOS | RIGHT Row (GP3 TX) | Pin 5 | ๐ข Green | Master Out Slave In (Data to Sensor) |
| Pin 4 | SCL | RIGHT Row (GP2 SCK) | Pin 4 | ๐ก Yellow | SPI Serial Clock (2 MHz) |
| Pin 5 | SS | RIGHT Row (GP5 CSn) | Pin 7 | ๐ฃ Purple | Slave Select / Chip Select #1 (Active LOW) |
| Pin 6 | MOT | Not Connected | — | — | Motion Interrupt Flag (Optional, polling used) |
| Pin 7 | GND | LEFT Row (GND) | Pin 38 | ๐ Orange | Common Ground Reference |
| Pin 8 (Bottom) | RS | Not Connected | — | — | Hardware Reset (Internal pull-up, leave open) |
โ Tested & Validated Hardware Script (sensor_test.py)
Matches the exact desk pinout above (Left Row 3V3/GND, Right Row GP2-GP5 SPI). Paste into Thonny and click Run.
import time
from machine import Pin, SPI
# Exact pins matching the 1:1 desk wiring layout:
PIN_SCK = 2 # GP2 (Pin 4) -> Yellow wire (Sensor Pin 4 SCL)
PIN_MOSI = 3 # GP3 (Pin 5) -> Green wire (Sensor Pin 3 MOS)
PIN_MISO = 4 # GP4 (Pin 6) -> Blue wire (Sensor Pin 2 MIS)
PIN_CS = 5 # GP5 (Pin 7) -> Purple wire (Sensor Pin 5 SS)
# Power: Red wire (Sensor Pin 1 VCC) -> Left Row Pin 36 (3V3_OUT)
# Ground: Orange wire (Sensor Pin 7 GND) -> Left Row Pin 38 (GND)
cs = Pin(PIN_CS, Pin.OUT, value=1)
spi = SPI(0, baudrate=2_000_000, polarity=1, phase=1,
sck=Pin(PIN_SCK), mosi=Pin(PIN_MOSI), miso=Pin(PIN_MISO))
def write_reg(reg, val):
cs.value(0)
time.sleep_us(10)
spi.write(bytes([reg | 0x80, val]))
time.sleep_us(30)
cs.value(1)
time.sleep_us(35)
def read_reg(reg):
cs.value(0)
time.sleep_us(10)
spi.write(bytes([reg & 0x7F]))
time.sleep_us(160) # t_SRAD turnaround delay
val = spi.read(1)[0]
time.sleep_us(5)
cs.value(1)
time.sleep_us(20)
return val
# 1. Reset SPI port
cs.value(1); time.sleep_ms(10)
cs.value(0); time.sleep_ms(2); cs.value(1); time.sleep_ms(10)
# 2. Power-up Reset command (0x5A to register 0x3A)
write_reg(0x3A, 0x5A)
time.sleep_ms(60)
# 3. Flush motion registers pipeline
for r in [0x02, 0x03, 0x04, 0x05, 0x06]:
read_reg(r)
time.sleep_ms(10)
# 4. Check IDs
prod_id = read_reg(0x00)
rev_id = read_reg(0x01)
print(f"๐ฆ Product ID: 0x{prod_id:02X} | Revision ID: 0x{rev_id:02X}")
print("๐ฎ Live Tracking Active - Swipe surface over sensor:")
while True:
motion = read_reg(0x02)
squal = read_reg(0x07) # Surface quality (0-255)
if motion & 0x80:
dx_l = read_reg(0x03)
dx_h = read_reg(0x04)
dy_l = read_reg(0x05)
dy_h = read_reg(0x06)
dx = (dx_h << 8) | dx_l
if dx >= 32768: dx -= 65536
dy = (dy_h << 8) | dy_l
if dy >= 32768: dy -= 65536
print(f"๐ dX: {dx:+6d} | dY: {dy:+6d} | SQUAL: {squal:3d}")
time.sleep_ms(20)
๐ Step-by-Step 5-Minute Hookup Sequence
VCC into Row 5.Plug a Black jumper from Pico Pin 38 (GND) into Breadboard Row 10. Plug both sensors'
GND into Row 10.โ ๏ธ Danger: Never connect to 5V (VBUS / VSYS).
SCK & Sensor 2 SCK.MOSI (Blue): Pico Pin 25 (GP19) โ Row 20 โ Sensor 1
MO & Sensor 2 MO.MISO (Green): Pico Pin 21 (GP16) โ Row 25 โ Sensor 1
MI & Sensor 2 MI.
SS / CS directly into Pico Pin 22 (GP17).Sensor 2 CS (Purple): Plug Sensor 2
SS / CS directly into Pico Pin 26 (GP20).
โ Must be SILENT (high resistance). If you hear a continuous beep ($0\,\Omega$), you have a short circuitโdo NOT plug in USB!
python software/globe_doctor.pyIt will query SPI register
0x00 (Product ID), verify 0x42, and test the lens optical focus!