前提・実現したいこと
raspberry piでADS1015(A-Dコンバータ)を使用しようとしています。
最終的にraspberry piで距離センサを使用したいです。
Adafruitのサイトを参考に、サンプルプログラム(Adafruitのもの)を
実行しましたがエラーが起き、解決方法が判らず
教えていただけないでしょうか。
発生している問題・エラーメッセージ
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.5/dist-packages/Adafruit_ADS1x15-1.0.2-py3.5.egg/Adafruit_ADS1x15/ADS1x15.py", line 192, in read_adc File "/usr/local/lib/python3.5/dist-packages/Adafruit_ADS1x15-1.0.2-py3.5.egg/Adafruit_ADS1x15/ADS1x15.py", line 128, in _read File "/usr/local/lib/python3.5/dist-packages/Adafruit_GPIO-1.0.4-py3.5.egg/Adafruit_GPIO/I2C.py", line 129, in writeList File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO-1.1.5-py3.5.egg/Adafruit_PureIO/smbus.py", line 363, in write_i2c_block_data File "/usr/local/lib/python3.5/dist-packages/Adafruit_PureIO-1.1.5-py3.5.egg/Adafruit_PureIO/smbus.py", line 163, in _select_device OSError: [Errno 16] Device or resource busy
該当のソースコード
以下、実行したプログラムです。
python
1# Simple demo of reading each analog input from the ADS1x15 and printing it to 2# the screen. 3# Author: Tony DiCola 4# License: Public Domain 5import time 6 7# Import the ADS1x15 module. 8import Adafruit_ADS1x15 9 10 11# Create an ADS1115 ADC (16-bit) instance. 12adc = Adafruit_ADS1x15.ADS1115() 13 14# Or create an ADS1015 ADC (12-bit) instance. 15#adc = Adafruit_ADS1x15.ADS1015() 16 17# Note you can change the I2C address from its default (0x48), and/or the I2C 18# bus by passing in these optional parameters: 19#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1) 20 21# Choose a gain of 1 for reading voltages from 0 to 4.09V. 22# Or pick a different gain to change the range of voltages that are read: 23# - 2/3 = +/-6.144V 24# - 1 = +/-4.096V 25# - 2 = +/-2.048V 26# - 4 = +/-1.024V 27# - 8 = +/-0.512V 28# - 16 = +/-0.256V 29# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain. 30GAIN = 1 31 32print('Reading ADS1x15 values, press Ctrl-C to quit...') 33# Print nice channel column headers. 34print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4))) 35print('-' * 37) 36# Main loop. 37while True: 38 # Read all the ADC channel values in a list. 39 values = [0]*4 40 for i in range(4): 41 # Read the specified ADC channel using the previously set gain value. 42 values[i] = adc.read_adc(i, gain=GAIN) 43 # Note you can also pass in an optional data_rate parameter that controls 44 # the ADC conversion time (in samples/second). Each chip has a different 45 # set of allowed data rate values, see datasheet Table 9 config register 46 # DR bit values. 47 #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128) 48 # Each value will be a 12 or 16 bit signed integer value depending on the 49 # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit). 50 # Print the ADC values. 51 print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values)) 52 # Pause for half a second. 53 time.sleep(0.5)ソースコード
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/22 12:17