ADS1256

Python auf Einplatinencomputer wie Raspberry Pi, Banana Pi / Python für Micro-Controller
Antworten
MatLan
User
Beiträge: 9
Registriert: Freitag 14. Oktober 2022, 09:14

Hallo,

Ich habe ein kleines Problem mit meinem High Precision AD/DA Board auf dem RasPi 3B
Ich habe zum größten Teil den Beispiel Code von Github übernommen:

logging.getLogger("asyncio").setLevel(logging.WARNING)

screen = TextScreen()


logging.basicConfig(level=logging.DEBUG)

print("\x1B[2J\x1B[H") # Clear screen
print(__doc__)
print("\nPress CTRL-C to exit.\n")

# For in-place text-mode output
screen = TextScreen()

def text_format_8_ch(digits, volts):
digits_str = ", ".join([f"{i: 8d}" for i in digits])
volts_str = ", ".join([f"{i: 8.3f}" for i in volts])
text = (" AIN0, AIN1, AIN2, AIN3, "
" AIN4, AIN5, AIN6, AIN7\n"
f"{digits_str}\n\n"
"Values converted to volts:\n"
f"{volts_str}\n"
)
return text


### START EXAMPLE ###########################################################
#
###### STEP 0: Configure channels
# For channel code values (bitmask) definitions, see ADS1256_definitions.py.
# The values representing the negative and positive input pins connected to
# the ADS1256 hardware multiplexer must be bitwise OR-ed to form eight-bit
# values, which will later be sent to the ADS1256 MUX register. The register
# can be explicitly read and set via ADS1256.mux property, but here we define
# a list of differential channels to be input to the ADS1256.read_sequence()
# method which reads all of them one after another.
#
# ==> Each channel in this context represents a differential pair of physical
# input pins of the ADS1256 input multiplexer.
#
# ==> For single-ended measurements, select AINCOM as the negative input.
#
# AINCOM does not have to be connected to AGND (0V), but it is if the jumper
# on the Waveshare board is set.
POTI = POS_AIN0 | NEG_AINCOM
LDR = POS_AIN1 | NEG_AINCOM
CH2 = POS_AIN2 | NEG_AINCOM
CH3 = POS_AIN3 | NEG_AINCOM
CH4 = POS_AIN4 | NEG_AINCOM
CH5 = POS_AIN5 | NEG_AINCOM
CH6 = POS_AIN6 | NEG_AINCOM
CH7 = POS_AIN7 | NEG_AINCOM

# Arbitrary length tuple of input channel pair values to scan sequentially
CH_SEQUENCE = POTI, LDR, CH2, CH3, CH4, CH5, CH6, CH7

def loop_forever_measurements(ads):
while True:
# Returns list of integers, one result for each configured channel
raw_channels = ads.read_sequence(CH_SEQUENCE)
# Text-mode output
voltages = [i * ads.v_per_digit for i in raw_channels]
screen.put(text_format_8_ch(raw_channels, voltages))
screen.refresh()
time.sleep(0.5)

try:
###### STEP 1: ADS1256 now supports the context-manager API. [*]
# Use this to have ADS1256 automatically close the SPI device and
# pigpio resources at exit:
with ADS1256() as ads:
###### STEP 2: Configuration and control by setting ADS1256 properties:
ads.drate = DRATE_100
# Gain and offset self-calibration can be triggered at any time
ads.cal_self()
###### STEP 3: Get and process data
loop_forever_measurements(ads)

except KeyboardInterrupt:
print("\nUser Exit.\n")

Jetzt funktioniert es ab und zu aber vermehrt kommen die Fehlermeldungen :

DEBUG: PiPyADC: Setting as input: 22 (chip select)
DEBUG: PiPyADC: Setting as input: 23 (chip select)
DEBUG: PiPyADC: Setting as output: 18 (reset pin)
DEBUG: PiPyADC: Setting as output: 27 (pdwn pin)
DEBUG: PiPyADC: Activating SPI, SW chip select on GPIO: 22
DEBUG:PiPyADC:Obtained SPI device handle: 1
DEBUG:PiPyADC:Closing SPI handle: 1
DEBUG:PiPyADC:Closing PIGPIO instance

Das Board habe ich bereits mit dem gleichen getauscht und trotzdem der gleiche Fehler. Das Board funktioniert. Auch SPI ist auf dem RasPi 3 aktiviert.


Kann mir jemand helfen ? :)

Vielen Dank im Voraus
Sirius3
User
Beiträge: 17710
Registriert: Sonntag 21. Oktober 2012, 17:20

Was heißt "Es funktioniert ab und zu"? Was passiert, wenn es nicht funktioniert?
Das sind keine Fehlermeldungen, sondern Debugmeldungen. Wenn Du die nicht haben willst, schalte sie nicht ein.
MatLan
User
Beiträge: 9
Registriert: Freitag 14. Oktober 2022, 09:14

Oh Sorry die Fehlermeldung ist etwas untergegangen^^

lib/python3.9/site-packages/pipyadc/pipyadc.py", line 171, in check_chip_id
raise RuntimeError("Received wrong chip ID value for ADS1256. "
RuntimeError: Received wrong chip ID value for ADS1256. Hardware connected?

Diese Fehlermeldung kommt dann nach den Debugmeldungen

Der Ausschnitt aus der Bibliothek:

def check_chip_id(self):
# This invokes a getter function..
chip_ID = self.chipt_ID
logger.debug(f"Chip ID: {chip_ID}")
if chip_ID != 3:
self.stop_close_all()
raise RuntimeError( " Received wrong chip ID value for ADS1256. Hardware connected?")


jetzt fehlt mir an Verständnis, wie ich die Chip_ID ändern kann oder wo diese vergeben wird. Wie gesagt der Fehler taucht erst seit letztens auf und ich kann mir nicht helfen woher ^^
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Wenn du die Hardware nicht geaendert hast, dann hast du ein Hardware-Problem. Die Chip-ID ist fest vergeben in dem ADS1256, und wenn sich das ohne weiteres zutun geaendert hat, deutet das auf ein groesseres Problem hin - irgendwie kommt die richtige ID nicht mehr zurueck via SPI. Was dafuer spricht, dass wahlweise der Chip selbst, oder die SPI-Verbindung, oder der Pi ein Problem haben.
MatLan
User
Beiträge: 9
Registriert: Freitag 14. Oktober 2022, 09:14

Nach langer Suche bin ich endlich fündig geworden :). Die Hardware lief soweit fehlerfrei. Der einzige Fehler war der pigpiod Daemon, der sofort nach dem Start des RasPi's angesprochen wurde und Signale geschickt hatte ^^ Durch Neustarten des Daemons funktioniert der Code wieder fehlerfrei. Vielen Dank nochmal allen :)
Antworten