[SOLVED] PIO Library/Sketches For The Nano RP2040

Using the PDM code in the ArduinoCore-mbed as a guide I tried porting the simple "hello-pio" example from the Raspberry Pi PIO examples to the Nano RP2040. This code should emulate the standard blink sketch, but using PIO to interact with the GPIO pin. I can see that the sketch is running because print statements in the loop section of the sketch appear on the serial console, but I cannot get the LED to blink.

Before posting all the code, I was wondering if someone has done something similar successfully? If so, could you point me to the code? I am ultimately trying to create NeoPixel and HC-SR04 libraries using PIO for the Nano Connect.

1 Like

Yes, I've done this successfully. Have you compiled the PIO code with pioasm.exe and included the "hello.pio.h" file in your sketch? Is the led pin specified incorrectly?

The sketch below works

include <hardware/pio.h>

// Our assembled program:
#include "hello.pio.h"

PIO pio = pio0;
uint offset;
uint sm;

void setup() {
  offset = pio_add_program(pio, &hello_program);
  sm = pio_claim_unused_sm(pio, true);
  hello_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN);
}

void loop() {
  // put your main code here, to run repeatedly:
  pio_sm_put_blocking(pio, sm, 1);
  sleep_ms(5000);
  pio_sm_put_blocking(pio, sm, 0);
  sleep_ms(5000);
}

Thanks for the quick reply. Things are still not operational here. I see that you are specifying the LED pin as PICO_DEFAULT_LED_PIN, which is pin 25. I changed that to be pin 13, and the LED still does not blink.
Just to be clear, I am using the ArduinoCore-mbed board library and not the Earle F. Philhower's board library.
I built the code physically, including hello.pio.h at the top of the file and also as a pseudo-library with a skeletal .cpp and .h file. Here is the directory structure I am using:

├── examples
│   └── tryit
│       └── tryit.ino
├── library.properties
├── LICENSE
├── README.md
└── src
    ├── hello.cpp
    ├── hello.h
    ├── hello.pio
    └── hello.pio.h

I can provide the contents of any of the files if that would help. Thanks again.

You need to upload your sketch and all your code.

Have you tried running the sketch I supplied with the hello.pio.h in the same folder? you may have a path issue unless this directory structure is stored in your libraries folder.

Whether you're using the mbed core or community core shouldn't matter for this example. The above sketch works on both.

I tried placing the .ino and .pio.h in the same directory and the same results. I created a GitHub repo that contains my pseudo library incorporating your code.
There is a zip file included that I use to load the library using the Arduino IDE.

Thanks.

Downloaded the code, stuck it in my library folder and the tryit example ran perfectly using the mbed core.

So in that case I would recommend attaching an LED to a known pin. It could be your led is bust or the pin names are getting confused somehow. Remmebr the RP2040 code is wanting the GPIOs in the RP2040 pinout names, not the Arduino names (I'm guessing these are different).

Thanks for all the effort you put into this. It turns out that the board LED is connected to GPIO 6, and when I plug that into my sketch all works.
It appears that when using PIO, the pin numbers that need to be used are RP2040 GPIO pin numbers and not Arduino pin numbers. It makes sense.
I obviously assumed (erroneously) that the pins would be automatically mapped appropriately.
Again, thanks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.