树莓派安装运行ADS1015库(python)

https://github.com/pimoroni/ads1015-python

安装Installing

 

Stable library from PyPi:使用此命令直接安装后只有python可以执行,python3无法执行,因为只在python2.x中安装了,跳过了python3.x,建议使用git安装方法。

sudo pip install ads1015

Latest/development library from GitHub:

git clone https://github.com/pimoroni/ads1015-python
cd ads1015-python
sudo ./install.sh

 示例程序在examples>read-all.py中

#!/usr/bin/env python
import time
from ads1015 import ADS1015

CHANNELS = ['in0/ref', 'in1/ref', 'in2/ref']

print("""read-all.py - read all three inputs of the ADC
Press Ctrl+C to exit!
""")

ads1015 = ADS1015()
ads1015.set_mode('single')
ads1015.set_programmable_gain(2.048)
ads1015.set_sample_rate(1600)

reference = ads1015.get_reference_voltage()

print("Reference voltage: {:6.3f}v \n".format(reference))

try:
    while True:
        for channel in CHANNELS:
            value = ads1015.get_compensated_voltage(channel=channel, reference_voltage=reference)
            print("{}: {:6.3f}v".format(channel, value))

        print("")
        time.sleep(0.5)

except KeyboardInterrupt:
    pass

 


版权声明:本文为u010906644原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。