diff --git a/luxonis_example/multipleBoards.py b/luxonis_example/multipleBoards.py new file mode 100644 index 00000000..afccc4a7 --- /dev/null +++ b/luxonis_example/multipleBoards.py @@ -0,0 +1,50 @@ +import os +from adafruit_blinka.microcontroller.rp2040_u2if.pin import Pin +from adafruit_blinka.microcontroller.rp2040_u2if.rp2040_u2if import RP2040_u2if +from specific_board import init_specific_board, display_connected_rp2040, RP2040_u2if_init + +os.environ["BLINKA_U2IF"]="1" + + +display_connected_rp2040() + + +import time +import adafruit_apds9960.apds9960 +# Initialize I2C using u2if's I2C interface +#board2=init_specific_board(0xE6636825930C7C23) + +#This class is more low level, used mostly for GPIO manipulation. +rp = RP2040_u2if_init("0xE6636825930C7C23") + + +# This is high level adafruit class used for I2C. +# Do not import the board class if you are using multiple rp2040 without this method as you cant control the serial of the board +board1, busio1=init_specific_board("0xE462B0659F1B2036") +i2c = busio1.I2C(board1.GP5, board1.GP4) # SCL, SDA for default I2C1 +sensor = adafruit_apds9960.apds9960.APDS9960(i2c) + + +# Enable color sensing +sensor.enable_color = True + +print("INIT GPIO") +rp.gpio_init_pin(0, Pin.OUT,Pin.PULL_NONE) +rp.gpio_init_pin(1, Pin.IN,Pin.PULL_NONE) +# Main loop to read RGB data +print("Inside main loop") +r, g, b, c = 1,1,1,1 +while True: + r, g, b, c = sensor.color_data # Red, Green, Blue, and Clear channel data + print(f"Red: {r}, Green: {g}, Blue: {b}, Clear: {c}") + if r > g and r > b: + print("RED") + if g > r and g > b: + print("GREEN") + if b > g and b > r: + print("BLUE") + print(rp.gpio_get_pin(1)) + (rp.gpio_set_pin(0, 0)) + time.sleep(2) + (rp.gpio_set_pin(0, 1)) + time.sleep(1) diff --git a/luxonis_example/muxerExample.py b/luxonis_example/muxerExample.py new file mode 100644 index 00000000..633c2f30 --- /dev/null +++ b/luxonis_example/muxerExample.py @@ -0,0 +1,47 @@ +import os +os.environ["BLINKA_U2IF"]="1" +from time import sleep +from specific_board import init_specific_board, display_connected_rp2040, RP2040_u2if_init +import digitalio +display_connected_rp2040() + + + +# led 0 means the USB is on the LED soldiered side + +# Set up a GPIO pin as an output +board, busio = init_specific_board("0xE6636825930C7C23") + +button = digitalio.DigitalInOut(board.GP0) +button.direction = digitalio.Direction.OUTPUT +button.value=True + +usbLed = digitalio.DigitalInOut(board.GP1) +usbLed.direction = digitalio.Direction.INPUT + +def press_button(button): + print("Pressing button") + button.value = False + # If delay is too small button will not siwtch. With delay of 3 seconds, this worked pretty much 100% od the time + sleep(3) + button.value = True + #If you retry multiple times, you need this delay. + sleep(2) + + +def toogle_to_correct(led, button, wanted_state): + for i in range(5): + if bool(int(wanted_state)) == led.value: + return True + else: + press_button(button) + + raise Exception("Toogle unsuccessful, didnt change states") + + +while True: + toogle_to_correct(usbLed, button, True) + print(usbLed.value) + sleep(1) + toogle_to_correct(usbLed, button, False) + print(usbLed.value) diff --git a/src/adafruit_blinka/microcontroller/rp2040_u2if/pin.py b/src/adafruit_blinka/microcontroller/rp2040_u2if/pin.py index c42f6238..5187cdc4 100644 --- a/src/adafruit_blinka/microcontroller/rp2040_u2if/pin.py +++ b/src/adafruit_blinka/microcontroller/rp2040_u2if/pin.py @@ -23,6 +23,7 @@ def __init__(self, pin_id=None): self.id = pin_id self._mode = None self._pull = None + self.rp2040_u2if=rp2040_u2if # pylint:disable = no-self-use def _u2if_open_hid(self, vid, pid): diff --git a/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py b/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py index e5198a10..eec08494 100644 --- a/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py +++ b/src/adafruit_blinka/microcontroller/rp2040_u2if/rp2040_u2if.py @@ -109,7 +109,7 @@ def _reset(self): # ---------------------------------------------------------------- # MISC # ---------------------------------------------------------------- - def open(self, vid, pid): + def open(self, vid, pid, serial=None): """Open HID interface for given USB VID and PID.""" if self._opened: @@ -117,7 +117,10 @@ def open(self, vid, pid): self._vid = vid self._pid = pid self._hid = hid.device() - self._hid.open(self._vid, self._pid) + if not serial: + serial =os.environ["CURRENT_BOARD_SERIAL"] + self._serial =serial + self._hid.open(self._vid, self._pid, self._serial) if RP2040_U2IF_RESET_DELAY >= 0: self._reset() self._opened = True diff --git a/src/specific_board.py b/src/specific_board.py new file mode 100644 index 00000000..d969b838 --- /dev/null +++ b/src/specific_board.py @@ -0,0 +1,22 @@ +import os +from adafruit_blinka.microcontroller.rp2040_u2if.rp2040_u2if import RP2040_u2if + +def init_specific_board(serial): + os.environ["CURRENT_BOARD_SERIAL"] = serial + import board + import busio + return board, busio + +def RP2040_u2if_init(serial): + os.environ["CURRENT_BOARD_SERIAL"] = serial + rp= RP2040_u2if() + rp.open(51966, 16389, serial=serial) + return rp + +def display_connected_rp2040(): + import hid + for dev in hid.enumerate(): + vendor = dev["vendor_id"] + product = dev["product_id"] + if vendor == 0xCAFE and product == 0x4005: + print(dev) \ No newline at end of file