thiagoralves
You should first check if OpenPLC can program this board. Although the Raspberry Pi Pico uses the same CPU as the Arduino RP2040, they are not the same board. There is a chance OpenPLC won't be able to program it at all, so the GPIO mapping will be the least of your problems.
Reply 1 0
DelarnTheBard
https://github.com/earlephilhower/arduino-pico

This sdk is used for all board with rp2040.
Reply 0 0
thiagoralves
I'm not talking about SDK, I'm talking about bootloader. That arduino-pico project is a 3rd party board support, which is not the same as the official Arduino Nano RP2040. Of course the code would be binary compatible, but these boards probably upload the code through different ways, and that's where the problem might be.
Reply 1 0
DelarnTheBard
the UF2  bootloader ???
Reply 0 0
onos_tech
Great work @thiagoralves! I just programmed a newly purchased Raspberry Pi Pico with board type Nano RP2040 Connect selected. I tested the digital inputs, digital out and some analog input checking out the pins with the Nano Connect pinout below. Except for GP25 which is not physically available as input on the Pico. It will be great if you can find time to add the Pico as a separate board type. Many thanks.


Arduino Nano RP2040 Connect pinout
Reply 1 0
thiagoralves
I don’t have a Raspberry Pi Pico. If you can tell me what kind of IO mapping works for that board, I can then write a separate hal file for it
Reply 1 0
GrowesInd
Hello Everyone!  I am new to OpenPLC, and this forum. I see in OpenPLC documentation 2.2 Physical Addressing page it (now) lists the RP2040 IO addressing (page was updated July/22). I do not see any "RP2040" or "Pico" under the microcontroller download button's (the Arduino icon) pull-down menu for selecting the microcontroller boards. Thanks to @onos_tech for sharing their success when they selected the 'Arduino Nano Connect' board. What I need help with is with "Pico W". It first needs the UF2 firmware file (binary) and several .py files & uses NETWORK library (...or TinyWEB) to configure the wifi connection and connect to a wifi network - in order to get an IP address from the router/AP. How does one go about connecting to wifi network & then downloading the OpenPLC runtime .st binary file? ...If anyone can share a "how-to" document, Youtube tutorial or some step-by-step examples that would be greatly appreciated! I have a PLC program .st file running in simulator mode OK in the editor on my Win10 PC & I can force IO and see chart lines move true/false in debugger. - I now need it running on the Pico W and to access it through my WLAN. Thanks in advance!
Reply 0 0
mbunds

I don’t have a Raspberry Pi Pico. If you can tell me what kind of IO mapping works for that board, I can then write a separate hal file for it


PM me with your post office box and I’ll send you a couple of Picos to play with. If they work-out, great. If not, we’ll find something else. I need to build some “physical I/O manipulation circuitry” to allow OpenPLC to affect I/O on a physical PLC rack, from programmed responses running within a simulated factory. RPI Picos would be cheap and excellent devices for physical I/O feedback from simulation in my use-case, but it would be a great addition to maker’s toolkits!

For now, I’ll be working-up “I/O responders” using ESP32 and Atmel…

Reply 0 0
GrowesInd
I don’t have a Raspberry Pi Pico. If you can tell me what kind of IO mapping works for that board, I can then write a separate hal file for it


I believe the RP2040 Datasheet has the 'memory map & IO' information you are looking for.
https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
See: Chapter 2 - System Description
..."This Chapter describes the RP2040 key system features including processor, memory, how blocks are connected,
clocks, resets, power, and IO."
 2.2. Address Map
Reply 0 0
Rob65
I just looked at the HAL stuff. Seems to be very well written, making it easy to add a HAL for a new target.

What I just did:

  1. Add the arduino-cli core install arduino:mbed_rp2040 command to builder.py
  2. Create an entry for the arduino:mbed_rp2040: Pico in hals.json
  3. Create the .cpp and .hal file for the Raspberry Pi Pico (which is just a copy of the rp2040.hal and rp2040.cpp files for now.

I don't have a Pico board yet, so I have to wait a few days before I can test this but it looks like it's at least compiling (see code section below)
If the Pico board can indeed be programmed just like the rp2040 nano, I guess this should work.

I'll let you know as soon as the boards arrive.

Regards,

Rob

Compiling .st file...
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c
Generating binary file...
COMPILATION START: arduino:mbed_rp2040:pico
Using board 'pico' from platform in folder: C:\Users\Rob\AppData\Local\Arduino15\packages\arduino\hardware\mbed_rp2040\3.4.1
Using core 'arduino' from platform in folder: C:\Users\Rob\AppData\Local\Arduino15\packages\arduino\hardware\mbed_rp2040\3.4.1
Detecting libraries used...
...
...
Using library src in folder: C:\Users\Rob\OpenPLC_Editor\editor\arduino\src (legacy)
"C:\\Users\\Rob\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-size" -A "C:\\Users\\Rob\\AppData\\Local\\Temp\\arduino-sketch-FB57CAFC5FA7C597BB7DAC6424E61B14/Baremetal.ino.elf"
Sketch uses 98894 bytes (4%) of program storage space. Maximum is 2097152 bytes.
Global variables use 43980 bytes (16%) of dynamic memory, leaving 226356 bytes for local variables. Maximum is 270336 bytes.

OUTPUT DIRECTORY:
C:\Users\Rob\OpenPLC_Editor\editor\arduino\examples\Baremetal\build
COMPILATION DONE!
Reply 1 0
GrowesInd
Thanks Rob65!

Nice work & a great help. I looked at the HAL file and IO mapping for Arduino RP2040 Nano that is in OpenPLC files a few weeks ago but had no time to do a deep dive into it yet. I am just getting back in to coding again after a few years - so your reply is very helpful in what to do and how to do it. 
Updated my Arduino IDE only yesterday to 2.0.1, so I will now install the CLI core and start playing! Perfect!
Reply 0 0
Rob65
Yes, this looks to function - at least for digital I/O, I did not check Analog

I added a section for the rp2040_pico to hals,json:
   "Raspberry Pi Pico": {
        "platform": "arduino:mbed_rp2040:pico",
        "define": "BOARD_WIFININA",
        "source": "rp2040_pico.cpp"
    },



Copied the rp2040.cpp to rp2040_pico.cpp and changed the I/O pin definitions:
//Define the number of inputs and outputs for this board (mapping for the Arduino UNO)
#define NUM_DISCRETE_INPUT          12
#define NUM_ANALOG_INPUT            0
#define NUM_DISCRETE_OUTPUT         11
#define NUM_ANALOG_OUTPUT           0
//Create the I/O pin masks
uint8_t pinMask_DIN[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
uint8_t pinMask_AIN[] = {27, 28}; //Apparently Arduino mbedOS crashes when we use A4 onward. They need to fix this...
uint8_t pinMask_DOUT[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
uint8_t pinMask_AOUT[] = {26};


As you can see, I disabled the analog output. I don't use this (yet) and need to test this in the Arduino environment first before taking this over into my OpenPLC HAL.

I also created the rp2040_pico.hal file:
Raspberry Pi Pico,      arduino:mbed_rp2040:pico, BOARD_WIFININA


This now gives me %IX0.0 - %IX0.7, %IX1.0 - %IX1.3 on GP0 - GP11 and %QX0.0 - %QX0.7, %QX1.0 - %QX1.2 on GP12 - GP22

A note about the serial port: it seems the serial port is not enabled by default. I needed to upload a hello-world sketch using the Arduino IDE to get the serial port enabled in order to use the Modbus Master Simulator

Rob
Reply 0 0
yonush
I have started working on a simple PLC using the Raspberry Pi Pico for my students and have attached the schematic and pinouts for the pico layout i used with openplc. The Pico works just fine in a breadboard for demonstrating the PLC. To bootstrap the Pico initially i used a blank plc project and generated a .uf2 file. I then copied this over to the pico RP2 folder whilst its in bootsel mode.

I created a rp2040.hal with the following. I downloaded and installed the Pico mbed  OS manually but you can use the Arduino IDE too. I have had great success with the Pico running standalone and with the pico connected to the runtime as a slave.

# Arduino CLI tool
# https://arduino.github.io/arduino-cli/0.28/installation/#latest-packages
# install the mbed OS for the RP2040 with the CLI tool
# arduino-cli core install arduino:mbed_rp2040
Raspberry Pico, arduino:mbed_rp2040😋ico
Raspberry Pico W, arduino:mbed_rp2040😋ico

Added the following to the hals.json
    "Raspberry Pico": {
    "platform": "arduino:mbed_rp2040😋ico",
     "source": "rp2040pico.cpp"
    },
    "Raspberry Pico W": {
    "platform": "arduino:mbed_rp2040😋ico",
     "source": "rp2040pico.cpp"
    },
 

My changes to the rp2040.cpp as a new file, rp2040pico.cpp are as follows
picocpp1.pngpicocpp2.png

John in NZ
Reply 2 0
thiagoralves
Nice work @yonush ! Could you make a PR on Github with your changes so they become oficial on the editor? I think many users could benefit from that.
Reply 1 0
Reply