Skip to content

Example from README fails to run #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gordykeene opened this issue Nov 28, 2024 · 0 comments · Fixed by #3
Closed

Example from README fails to run #2

gordykeene opened this issue Nov 28, 2024 · 0 comments · Fixed by #3
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@gordykeene
Copy link

The example usage found in README.rst#usage-example fails to run with the following error:

code.py output:
Traceback (most recent call last):
  File "code.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'Adafruit_ADS7830'

After some research and experimentation, I arrived at this resolution:

import time
import board
import adafruit_ads7830.ads7830
from adafruit_ads7830.analog_in import AnalogIn

i2c = board.I2C()

# Initialize ADS7830
adc = adafruit_ads7830.ads7830.ADS7830(i2c)
analog_inputs = []
for i in range(8):
    c = AnalogIn(adc, i)
    analog_inputs.append(c)

while True:
    for i in range(8):    
        print(f"ADC input {i} = {analog_inputs[i].value}")
    time.sleep(0.1)

As a diff, if it helps:

@@ -1,17 +1,18 @@
 import time
 import board
-import adafruit_ads7830
+import adafruit_ads7830.ads7830
+from adafruit_ads7830.analog_in import AnalogIn

 i2c = board.I2C()

 # Initialize ADS7830
-adc = adafruit_ads7830.Adafruit_ADS7830(i2c)
+adc = adafruit_ads7830.ads7830.ADS7830(i2c)
 analog_inputs = []
 for i in range(8):
-    c = adc.inputs[i]
+    c = AnalogIn(adc, i)
     analog_inputs.append(c)

 while True:
-    for i in enumerate(analog_inputs):
+    for i in range(8):
         print(f"ADC input {i} = {analog_inputs[i].value}")
     time.sleep(0.1)
@caternuson caternuson added documentation Improvements or additions to documentation good first issue Good for newcomers labels Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants