资讯详情

树莓派 4B 使用拓展板的四声音传感器AO模块连接

RaspberryPi-Sensor-Board使用文档

RaspberryPi-Sensor-Board - emakefun文档中心 (test-doc-zh-cn.readthedocs.io)

特点

  • 支持8路ADC检测
  • 内置MCU
  • 支持树莓派 2B/3B/3B /4/zero
  • 5.5x2.1DC头与接线端子供电
  • 外部传感器电压3V3与5V自由切换
  • 板载DC-DC降压芯片 宽电压输入:6~36V 电压输出:5V 最大电流输出: 3A

MCU规格

  • 工作电压:3.3V
  • MCU :STM32/STC8G
  • IO: 8路ADC检测
  • 与树莓派通信: I2C
  • I2C地址: 0x04

硬件概述

寄存器

???扩展板MCU I2C地址为0x04,寄存地址说明如下:

  • 0x10 ~ 0x17: 读取ADC原始数据

  • 0x20 ~ 0x27: 读取输入电压

  • 0x30 ~ 0x37: 读取输入电压与输出电压之比 输入电压/输出电压

读取ADC模拟值

???众所周知,Raspberry Pi中没有ADC,因此,传感器的模拟值不能直接读取。内置在扩展板上MCU 在帮助下,你可以读10位ADC这意味着模拟传感器可以用于树莓派,共有8个可用接口。

???模拟传感器将模拟电压输入10位模数转换器。模数转换器将模拟数据转换为数字数据I2C在树莓派中输入数字数据。

在终端输入sudo i2cdetect -y 命令可以扫描连接I2C总线上的一切I2C打印设备并打印设备I2C总线地址(这里使用)PCF8591)

import time import RPi.GPIO as GPIO import smbus  GPIO.setmode(GPIO.BCM)  address=0x48  delta=20  time_list=[0,0,0,0] threshold=[0,0,0,0] basic_value_1=[] basic_value_2=[] basic_value_3=[] basic_value_4=[]  bus=smbus.SMBus(1) def loop_print():     flag1=0     flag2=0     flag3=0     flag4=0     while True:                  bus.write_byte(address,0x40)         bus.write_byte(address,0x41)         bus.write_byte(address,0x42)         bus.write_byte(address,0x43)                  sound1=bus.read_byte_data(address,0x40)         sound2=bus.read_byte_data(address,0x41)         sound3=bus.read_byte_data(address,0x42)         sound4=bus.read_byte_data(address,0x43)                  if sound1:             print("the NO.1 power of the sound is %lf"%sound1)                          if len(basic_value_1)<=10:                 basic_value_1.append(sound1)                 if len(basic_value_1)==10:                     value=0                     for i in range(10):                         value =basic_value_1[i]                     threshold[0]=(value/10) delta                                  if 0 not in threshold:                 if sound1>threshold[0] and flag1==0:                     time_list[0]=time.time_ns()/10**9                     flag1=1                                  time.sleep(0.0)                      if sound2:             print("the NO.2 power of the sound is %lf"%sound2)                          if len(basic_value_2)<=10:                 basic_value_2.append(sound2)                 if len(basic_value_2)==10:                     value=0                     for i in range(10):                         value =basic_value_2[i]                     threshold[1]=(value/10) delta                                  if 0 not in threshold:                 if sound2>threshold[1] and flag2==0:                     time_list[1]=time.time_ns()/10**9                     flag2=1                                  time.sleep(0.0)                  if sound3:             print("the NO.3 power of the sound is %lf"%sound3)                          if len(basic_value_3)<=10:                 basic_value_3.append(sound3)                 if len(basic_value_3)==10:                     value=0                     for i in range(10):                         value =basic_value_3[i]                     threshold[2]=(value/10) delta                                  if 0 not in threshold:                 if sound3>threshold[2] and flag3==0:                     time_list[2]=time.time_ns()/10**9                     flag3=1                                  time.sleep(0.0)                      if sound4:             print("the NO.4 power of the sound is %lf"%sound4)                          if len(basic_value_4)<=10:                 basic_value_4.append(sound4)                 if len(basic_value_4)==10:                     value=0                     for i in range(10):                         value =basic_value_4[i]                     threshold[3]=(value/10) delta                                  if 0 not in threshold:                 if sound4>threshold[3] and flag4==0:                     time_list[3]=time.time_ns()/10**9                     flag4=1                                  time.sleep(0.0)                  if (0 not in time_list) and (0 not in threshold):             print(threshold)             print(time_list)             break  loop_print()

标签: 48v电流传感器传感器zh30104

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台