Hallo zusammen,
ich kann leider meinen NTC Temperatursensor welches an einem I2C (PCF8591) hängt nicht auslesen.
Infos zu meinem Setup:
cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Mein Code:
import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)
#check your PCF8591 address by type in 'sudo i2cdetect -y -1' in terminal.
def setup(Addr):
global address
address = Addr
def read(chn): #channel
try:
if chn == 0:
bus.write_byte(address,0x40)
if chn == 1:
bus.write_byte(address,0x41)
if chn == 2:
bus.write_byte(address,0x42)
if chn == 3:
bus.write_byte(address,0x43)
bus.read_byte(address) # dummy read to start conversion
except Exception as e:
print ("Address: %s" % address)
print (e)
return bus.read_byte(address)
if __name__ == "__main__":
setup(0x48)
while True:
print ('AIN0 = ', read(0))
print ('AIN1 = ', read(1))
print ('AIN2 = ', read(2))
print ('AIN3 = ', read(3))
# time.sleep(0.3)
Alles anzeigen
Mein Output:
AIN0 = 255
AIN1 = 255
AIN2 = 255
AIN3 = 255
Meine Erwartung wäre, dass bei einen der Pins (da wo der NTC angeschlossen ist) eine andere Zahl als 255 stehen würde.
Ich bin nach diesem Tutorial gegangen: http://www.netzmafia.de/skripten/hardw…/RasPi_I2C.html
Ich bin noch relativ neu im Thema Raspberry Pi und Python
Was mach ich falsch oder wo kann der Fehler liegen.
Danke schonmal im Vorraus!
Viele Grüße
Alex