Raspberry i2c: [Errno 16] Device or resource busy

di il
1 risposte

Raspberry i2c: [Errno 16] Device or resource busy

Ciao a tutti,
Sto usando un Raspberry 3 Model A+ e vorrei utilizzare un sensore analogico, motivo per cui ho provato a configurare un ADS1115. Utilizzando Python e la libreria di Adafruit, il codice di esempio per verificarne il comportamento mi restituisce questo errore:
pi@raspberrypi:~/Adafruit_Python_ADS1x15/examples $ python3 simpletest.py 
Reading ADS1x15 values, press Ctrl-C to quit...
|      0 |      1 |      2 |      3 |
-------------------------------------
Traceback (most recent call last):
  File "simpletest.py", line 42, in <module>
    values[i] = adc.read_adc(i, gain=GAIN)
  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 363, in write_i2c_block_data    
    self._select_device(addr)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/smbus.py", line 163, in _select_device
    ioctl(self._device.fileno(), I2C_SLAVE, addr & 0x7F)
OSError: [Errno 16] Device or resource busy
Questo il codice del programma in python
pi@raspberrypi:~/Adafruit_Python_ADS1x15/examples $ cat simpletest.py
# Simple demo of reading each analog input from the ADS1x15 and printing it to
# the screen.
# Author: Tony DiCola
# License: Public Domain
import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15


# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
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)
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
Non so davvero cosa fare per risolvere.

1 Risposte

Devi accedere o registrarti per scrivere nel forum
1 risposte