Nano RP2040 Connect - itoa works, ltoa does not work

Hello,

I am having a problem with my RP2040 and I would be grateful for any help. I am trying to print a variable to a display. itoa and utoa work. ltoa and ultoa do not work. I get the following error when I try to compile the sketch: " 'ltoa' was not declared in this scope "

The code:

#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 5, 4);

long variable;

void setup(void) {
  u8g2.begin();
}
char buffer[33];
void loop(void) {
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_courR14_tf);
  u8g2.drawStr(6, 24, (ltoa(variable, buffer, 10)));
  u8g2.sendBuffer();
}

I have tried with both a genuine Nano RP2040 Connect board and with a RP2040-Zero board and I get the same results. For the Nano RP2040 Connect I installed the Mbed OS Nano Boards version 4.1.5. For the RP2040-Zero I installed Mbed OS RP2040 Boards version 4.1.5.

I am using Arduino IDE 1.8.19

With the Atmega328 Arduino UNO board ltoa works fine.

I do not know what I am doing wrong and what else to do. Should I upgrade to Arduino IDE 2.3.2?

The function might not be unsupported, or you have a missing library problem. Please post the full error message, using code tags.

snprintf() should work.

Note that Mbed is end-of-life and will go away, so consider using another approach.

@vejeliha
Take the note that on RP2040 in arduino environment an int and long types both has 4 bytes, so you you can use itoa as replacement of ltoa

1 Like