-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suppoort multiple boards at once, via serial number of the chip
- Loading branch information
tomaz.strus
committed
Nov 19, 2024
1 parent
b91d3fc
commit 8c10d94
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |