Skip to content

Support boards that don't have a fixed I2C bus. #59

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

Merged
merged 3 commits into from
Jan 29, 2021

Conversation

rsbohn
Copy link
Contributor

@rsbohn rsbohn commented Jan 29, 2021

Fixes #57 -- allows loading tftshield18 on the Raspberry Pi Pico.

Preserves the existing behavior on devices with board.I2C.
The Pico doesn't have a pre-defined I2C, you have to set it up with busio before you can instantiate the TFTShield18 object.

import board
import busio
from adafruit_seesaw.tftshield18 import TFTShield18
i2c_bus = busio.I2C(board.GP3, board.GP2)
shield = TFTShield18(i2c_bus)

Copy link
Contributor

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I believe this is a good change. In Python, the default value of a function argument is evaluated when the function's definition is encountered, so it should be something that can always succeed and has no "side effects"; even on boards that have board.I2C(), simply calling board.I2C() can have a side effect: it reserves those pins and does not let them be used for other purposes.

A minor change, though: It is better in Python to say if i2c_bus is None, according to the Style Guide for Python Code

Making this change should resolve the problems detected by the automatic checks.

Based on guidance from jepler.
Suggested by pylint. TFTShield won't work without an i2c_bus, so fail with an informative message.
Copy link
Contributor

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good now! No testing performed.

@jepler jepler merged commit 781c8e7 into adafruit:master Jan 29, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 3, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_SCD30 to 2.0.1 from 2.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_SCD30#7 from rpavlik/pressure-type

Updating https://github.com/adafruit/Adafruit_CircuitPython_Seesaw to 1.7.0 from 1.6.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#58 from adafruit/dherrada-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_seesaw#59 from rsbohn/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.12.1 from 2.11.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#112 from jposada202020/updating-docs
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#110 from FoamyGuy/bitmap_label_ascent_descent

Updating https://github.com/adafruit/Adafruit_CircuitPython_Slideshow to 1.5.5 from 1.5.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_Slideshow#35 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_SimpleMath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't import adafruit_seesaw.tftshield18 on RP2040 Raspberry Pi Pico
2 participants