ich habe auf de i2c Bus einen Multiplexer und an Kanal 5 einen ADS1115 4-Kanal Analogeingang angeschlossen.
Am Eingang 1 des Analog Eingangs habe ich einen Fotowiderstand zum Helligkeitsmessen.
Angeschlossen über einen 10KOhm Widerstand wie hier beschrieben:
https://tutorials-raspberrypi.de/raspbe ... iderstand/
der code:
Code: Alles auswählen
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=5)
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)
#values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
# Print the ADC values.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
# Pause for half a second.
time.sleep(0.5)
Starte ich das Programm, erhalte ich den Fehler:
Code: Alles auswählen
Reading ADS1x15 values, press Ctrl-C to quit...
| 0 | 1 | 2 | 3 |
-------------------------------------
Traceback (most recent call last):
File "simpletest.py", line 20, in <module>
values[i] = adc.read_adc(i, gain=GAIN, data_rate=860)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_ADS1x15/ADS1x15.py", line 192, in read_adc
return self._read(channel + 0x04, gain, data_rate, ADS1x15_CONFIG_MODE_SINGLE)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_ADS1x15/ADS1x15.py", line 128, in _read
self._device.writeList(ADS1x15_POINTER_CONFIG, [(config >> 8) & 0xFF, config & 0xFF])
File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO/I2C.py", line 127, in writeList
self._bus.write_i2c_block_data(self._address, register, data)
File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 364, in write_i2c_block_data
self._device.write(data)
OSError: [Errno 121] Remote I/O error
Schaut so aus, als müsste der Sensor im negativen Bereich sein?
Ausgabe(zuerst war er abgedeckt, dann offen im Raum):
Code: Alles auswählen
Reading ADS1x15 values, press Ctrl-C to quit...
| 0 | 1 | 2 | 3 |
-------------------------------------
| -2336 | -1952 | -1968 | -1952 |
| -2304 | -1952 | -1968 | -1952 |
| -2320 | -1952 | -1936 | -1936 |
| -2336 | -1952 | -1936 | -1952 |
| -2320 | -1920 | -1952 | -1952 |
| 6992 | 4128 | 4656 | 6784 |
| 7008 | 6752 | 5920 | 3696 |
| 6752 | 5456 | 7520 | 8544 |
| 7056 | 4208 | 4000 | 5792 |
| 7264 | 7056 | 6800 | 4944 |
| 7024 | 4592 | 5872 | 9088 |
| 6832 | 5552 | 3936 | 4192 |