Skip to content

NRF24L01 Driver's Test Program Mis-handles Non-default Pins #539

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

Open
EdanStarfire opened this issue Sep 21, 2022 · 0 comments
Open

NRF24L01 Driver's Test Program Mis-handles Non-default Pins #539

EdanStarfire opened this issue Sep 21, 2022 · 0 comments

Comments

@EdanStarfire
Copy link

EdanStarfire commented Sep 21, 2022

Spent some time troubleshooting if I had bad drivers, firmware, or chip, but eventually figured out that the way the current nrf24l01test.py file handles SPI buses and non-default pinouts is misleading at best.

Basically, the config section enables you to add more boards and configs that could be supported, or update pinouts, like I did here with my Raspberry Pi Pico board.

if usys.platform == "pyboard":
    cfg = {"spi": 2, "miso": "Y7", "mosi": "Y8", "sck": "Y6", "csn": "Y5", "ce": "Y4"}
elif usys.platform == "esp8266":  # Hardware SPI
    cfg = {"spi": 1, "miso": 12, "mosi": 13, "sck": 14, "csn": 4, "ce": 5}
elif usys.platform == "esp32":  # Software SPI
    cfg = {"spi": -1, "miso": 32, "mosi": 33, "sck": 25, "csn": 26, "ce": 27}
elif usys.platform == "rp2":  # PI PICO
    cfg = {"spi":0, "miso": 16, "mosi": 19, "sck": 18, "csn": 7, "ce": 6}
else:
    raise ValueError("Unsupported platform {}".format(usys.platform))

However, when it actually comes time to construct the NRF24L01 class object, it's done using only the default pinouts everywhere except the esp32 board. (Notice how the only time the custom mosi, sck, and miso values are used is on the cfg["spi"] == -1 check:

    if cfg["spi"] == -1:
        spi = SPI(-1, sck=Pin(cfg["sck"]), mosi=Pin(cfg["mosi"]), miso=Pin(cfg["miso"]))
        nrf = NRF24L01(spi, csn, ce, payload_size=8)
    else:
        nrf = NRF24L01(SPI(cfg["spi"]), csn, ce, payload_size=8)

I've fixed this for my testing purposes by creating some stub value of cfg["spi"] = -2 and then forcing the bus to the 0 bus since that's the one that I'm using with the other SPI pinout.

    if cfg["spi"] == -1:
        spi = SPI(-1, sck=Pin(cfg["sck"]), mosi=Pin(cfg["mosi"]), miso=Pin(cfg["miso"]))
        nrf = NRF24L01(spi, csn, ce, payload_size=8)
    elif cfg["spi"] == -2:
        spi = SPI(0, sck=Pin(cfg["sck"]), mosi=Pin(cfg["mosi"]), miso=Pin(cfg["miso"]))
        nrf = NRF24L01(spi, csn, ce, payload_size=8)
    else:
        nrf = NRF24L01(SPI(cfg["spi"]), csn, ce, payload_size=8)

I also updated the config to use that stub -2 value:

    cfg = {"spi": -2, "miso": 16, "mosi": 19, "sck": 18, "csn": 7, "ce": 6}

I suspect this could be done more elegantly by adding a flag in the cfg dictionary and checking that for non-defaults and documenting how to turn on non-default pins in the comments right above the config section. I know my fix corrects my mistake, but I'm not sure the most "appropriate" fix for the library's official testing to properly keep it generalized for other users.

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

No branches or pull requests

1 participant