davidv1325.
Hello, I hope you are well but I am starting in the world of plc programming and I am excited to program my raspberry pico cards with openplc, I have read and there is not much information about it. For example, how should I program the analog inputs bool, dt, word? What block for the analog inputs should I use?
how to activate the pwm outputs? Please if you have more information you can help me I would appreciate it
Reply 0 0
yonush
Hi, the OpenPLC certainly does support the Raspberry Pi Pico. If you visit the OpenPLC editor  github page there is a documentation folder that contains some information regarding the Pico and its use in the OpenPLC. This includes the I/O mapping (in the PDF) . You can use the analogue like any other I/O.
 
You may have to make one minor change to the 'editor\arduino\src\hal\rp2040pico.cpp' file to increase the ADC from 8bit to 16bit. You can read this post regarding that.
 
 
Reply 1 0
davidv1325.
thank you very much for your reply. I bought several raspberry pico cards, and I had a lot of problems with raspberry pico 16mb because it recognized it as nano rp2040, and I made the transfer without a problem, only the pin assignment is not as described in openplc pinout, I had to discard pin by pin. Today I bought an original raspberry and I'm going to try as you indicate. greetings
Reply 0 0
yonush
There are two sets of pinouts for the Pico. One for the Arduino nano version and the Raspberry Pi Pico. The nano pinout is the one on the OpenPLC website. The other is the one I made and located in the documentation folder i mentioned earlier.  I also have two 16mb pico boards and they work fine with the OpenPLC.
 
Both the Nano and the Rasp pi Pico use the mbed firmware but the implementation is not the same hence why you need the updated .hal & .cpp file that supports the rasp pi pico.
Reply 0 0
davidv1325.
Perfect check the pinout of the link and perfect. Now which block should I use or what should I do to use the lm35 temperature sensor, using adc pins 26, 27, 28
Reply 0 0
yonush
I assume you have the LM35 wired in such a way it matches the input V for the Pico ADC (typically 0-3V3 on the inputs using default ADC_AVDD. page 642 in the datasheet). Once its connected you can read the input like any other input. It would be up to you to convert the V -> degC, which should be easy enough if the LM35 is +10-mV/°C (as per the datasheet for the LM35). So I would assume 250mV would be 25V. If you want to measure negative temperatures then you have to use a different device.
I took a different route by using I2C with a AHT20 (temp+humidity) device. Seeing as the code use with OpenPLC is Arduino, it was not an issue to create a custom block for it. I did the same for a DHT11/22 device which is non I2C but bit banged serial - proved to be a pain as it is a blocking protocol.
Reply 0 0
davidv1325.
okay. but my question is where is the adc block? oh should i create a variable for the lm35 and for the output? For example, if I want to connect a potentiometer to read that potentiometer input, do I create a word or int variable? for the analog input gp26 %IW0, and when it reaches 2v I activate the output %QX0.0. I don't know that whole process and that's what I want to do. because I use ldmicro32 for stm32 and it works perfect but I want to use raspberry using openplc, regards I hope you can help me happy weekend
Reply 0 0
thiagoralves
There is no ADC block. Analog inputs are placed by the hardware driver at %IW locations. You can just compare whatever value is in the %IW pin of your choice with a value threshold (you can use a GT block for example).
 
As for Raspberry Pi you’re out of luck. There is no analog inputs on the Pi board
Reply 0 0
thiagoralves
@yonush please share your custom blocks on a github PR so that everyone can benefit from it.
Reply 0 0
davidv1325.
Hello, thanks for your help. Today I was doing some exercises with rp pico and I configured the gpio27 pin as output %QX1.0 and it doesn't accept it, it doesn't send the logical 1 to the output. In turn, I configured the gpio28 pin as %QX1 output. 1 and if it worked and if it sends the logical 1 to the output. Could it be that I can't use the gpio27 pin as an output and nothing else as an adc input?
Reply 0 0
yonush
Hi, When the pins are mapped to respective I/Os, you cant remap their function. This means the analogue inputs remain as analogues and cannot be reassigned to GPIO.
If you want to change the mappings then you will have to change the relevant "hal" code - the rp2040pico.c file.
GPIO26,27 & 28 are the only analogue inputs on the Raspberry Pi Pico. They differ on the Arduino Nano connect which is NOT the same board as the Rasperry Pi Pico.
 
Reply 0 0
thiagoralves
Actually on the latest version of the OpenPLC Editor you can remap pins. There is a specific section on the upload dialog that allows you to do just that.
Reply 0 0
Reply