vision/README.md

81 lines
2.2 KiB
Markdown
Raw Normal View History

2026-07-20 02:15:37 +00:00
# linefollower_eye
2026-07-20 02:15:37 +00:00
ESP32-S3 camera board that finds a coloured blob and reports its position over I2C. Meant to sit on a robot as the “eye”, with something like a Pico as the master.
2026-07-20 02:15:37 +00:00
## What it does
2026-07-20 02:15:37 +00:00
The ESP runs HSV blob detection on the camera. A MicroPython master can turn the camera on, set colour, and poll for a target. Optionally it can join WiFi so you can open a browser page to tune the colour live.
2026-07-20 02:15:37 +00:00
Target position from `read_target()` is relative to the image centre (320x240). Positive x is right, positive y is up. No target returns `None`.
2026-07-20 02:15:37 +00:00
## Hardware
2026-07-20 02:15:37 +00:00
ESP pins for the I2C slave:
2026-07-20 02:15:37 +00:00
- SDA: GPIO19
- SCL: GPIO20
- Address: 0x42
2026-07-20 02:15:37 +00:00
Example Pico wiring:
2026-07-20 02:15:37 +00:00
- GP0 (SDA) -> ESP GPIO19
- GP1 (SCL) -> ESP GPIO20
- GND shared
- Use external pull-ups on SDA/SCL (about 2k24k7 to 3V3)
2026-07-20 02:15:37 +00:00
Camera and WiFi stay off until the master enables them.
2026-07-20 02:15:37 +00:00
## Firmware
2026-07-20 02:15:37 +00:00
ESP-IDF project for ESP32-S3. Build and flash as usual:
```
2026-07-20 02:15:37 +00:00
idf.py build
idf.py -p PORT flash monitor
```
2026-07-20 02:15:37 +00:00
## MicroPython master
2026-07-20 02:15:37 +00:00
Files live in `mp_i2c_master/`. Copy `vision.py` (and `main.py` if you want the demo) onto the board.
2026-07-20 02:15:37 +00:00
```python
from vision import Vision
import time
2026-07-20 02:15:37 +00:00
eye = Vision(sda=0, scl=1)
2026-07-20 03:05:24 +00:00
eye.start() # start the camera and blob algorithm
2026-07-20 02:51:40 +00:00
2026-07-20 03:05:24 +00:00
eye.set_hsv(4, 128, 116) # Set target colour (HSV)
2026-07-20 02:51:40 +00:00
eye.set_rgb(255, 255, 255) # Set RGB LED to max white
2026-07-20 03:05:24 +00:00
# Optional: browser UI for tuning colour
#eye.set_wifi("rr workshop", "ourpassword")
#print(eye.wifi_ip())
2026-07-20 02:15:37 +00:00
while True:
2026-07-20 03:05:24 +00:00
target = eye.read_target()
if target is None:
2026-07-20 02:15:37 +00:00
print("no target")
else:
2026-07-20 03:05:24 +00:00
x, y = target
print("target at ({}, {})".format(x, y))
time.sleep(0.07)
2026-07-20 02:15:37 +00:00
```
Useful calls:
- `eye.start()` — camera on and local detection
- `eye.set_hsv(h, s, v)` / `eye.set_tolerance(...)` — colour (or tune in the browser)
- `eye.set_wifi(ssid, password)` / `eye.wifi_off()` / `eye.wifi_ip()`
- `eye.read_target()``(x, y)` or `None`
2026-07-20 03:05:24 +00:00
- `eye.set_rgb(r, g, b)`
2026-07-20 02:15:37 +00:00
## Web UI
After WiFi is up, open the ESPs IP in a browser. You get the live image, colour picker / eyedropper, mask options, and timing. Colour changes there are what the I2C master reads next.
2026-07-20 02:15:37 +00:00
## Other folders
2026-07-20 02:15:37 +00:00
- `pc_vision/` — older desktop viewer; the on-device web UI replaces it for tuning
- `main/` — ESP firmware