Skip to content

moved spi block to where it's needed #36

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 6 commits into from
Apr 27, 2021

Conversation

slootsky
Copy link
Contributor

without this block moved, there is an error regarding SCK in use

Traceback (most recent call last):
File "code.py", line 80, in
File "/lib/adafruit_pyportal/init.py", line 152, in init
File "/lib/adafruit_pyportal/network.py", line 95, in init
File "adafruit_portalbase/wifi_coprocessor.py", line 66, in init
ValueError: SCK in use

The spi object is passed into the WiFi constructor, but if there was no esp object passed in, then the spi was ignored and attempted to be reconstructed.

Since spi isn't needed in the if esp block, I just moved it to the else block

@FoamyGuy
Copy link
Contributor

Thanks for submitting this fix @slootsky, the change makes sense to me.

I think we also want to use board.SPI() instead of busio.SPI(board.SCK, board.MOSI, board.MISO) which will help aleviate the issue if the SPI bus has already been initialized before this code is run.

@FoamyGuy FoamyGuy requested a review from a team April 26, 2021 12:10
@slootsky
Copy link
Contributor Author

@FoamyGuy yeah, I saw your patch [ to remove the parameters to board.SPI() ] after I'd done my code.

I didn't realize that SPI would work with no parameters (I haven't gone into the board code). I can add that change if you want.

@FoamyGuy
Copy link
Contributor

I think the main difference is board.SPI() will assume the default pins, but busio.SPI() can be passed different ones if you don't want to use the default.

The other nice thing is board.SPI() is forgiving to being called twice, it will not raise an error if you call it twice. Whereas busio.SPI() tries to initialize the pin again which raises this error.

I do think we want to make that change. If you change this PR to use board.SPI() we can close my PR. I think the way you moved this block into the proper branch of the if statement is a good improvement over mine.

note: I don't have code that tests this line, so I can't confirm it.

Also, having trouble getting black to run correctly.
@evaherrada
Copy link
Collaborator

@slootsky It looks like all you've got to do is run black which should automatically fix the errors we're getting. You can find out how to do that here: https://learn.adafruit.com/improve-your-code-with-pylint/black

The short version is pip3 install black then go to your local repository, then black --target-version=py35 .

…thon_PortalBase into feature/fix_SPI_error

# Conflicts:
#	adafruit_portalbase/wifi_coprocessor.py
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

These changes look good to me.

I tested them successfully with:

Adafruit CircuitPython 7.0.0-alpha.1-817-g927d5a045 on 2021-04-25; Adafruit PyPortal with samd51j20

@makermelissa makermelissa merged commit 7b0b740 into adafruit:main Apr 27, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 29, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_FunHouse to 2.1.0 from 2.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FunHouse#12 from makermelissa/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 2.1.0 from 2.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#61 from makermelissa/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_PortalBase to 1.7.0 from 1.6.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#39 from makermelissa/main
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#38 from makermelissa/main
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#36 from slootsky/feature/fix_SPI_error
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.

4 participants