在这里,我正在使用Raspberry Pi 3从“ sharp gp2y1014au0f” DustSensor中读取数据。由于传感器数据为模拟量,因此我将ads1115用作模拟数字转换器。但是问题是,必须在关闭后的0.32毫秒内读取灰尘传感器的数据。 ads1115的最高速度仅为0.86毫秒。如何使用树莓派3从Sharp Gp2y1014au0f读取数据?
我已经更改了ads1115库中读取的数据,但仅获得0.82毫秒。所以仍然没有得到数据
import RPi.GPIO as GPIO
import time
from AdsValue import getData #this ads1115 program i made
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
def getDustData():
Vo = 0
VT = 0
K = 0.5
data = 0
for i in range(30):
begin = time.perf_counter_ns()
#print ("LED off")
GPIO.output(18,GPIO.LOW)
#time.sleep(280/1000000) #sleep 0.28 millisecond or 280 microsecond
data = getData(0) #call get data to get data from ads1115
#print ("LED on")
GPIO.output(18,GPIO.HIGH)
time.sleep(9620/1000000) #slepp 9.62 millissecond or 9620 microsecond
end = time.perf_counter_ns()
#print(data)
VT += data
waktu = (end-begin)/1000000 #time in nano so it in milli second
V = VT/30
dev = V-Vo
return dev/K*100, waktu
while True:
Debu = getDustData()
print("Data :",Debu)
此AdsValue.py程序
import time
from Libs.ads1115 import ADS1115
adc = ADS1115()
GAIN = 1
def getData(Pin):
values = adc.read_adc(Pin, gain=GAIN)
value = values*(4.09/32767)
return value