Skip to content

Instantly share code, notes, and snippets.

@flavio-fernandes
Created November 14, 2021 13:05
Show Gist options
  • Save flavio-fernandes/0931d1faf8d648a866197ab996092d02 to your computer and use it in GitHub Desktop.
Save flavio-fernandes/0931d1faf8d648a866197ab996092d02 to your computer and use it in GitHub Desktop.
hacking Circuit Python with Bruno
import busio
import board
import time
import adafruit_aw9523
i2c = busio.I2C(board.SCL, board.SDA)
aw = adafruit_aw9523.AW9523(i2c)
print("Found AW9523")
ON = False
OFF = not ON
leds = []
led_gpios = [1,2,3,4,5,6]
for led_gpio in led_gpios:
leds.append( aw.get_pin(led_gpio) )
for i in range(len(led_gpios)):
leds[i].switch_to_output(value=OFF)
green_button = aw.get_pin(0)
red_button = aw.get_pin(11)
for button in [green_button, red_button]:
button.switch_to_input()
incr = 1
curr_led = 0
prev_red_button_value = red_button.value
prev_green_button_value = green_button.value
next_refresh = time.monotonic() + 0.5
while True:
now = time.monotonic()
if prev_red_button_value != red_button.value:
if not red_button.value:
incr = {0: 1, 1: 0, -1: 0}.get(incr, 0)
prev_red_button_value = red_button.value
#print(f"Red {red_button.value} {incr} {curr_led}")
if prev_green_button_value != green_button.value:
if not green_button.value:
incr *= -1
prev_green_button_value = green_button.value
#print(f"Green {green_button.value} {incr} {curr_led}")
if now >= next_refresh:
for i in range(len(leds)):
is_on = curr_led != i
leds[i].value = is_on
curr_led = (curr_led + incr) % len(leds)
next_refresh = time.monotonic() + 0.3
time.sleep(0.02)
evernote uuid: 2021-Nov-13-Sat@12:04:44
https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases
https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221/mac-osx
```
cd ~/Desktop/bruno
python3 -m venv venv && source ./venv/bin/activate && pip install -U pip setuptools wheels &> /dev/null
pip --version
pip install --upgrade pip
pip3 install hidapi
pip3 install adafruit-blinka
# need to set this every time
export BLINKA_MCP2221="1" ; echo $BLINKA_MCP2221
python
import board
dir(board)
import hid
hid.enumerate()
import hid
device = hid.device()
device.open(0x04D8, 0x00DD)
```
```
import time
import board
import digitalio
led = digitalio.DigitalInOut(board.G0)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
```
=-==-
STEMMA / STEMMA QT (JST SH) / Devices and Sensors / Adafruit VCNL4040 Proximity and Lux Sensor - STEMMA QT / Qwiic
https://www.adafruit.com/product/4161
https://learn.adafruit.com/adafruit-vcnl4040-proximity-sensor
```
pip3 install adafruit-circuitpython-vcnl4040
```
address=0x60
https://github.com/adafruit/Adafruit_CircuitPython_VCNL4040/blob/c7ed9221f06004cb085044f7f7ccc54059a9891e/adafruit_vcnl4040.py#L282
```
import time
import board
import adafruit_vcnl4040
i2c = board.I2C()
sensor = adafruit_vcnl4040.VCNL4040(i2c)
while True:
print("Proximity:", sensor.proximity)
print("Light: %d lux" % sensor.lux)
time.sleep(1.0)
```
=-=-=-=-=-=-
Sensors / Temperature / I2C / SPI Digital / Adafruit PCT2075 Temperature Sensor - STEMMA QT / Qwiic
https://www.adafruit.com/product/4369
https://learn.adafruit.com/adafruit-pct2075-temperature-sensor
```
This means that the default address for the breakout is 0x37.
```
```
pip3 install adafruit-circuitpython-pct2075
```
```
import time
import board
import adafruit_pct2075
import adafruit_vcnl4040
i2c = board.I2C()
pct = adafruit_pct2075.PCT2075(i2c)
sensor = adafruit_vcnl4040.VCNL4040(i2c)
while True:
print("Temperature: %.2f C" % pct.temperature)
print("Proximity:", sensor.proximity)
print("Light: %d lux" % sensor.lux)
time.sleep(1.0)
```
=-=-=-=-=-=-
Breakout Boards / Level Shifters & Expanders / Adafruit AW9523 GPIO Expander and LED Driver Breakout
https://www.adafruit.com/product/4886
https://learn.adafruit.com/adafruit-aw9523-gpio-expander-and-led-driver
```
pip3 install adafruit-circuitpython-aw9523
```
https://github.com/adafruit/Adafruit_CircuitPython_AW9523
https://github.com/adafruit/Adafruit_CircuitPython_AW9523/blob/32f525af792063c19cc73674dbfe13bfbb9159e8/adafruit_aw9523.py#L37
```
_AW9523_DEFAULT_ADDR = const(0x58)
```
```
```
=-=-=-=
devices:
STEMMA / STEMMA QT (JST SH) / Controllers / Adafruit MCP2221A Breakout - General Purpose USB to GPIO ADC I2C
https://www.adafruit.com/product/4471
https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-mcp2221
STEMMA / STEMMA QT (JST SH) / Devices and Sensors / Adafruit VCNL4040 Proximity and Lux Sensor - STEMMA QT / Qwiic
https://www.adafruit.com/product/4161
Sensors / Temperature / I2C / SPI Digital / Adafruit PCT2075 Temperature Sensor - STEMMA QT / Qwiic
https://www.adafruit.com/product/4369
https://learn.adafruit.com/adafruit-pct2075-temperature-sensor
Breakout Boards / Level Shifters & Expanders / Adafruit AW9523 GPIO Expander and LED Driver Breakout
https://www.adafruit.com/product/4886
STEMMA / STEMMA QT (JST SH) / Controllers / Adafruit QT Py - SAMD21 Dev Board with STEMMA QT
https://www.adafruit.com/product/4600
https://learn.adafruit.com/adafruit-qt-py/circuitpython
Sensors / Light / Color / Photo / Adafruit BH1750 Light Sensor - STEMMA QT / Qwiic
https://www.adafruit.com/product/4681
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment