Skip to content

Updates examples #34

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
jposada202020 opened this issue May 25, 2021 · 13 comments · Fixed by #35
Closed

Updates examples #34

jposada202020 opened this issue May 25, 2021 · 13 comments · Fixed by #35
Assignees
Labels
enhancement New feature or request

Comments

@jposada202020
Copy link
Contributor

New example is desired to show the user how to add two or more sensors

@jposada202020 jposada202020 added the enhancement New feature or request label May 25, 2021
@jposada202020 jposada202020 self-assigned this May 25, 2021
@caternuson
Copy link
Contributor

These are sensors that use BusDevice?

@jposada202020
Copy link
Contributor Author

Yes indeed.

@caternuson
Copy link
Contributor

The current simpletest example shows this for two TSL2591s.

@jposada202020
Copy link
Contributor Author

Thanks closing this then 👍🏼

@caternuson
Copy link
Contributor

We could still update the example offerings though. Maybe something like this?

  • rename current tca9548a_simpletest.py to multi_sensor.py and that become the example for that
  • add a new tca9548a_simpletest.py which could be an i2c scan sweep example
  • any other use cases that are confusing and an example would help clarify?

@jposada202020
Copy link
Contributor Author

Oh yes I love the idea, will work on that :)

@caternuson caternuson reopened this May 26, 2021
@caternuson caternuson changed the title Add advanced example Updates examples May 26, 2021
@caternuson
Copy link
Contributor

OK, reopened and renamed. I think there was a good scan example in that other issue thread?

@jposada202020
Copy link
Contributor Author

yes there is, I did example for the fakerequests, i was thinking something similar
https://github.com/adafruit/Adafruit_CircuitPython_FakeRequests/blob/main/examples/fakerequests_advancedtest.py
what do you think?

@caternuson
Copy link
Contributor

Even simpler, something like:

import board
import adafruit_tca9548a

tca = adafruit_tca9548a.TCA9548A(board.I2C())

for channel in range(8): 
    if tca[channel].try_lock():
        print('Channel {}:'.format(channel), end='')
        tca[channel].scan()
        tca[channel].unlock()

Weird - I thought I had dumped something like that over in that PR #32 thread, but not seeing it now. Oh well. Easy enough to rewrite. Output would look something like:

Channel 0:[112]
Channel 1:[38, 56, 112]
Channel 2:[112]
Channel 3:[112]
Channel 4:[112]
Channel 5:[94, 112, 119]
Channel 6:[112]
Channel 7:[112]

Could maybe make it a little fancier and do a list comp on the return to filter out the TCA's address.

@jposada202020
Copy link
Contributor Author

Will do

@jerryneedell
Copy link

jerryneedell commented May 27, 2021

Can you please output the addresses in Hex?

@jposada202020
Copy link
Contributor Author

yes:) we like hex in the I2C world :)

@caternuson
Copy link
Contributor

import board
import adafruit_tca9548a

i2c = board.I2C()

tca = adafruit_tca9548a.TCA9548A(i2c)

for channel in range(8): 
    if tca[channel].try_lock():
        print('Channel {}:'.format(channel), end='')
        addresses = tca[channel].scan()
        print([hex(address) for address in addresses if address != 0x70]) 
        tca[channel].unlock()
Channel 0:[]
Channel 1:['0x26', '0x38']
Channel 2:[]
Channel 3:[]
Channel 4:[]
Channel 5:['0x5e', '0x77']
Channel 6:[]
Channel 7:[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants