Skip to content

I2C pin conflicts #35

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
jerryneedell opened this issue Feb 24, 2019 · 10 comments
Closed

I2C pin conflicts #35

jerryneedell opened this issue Feb 24, 2019 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@jerryneedell
Copy link
Contributor

This is just FYI regardsing some experimentation I have been doing

I was trying to use the an alphanumeric display vi the featherwing library along with some other I2C sesnors. I wanted to get the sensor data and display it on the alphanumeric featherwing. A common use case, I think.

When I tried to create the sensor objects, i got errors indicating that the I2C pins were "in use".

I experimented a bit using the board.I2C() function instead of the busio.I2C() with the sensors and got it working, but then found that if I make the following change, I think shared.py becomes unnecessary.

uit_featherwing$ git diff
diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py
index 06b0409..cf445a6 100755
--- a/adafruit_featherwing/alphanum_featherwing.py
+++ b/adafruit_featherwing/alphanum_featherwing.py
@@ -31,8 +31,8 @@ Helper for using the `14-Segment AlphaNumeric FeatherWing <https://www.adafruit.
 __version__ = "0.0.0-auto.0"
 __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
 
+import board
 import adafruit_ht16k33.segments as segments
-from adafruit_featherwing import shared
 from adafruit_featherwing.led_segments import Segments
 
 class AlphaNumFeatherWing(Segments):
@@ -42,5 +42,5 @@ class AlphaNumFeatherWing(Segments):
        Automatically uses the feather's I2C bus."""
     def __init__(self, address=0x70):
         super().__init__()
-        self._segments = segments.Seg14x4(shared.I2C_BUS, address)
+        self._segments = segments.Seg14x4(board.I2C(), address)
         self._segments.auto_write = False

here is the test code I am running

import time
import board
import busio
import adafruit_sht31d
import adafruit_veml6070

from adafruit_featherwing import alphanum_featherwing

display = alphanum_featherwing.AlphaNumFeatherWing()
sensor = adafruit_sht31d.SHT31D(board.I2C())
uv = adafruit_veml6070.VEML6070(board.I2C())



loopcount = 0
while True:
    uv_raw = uv.read
    risk_level = uv.get_index(uv_raw)
    print('Reading: {0} | Risk Level: {1}'.format(uv_raw, risk_level))
    display.print(uv_raw)
    time.sleep(2)
    temperature = sensor.temperature
    print("\nTemperature: %0.1f C" % temperature)
    display.print(temperature)
    print("Humidity: %0.1f %%" % sensor.relative_humidity)
    loopcount += 1
    time.sleep(2)
    # every 10 passes turn on the heater for 1 second
    if loopcount == 10:
        loopcount = 0
        sensor.heater = True
        print("Sensor Heater status =", sensor.heater)
        time.sleep(1)
        sensor.heater = False
        print("Sensor Heater status =", sensor.heater)


One issue I an into was that in the current master, board.I2C() is not implemented for the particle boards and I was testing on a particle_argon. I implmented it in a local build and it now is working. It was already implemented in the feather_nrf52840.

@makermelissa
Copy link
Collaborator

The shared library was in place from @tannewt and @kattni's previous work. The library isn't very big and iI don't know if it's set up this way for more for backwards compatibility or convenience. Maybe they can chime in on this one.

@jerryneedell
Copy link
Contributor Author

There may well be better ways to do this -- I just wanted to capture the issue.

@jerryneedell
Copy link
Contributor Author

Why don't we just pass the I2C device into the alphanum_featherwing (and others) library like we do for the sensor libraries or have a n optional argument for it - if it is omitted or None then the lib can create it.

@makermelissa
Copy link
Collaborator

I'd like to keep it simple to initialize, however giving the user the option to pass it in but initializing inside the class like it does now if it's not passed in may be a good compromise.

@jerryneedell
Copy link
Contributor Author

I think that is better than the user having to import shared.py from adafruit_featherwing and use shared.I2C_BUS. That works, but seems awfully kludgey to me

@makermelissa
Copy link
Collaborator

makermelissa commented Feb 28, 2019

As Kattni said, it was intended to reduce duplicate code, but if it is broken we can change it.

@jerryneedell
Copy link
Contributor Author

NP -- your call -- as long there is a documented way to use multiple sensors with the wings, I'll be happy.

@makermelissa
Copy link
Collaborator

Yeah, I was eventually planning on adding some more examples that used multiple wings, so I may attempt that sooner than I originally planned.

@tannewt
Copy link
Member

tannewt commented Mar 8, 2019

I think the shared bit was added before board.I2C(). I'd suggest using board.I2C() from now on and replacing the shared stuff. By using board.I2C() it's easier to use for external stuff.

@makermelissa
Copy link
Collaborator

Fixed by #36.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants