Skip to content

Commit 99f312d

Browse files
committed
Set PIO base pin based on board name
1 parent d333824 commit 99f312d

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

red_vision_examples/ex08_high_fps_camera.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
# Import NumPy.
2929
from ulab import numpy as np
3030

31-
# Import machine and rp2 for I2C and PIO.
32-
import machine
33-
from machine import Pin
34-
import rp2
35-
i2c = machine.I2C()
36-
rp2.PIO(1).gpio_base(16)
31+
# Import the Pin class for the board's default pins, as well as SPI and I2C.
32+
from machine import Pin, SPI, I2C
33+
34+
# When the Red Vision Kit for RedBoard is used with the IoT RedBoard RP2350,
35+
# both the display and camera use GPIO 16-47 instead of GPIO 0-31, so we need to
36+
# adjust the base GPIO for PIO drivers.
37+
import sys
38+
if "IoT RedBoard RP2350" in sys.implementation._machine:
39+
import rp2
40+
rp2.PIO(1).gpio_base(16)
3741

3842
# Image size and bytes per pixel (depends on color mode). This example defaults
3943
# to 320x240 with BGR565.
@@ -59,7 +63,7 @@
5963
# color format. SPI is used here for compatibility with most platforms, but
6064
# other interfaces can be faster.
6165
interface_display = rv.displays.SPI_Generic(
62-
spi = machine.SPI(
66+
spi = SPI(
6367
baudrate = 24_000_000,
6468
),
6569
pin_dc = Pin.board.DISPLAY_DC,
@@ -87,7 +91,7 @@
8791
)
8892
driver_camera = rv.cameras.OV5640(
8993
interface = interface_camera,
90-
i2c = i2c,
94+
i2c = I2C(),
9195
continuous = True, # Continuous capture mode for fastest frame rate.
9296
height = height,
9397
width = width,

red_vision_examples/rv_init/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
# When the Red Vision Kit for RedBoard is used with the IoT RedBoard RP2350,
1515
# both the display and camera use GPIO 16-47 instead of GPIO 0-31, so we need to
1616
# adjust the base GPIO for PIO drivers
17-
import rp2
18-
rp2.PIO(1).gpio_base(16)
17+
import sys
18+
if "IoT RedBoard RP2350" in sys.implementation._machine:
19+
import rp2
20+
rp2.PIO(1).gpio_base(16)
1921

2022
# Import the camera driver
2123
try:

0 commit comments

Comments
 (0)