Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/sample_code/ADS1115_ACD_to_I2C.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (17 sloc)
745 Bytes
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
#!/usr/bin/env python3 | |
# This script reads an analog voltage on channel 0 on an ADS1115 and outputs | |
# an integer value that corresponds to this voltage. | |
# https://cdn-shop.adafruit.com/datasheets/ads1115.pdf | |
# $ sudo apt-get install python3 python3-pip python-dev python-smbus | |
# $ sudo pip3 install smbus Adafruit-Blinka adafruit-circuitpython-ads1x15 | |
import time | |
import board | |
import busio | |
import adafruit_ads1x15.ads1115 as ADS | |
from adafruit_ads1x15.analog_in import AnalogIn | |
i2c = busio.I2C(board.SCL, board.SDA) # Create the I2C bus | |
ads = ADS.ADS1115(i2c) # Create the ADC object using the I2C bus | |
chan = AnalogIn(ads, ADS.P0) # Create single-ended input on channel 0 | |
while True: | |
print("{:>5.3f}".format(chan.voltage)) | |
time.sleep(0.1) |