|
1 | 1 | # Analog to digital converter example. |
2 | 2 | # Will loop forever printing ADC channel 1 raw and mV values every second. |
3 | | -# Open the serial port after running to see the output printed. |
4 | | -# NOTE the ADC can only read voltages in the range of ~900mV to 1200mV! |
5 | | -# Author: Tony DiCola |
| 3 | +# NOTE the ADC can only read voltages in the range of ~900mV to 1800mV! |
| 4 | + |
6 | 5 | import time |
7 | 6 | import board |
8 | 7 | import busio |
9 | 8 | import adafruit_lis3dh |
| 9 | +# Uncomment if using SPI |
| 10 | +#import digitalio |
10 | 11 |
|
11 | 12 |
|
12 | | -# Uncomment _one_ of the hardware setups below depending on your wiring: |
13 | | - |
14 | | -# Hardware I2C setup: |
15 | | -i2c = busio.I2C(board.SCL, board.SDA) |
16 | | -lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) |
17 | | - |
18 | | -# Software I2C setup: |
19 | | -#import bitbangio |
20 | | -#i2c = bitbangio.I2C(board.SCL, board.SDA) |
21 | | -#lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) |
| 13 | +# Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available; |
| 14 | +# otherwise check I2C pins. |
| 15 | +if hasattr(board, 'ACCELEROMETER_SCL'): |
| 16 | + i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) |
| 17 | + lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19) |
| 18 | +else: |
| 19 | + i2c = busio.I2C(board.SCL, board.SDA) |
| 20 | + lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) |
22 | 21 |
|
23 | 22 | # Hardware SPI setup: |
24 | | -#import busio |
25 | | -#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) |
26 | | -#cs = busio.DigitalInOut(board.D6) # Set to appropriate CS pin! |
27 | | -#lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs) |
| 23 | +# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) |
| 24 | +# cs = digitalio.DigitalInOut(board.D5) # Set to correct CS pin! |
| 25 | +# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs) |
| 26 | + |
| 27 | +#PyGamer I2C Setup: |
| 28 | +#i2c = busio.I2C(board.SCL, board.SDA) |
| 29 | +#lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19) |
28 | 30 |
|
29 | 31 |
|
30 | 32 | # Loop forever printing ADC readings. |
|
0 commit comments