电子发烧友App

硬声App

创作
电子发烧友网>电子资料下载>单片机>树莓派 ADC模块 ADS1115 16位 模数转换器(python3)

树莓派 ADC模块 ADS1115 16位 模数转换器(python3)

2021-11-30 | pdf | 未知 | 次下载 | 免费

资料介绍

ADC数模转换

接线


VDD - 5V
GND - GND
SCL - SCL
SDA - SDA
ADDR - GND
A0 - MQ 传感器的 A0

当ADDR引脚连接到GND时,地址为:0x48(0100, 1000B)
当ADDR引脚连接到VDD时,地址为:0x49(0100, 1001B)
当ADDR引脚连接到SDA时,地址为:0x4A(0100, 1010B)
当ADDR引脚连接到SCL时,地址为:0x4B(0100, 1011B)

设置树莓(开启I2C)


模块检查(接通电源后)

sudo apt-get install i2c-tools
sudo i2cdetect -y 1

安装依赖

pip3 install -i https://pypi.mirrors.ustc.edu.cn/simple/ Adafruit_ADS1x15

代码

import Adafruit_ADS1x15
/**
增益
2/3 = +/-6.144V
1 = +/-4.096V
2 = +/-2.048V
4 = +/-1.024V
8 = +/-0.512V
16 = +/-0.256V
*/
GAIN = 1
adc1 = Adafruit_ADS1x15.ADS1115(address=0x48)
while True:
	/**
		A0 = Channel 0 minus channel 1
    	A1 = Channel 0 minus channel 3
    	A2 = Channel 1 minus channel 3
    	A3 = Channel 2 minus channel 3
    	data_rate=128 为每秒返回样本数 最高为860
	*/
	print(adc1.read_adc(0, gain=GAIN, data_rate=128))
# Simple demo of reading each analog input from the ADS1x15 and prinTIng it to
# the screen.
# Author: Tony DiCola
# License: Public Domain
import TIme

# Import the ADS1x15 module.
import Adafruit_ADS1x15


# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these opTIonal parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)
# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
        # Note you can also pass in an opTIonal data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
下载该资料的人也在下载 下载该资料的人还在阅读
更多 >

评论

查看更多

下载排行

本周

  1. 1MICROCHIP 509单片机资料.pdf
  2. 1.29 MB  |  15次下载  |  免费
  3. 2stm32单片机-学习笔记(1)
  4.   |  10次下载  |  免费
  5. 3ESP8266学习笔记01
  6.   |  5次下载  |  免费
  7. 4IO口软件模拟串口
  8.   |  4次下载  |  免费
  9. 5micropython四位数码管程序代码(YX55759-+4位数码管模块)
  10.   |  3次下载  |  免费
  11. 6电子入门的基础性学习资料
  12. 0.48 MB  |  3次下载  |  1 积分
  13. 7STM32上电复位电路参数选择
  14.   |  3次下载  |  免费
  15. 8STM32f103ZET6最小系统板原理图下载
  16. 1.53 MB  |  3次下载  |  免费

本月

  1. 150个典型应用电路设计思路和方法实例
  2. 5.69 MB  |  121次下载  |  免费
  3. 2《通信高频开关电源》第2版pdf
  4. 15.84 MB  |  46次下载  |  2 积分
  5. 3信号完整性与电源完整性分析第三版
  6. 122.68 MB  |  41次下载  |  免费
  7. 42008年精选100例电路设计思路和常见设计方法
  8. 0.25 MB  |  33次下载  |  免费
  9. 5开关电源学习路径
  10.   |  29次下载  |  免费
  11. 6四层PCB核心板制作8——内电层电源平面分割
  12.   |  23次下载  |  免费
  13. 7《模拟技术应用技巧101例》pdf
  14. 14.99 MB  |  23次下载  |  1 积分
  15. 8TC275 例程
  16.   |  22次下载  |  免费

总榜

  1. 1matlab软件下载入口
  2. 未知  |  934883次下载  |  免费
  3. 2protel99se软件下载(可英文版转中文版)
  4. 78.1 MB  |  537325次下载  |  免费
  5. 3MATLAB 7.1 下载 (含软件介绍)
  6. 1331200  |  419857次下载  |  免费
  7. 4OrCAD10.5下载,OrCAD10.5中文版软件
  8. 817182  |  233722次下载  |  免费
  9. 5Altium DXP2002下载入口
  10. 未知  |  232883次下载  |  免费
  11. 6电路仿真软件multisim 10.0免费下载
  12. 340992  |  190886次下载  |  免费
  13. 7十天学会AVR单片机与C语言视频教程 下载
  14. 158M  |  183079次下载  |  免费
  15. 8proe5.0野火版下载(中文版免费下载)
  16. 818176  |  137890次下载  |  免费
版权所有 © 深圳华秋电子有限公司 电子发烧友电路图粤公网安备 44030402000349号 电信与信息服务业务经营许可证:粤B2-20160233 工商网监认证工商网监 粤ICP备14022951号