![](/img/trans.png)
[英]Converting issue when read NTC temperature sensor with PCF8591 AD/DA with Raspberry PI
[英]Not able to read valid voltage input in raspberry pi with PCF8591
我嘗試使用I2C通訊通過Raspberry-pi中的PCF8591讀取來自機器的電壓輸入,但打印一些其他值。
還可以請我建議一下,因為如果我想獲得機器輸入電壓,如果電壓下降,它應該中斷功能,我應該使用哪種方法?
PCF8591-> Raspberry Pi之間的連接
將機器連接到PCF8591
PCF8591上的5v-> AIN1
GND-> GND Rpi
import smbus import time address = 0x48 A0 = 0x40 A1 = 0x41 A2 = 0x42 A3 = 0x43 bus = smbus.SMBus(1) while True: bus.read_byte_data(address,A1) value = bus.read_byte_data(address, A1) print("AOUT: %1.03f" %(value*3.3/255)) time.sleep(0.2)
顯示像這樣的輸出AOUT:2.756
要獲得正確的值,您必須讀取該值兩次。 第一次讀取告訴芯片進行新的測量並同時返回寄存器中的當前值(這不是正確的值)。 在第二次讀取時,您將獲得正確的值:
import smbus
import time
address = 0x48
A0 = 0x40
A1 = 0x41
A2 = 0x42
A3 = 0x43
bus = smbus.SMBus(1)
while True:
bus.read_byte_data(address, A1) # do the measurement but ignore the value
value = bus.read_byte_data(address, A1) # get the correct value
#print(value)
print("AOUT: %1.03f" %(value*3.3/255))
time.sleep(0.2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.