-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
49 lines (40 loc) · 1.01 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from busio import I2C
import board
import digitalio
from time import sleep
# Turns on the LED to make sure the pico is alive
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
led.value = True
# Rapid blinking: Not all devices connected
def notAllDevicesConnected():
print("ERROR: Not all devives are connected! Check and try again!")
while(True):
led.value = not led.value
sleep(0.1)
# Fast blinking: I2C not working
def i2cNotWorking():
while(True):
led.value = not led.value
sleep(0.25)
# Mediumish blinking: Pull up resistor
def i2cNoPullUp():
print("ERROR: No pull up resistor found")
while(True):
led.value = not led.value
sleep(0.5)
try:
i2c = I2C(board.GP15, board.GP14) # First SCL, then SDA
except RuntimeError:
i2cNoPullUp()
except Exception as e:
print(f"Something bad happened: {e}")
i2cNotWorking()
if(not i2c.try_lock()):
i2cNotWorking()
while(True):
print(i2c.scan())
test = bytearray(256)
i2c.readfrom_into(0x32, test)
print(list(test))
sleep(1)