utinko58
Does anyone know what range of analog values the Raspberry Pi Pico W can read? In the past, I used MicroPython to read analog values, and the range was 0-65535 (16 bits), but now I'm using OpenPLC, and I want to confirm this information. I read on some websites that the range is 0-4096, but I'm not sure.
Reply 0 0
thiagoralves
OpenPLC always scales up analog inputs to fit 16 bits so that the range is always 0-65535 for all platforms. If that’s not the case for any platform, then the driver needs to be fixed
Reply 0 0
utinko58
OpenPLC always scales up analog inputs to fit 16 bits so that the range is always 0-65535 for all platforms. If that’s not the case for any platform, then the driver needs to be fixed
Thank you Thiago!
Reply 0 0
yonush
Hi, add the following to the rp2040pico.cpp found in the editor\arduino\src\hal folder. I forgot to do this when I originally made the file.
 
void hardwareInit()
{
// set the analog input resolution to 12bit
analogReadResolution(12);
// set the analog output resolution to 16bit
analogWriteResolution(16);
...
Reply 1 0
utinko58
Hi, add the following to the rp2040pico.cpp found in the editor\arduino\src\hal folder. I forgot to do this when I originally made the file.
 
void hardwareInit()
{
// set the analog input resolution to 12bit
analogReadResolution(12);
// set the analog output resolution to 16bit
analogWriteResolution(16);
...
[203128%2F9048645%2Fmceclip0]
You create the file or only write the void in some of these files?
Reply 0 0
thiagoralves
rp2040pico.cpp should be one of the files in this folder. You should edit that file.
Reply 0 0
thiagoralves
Or just update your editor as I've incorporate those changes now to the latest version.
Reply 1 0
utinko58
Or just update your editor as I've incorporate those changes now to the latest version.

When I set the changes in the file rp2040pico.cpp.

void hardwareInit()
{
    // set the analog input resolution to 12bit // I want to read 16 bit
    analogReadResolution(16);
    // set the analog output resolution to 16bit
    analogWriteResolution(16);
   
    for (int i = 0; i < NUM_DISCRETE_INPUT; i++)
    {
        pinMode(pinMask_DIN[i], INPUT);
    }
    for (int i = 0; i < NUM_ANALOG_INPUT; i++)
    {
        pinMode(pinMask_AIN[i], INPUT);
    }
    for (int i = 0; i < NUM_DISCRETE_OUTPUT; i++)
    {
        pinMode(pinMask_DOUT[i], OUTPUT);
    }
    for (int i = 0; i < NUM_ANALOG_OUTPUT; i++)
    {
        pinMode(pinMask_AOUT[i], OUTPUT);
    }
}


Can I use the file .uf2 to charge to my Raspberry Pi Pico W or I need to do something else?

 
rp2040pico.cp
Reply 0 0
yonush
Once you rebuilt/compiled your code using the above changes, you can transfer the .uf2 to your device. You don't really have to do anything else apart from making sure your PLC program is using the 16bit values and not 12bit values before compiling/transferring.
Reply 0 0
Reply