Skip to content

Don't invert the polarity of the GPIO pins by default #21

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 4 commits into from
Feb 12, 2020

Conversation

foozmeat
Copy link
Contributor

@foozmeat foozmeat commented Feb 9, 2020

This PR changes the init behavior of the MCP23008 so only the IODIR register is set for input and leaves the other registers alone. By writing \xFF to the second, IPOL, register it was inverting the polarity of the GPIO ports.

@ladyada
Copy link
Member

ladyada commented Feb 11, 2020

i think biggest risk is whether this messes with
https://www.adafruit.com/product/1115
@caternuson @makermelissa do you have one?

@caternuson
Copy link
Contributor

@ladyada I don't have a PID1115. But I do have a bare MCP23008 that I'm wiring up to test this. Stay tuned...

@makermelissa
Copy link
Collaborator

I don't have one of those either.

@ladyada
Copy link
Member

ladyada commented Feb 11, 2020

@makermelissa good thing to order, get one of the RGB ones :)

@FoamyGuy
Copy link
Contributor

@ladyada @caternuson would it apply similarly to the RGB versions (PIDs 1110 and 1109)? I have one of those, I'm not whether it's negative or positive. I can test it out later tonight if that is helpful.

@ladyada
Copy link
Member

ladyada commented Feb 11, 2020

@FoamyGuy yah its the same code - either would be good for testing - either itll work or it wont :)

@makermelissa
Copy link
Collaborator

Ok, will add to my next order @ladyada.

@caternuson
Copy link
Contributor

caternuson commented Feb 11, 2020

The real issue here is the use of a string literal in the ctor's I2C write. This expands out to having bits which get written into both the IODIR and IPOL registers:
image
Problem can be solved by simply adding a b in front of the literal:

device.write(b'\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00')

and you get expected traffic:
image

I recreated issue #22 with an MCP23008 and also confirmed above change fixes it.

@foozmeat Can you update your PR to be like that? Basically identical to original code but with the additional b as shown above. The write being done in init() is using the sequential register write feature. The first value is the starting register, 0x00 in this case, not a value being sent to a register. The values that follow are then sequentially written out to the registers. So, 0xFF is the first value which gets sent to IODIR, 0x00 to IPOL, etc.

EDIT: The LCD keypads all use an MCP23017, which has a different register layout and init code and do not have this issue.

@foozmeat
Copy link
Contributor Author

@caternuson May I suggest changing the init to writing values to named registers more like how the MCP28017 init code works? I think it reads more clearly to a less experienced person (me). I'm happy to do the work.

@caternuson
Copy link
Contributor

Sure, that approach would work too. Go for it!

@FoamyGuy
Copy link
Contributor

Confirmed that this change has no issues for the PID 1110 LCD. The example code from the learn guide works the same with current adafruit:master and foozmeat:master. I can check again after the discussed changes.

@foozmeat
Copy link
Contributor Author

I set up the init method to match the MCP28017 more closely.

There appears to be a typo in

self.iocon = 0x4 # turn on IRQ Pins as open drain
referencing an iocon when the property is really io_control. I can sneak that fix into this PR or do another.

@FoamyGuy
Copy link
Contributor

I tested the updated version with PID 1110 LCD and it is still working as expected.

I would lean toward making a new PR for it so it's documented separately for anyone potentially looking for it in the future.

@caternuson
Copy link
Contributor

Cool. Thanks. Looks good. Test it on MCP23008 and works as expected.

@caternuson
Copy link
Contributor

@foozmeat Thanks for finding this and making the PR to fix it. Please open a new issue for the MCP23017 typo.

@caternuson caternuson merged commit 31b5825 into adafruit:master Feb 12, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 18, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 2.1.3 from 2.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#52 from ares-est/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_CLUE to 2.0.3 from 2.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#17 from kattni/slideshow-fix
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#14 from dherrada/master
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#16 from kattni/slideshow-example
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#15 from kattni/add-display-object
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#12 from kattni/add-space
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#11 from kattni/variable-change
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#10 from kattni/level-bubble-fix
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#9 from kattni/color-fix
  > Merge pull request adafruit/Adafruit_CircuitPython_CLUE#8 from kattni/example-update

Updating https://github.com/adafruit/Adafruit_CircuitPython_Fingerprint to 1.1.6 from 1.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Fingerprint#11 from stitchesnburns/stitchesnburns-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS2MDL to 2.0.2 from 2.0.1:
  > Update README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM303_Accel to 1.0.3 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM303_Accel#5 from BiffoBear/rename-example-file
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM303_Accel#4 from FoamyGuy/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM303DLH_Mag to 1.0.4 from 1.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM303DLH_Mag#5 from FoamyGuy/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx to 2.2.3 from 2.2.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP230xx#21 from foozmeat/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MPU6050 to 1.0.4 from 1.0.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_MPU6050#5 from FoamyGuy/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 3.1.10 from 3.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#65 from cogliano/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display to 3.8.9 from 3.8.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_RGB_Display#70 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_BluefruitConnect to 1.0.11 from 1.0.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_BluefruitConnect#17 from caternuson/controller_example

Updating https://github.com/adafruit/Adafruit_CircuitPython_BusDevice to 4.2.0 from 4.1.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#43 from dhalbert/avoid-alloc

Updating https://github.com/adafruit/Adafruit_CircuitPython_Gizmo to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Gizmo#10 from FoamyGuy/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_LPS2X
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.

6 participants