SOLVED Is itoa broken in 1.5.2?

I'm new to Arduino and C programming, so my appologies if this is a simple question.

I'd like to use itoa to convert a sensor counter to text so that I can write it to a char variable, strcat it with text, and display it as a scrolling message on an 2 x 16 LCD.

When compiling in 1.5.2, I get "'itoa' was not declared in this scope" errors. ( I have a DUE - probably not the best choice for a Nube - I blame SainSmart!)

Copying and pasting the same code into IDE 1.0.3 and it compiles without complaining.

I can post the code, but it's a bit 'all over the place' at the moment.

Am I doing something wrong?

TIA

Here is the code. I can get each part to work separatly - read the flow meter, print to the LCD, scroll static text to the LCD.

itoa fails when running verify in IDE version 1.5.2, but runs fine in IDE 1.0.3

Any help would be very welcome!

/*
The beginings of a sketch to measure water flow into and out of a tank 
 and calculate daily usage, peak flow litres/min, and look for patterns that might
 indicate a leak (inflow greater than out flow, visa versa, and high daily flow).
 Sound an alarm and/or close a valve if a leak is detected
 
 The flow meters used are from RS part number 257-133.  They
 have a Schmitt trigger output and give 1200 pulses per litre.
 
 Version 3 added scrolling output to a 2 x 16 lcd matrix
 */
// The pin the encoder is connected
int encoder_in = 2;

// Initialize the counter
volatile  long int pulses = 0;

#include <LiquidCrystal.h> // include the LCD library code


//constants for the number of rows and columns in the LCD
const int numRows = 2;
const int numCols = 16;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char stringA[8];
char stringB[] = "The start of some text ";
char stringC[] = "Count = ";
char stringD[32];
char stringE[] = " ltrs";

void count() {
  // This function is called by the interrupt
  pulses++;
}



void setup() {
  // put your setup code here, to run once:
  pinMode(encoder_in, INPUT);
  attachInterrupt(7, count, RISING);
  lcd.begin(numCols, numRows);
  lcd.print("FlowCountVer2");  // Print a message to the LCD.
  delay(3000);

}

// this function uses scrolling to display a message up to 32 bytes long
void marquee( char *text)
{  
  lcd.print(text);
  delay(1000);
  for (int position = 0; position < strlen(text)-numCols; position++)
  {
    lcd.scrollDisplayLeft();
    delay(300);

  }
}
void loop() {
  // put your main code here, to run repeatedly: 
  lcd.clear();
//convert pulses to a string
itoa(pulses,stringA,10);
strcat(stringC, stringA); 
  marquee(stringC);
}

Have you tried adding

#include <itoa.h>

at the beginning of the code? Regards!

Thanks Palliser, that was the answer.

Why did it work in an earlier version of the IDE? I had a read of the release notes, but couldn't see anything that looked related.

Hello frogeye,
I am happy it worked!

In IDE 1.0.3 atoi is a part of the AVR Libc for 8-bit microcontroller. I am not sure but you should consider things like 1.03 or any other before 1.5 BETA was designed supporting AVR MCUs. The people from Arduino started supporting the Due board (SAM3) sice the 1.5 BETA version. I understand when you say the code ran Ok under IDE 1.03, it was running in a UNO, or Leonardo, etc... but not Due. Am I right? Due is a different monster. ]:smiley:

Palliser:
Hello frogeye,
I am happy it worked!

In IDE 1.0.3 atoi is a part of the AVR Libc for 8-bit microcontroller. I am not sure but you should consider things like 1.03 or any other before 1.5 BETA was designed supporting AVR MCUs. The people from Arduino started supporting the Due board (SAM3) sice the 1.5 BETA version. I understand when you say the code ran Ok under IDE 1.03, it was running in a UNO, or Leonardo, etc... but not Due. Am I right? Due is a different monster. ]:smiley:

You're right - I chose an UNO in the IDE.

The DUE certainly is a Monster! Probably not the best board to use for an introduction to Arduino and C++ based programming! I bought a starter kit from SainSaint and 'assumed' the board would be a good one to learn with. My mistake!

Probably best to get an UNO until the IDE comes out of BETA - either that or there could be a heap more "why doesn't this work" type questions!

Thanks again for your help

I want to clarify that the current Due supporting Arduino IDE 1.5.2 is not beta and is stable (IDE 1.5 BETA was the first supporting DUE version) but I agree with you that UNO is a good choice to start playing with C/C++ basic programming and also to get familiar with the Arduino world . Good luck!

Would it be hard to replicate itoa in software?
WARNING: untested code

unsigned int x;
(x%10U); // ones digit
((x/10U)%10U); // tens digit
((x/100U)%10U); // hundreds digit
((x/1000U)%10U); // thousands digit
// and so forth
unsigned int x;
char xstr[]="00000";
xstr[4]='0'+(x%10U); // ones digit
xstr[3]='0'+((x/10U)%10U); // tens digit
xstr[2]='0'+((x/100U)%10U); // hundreds digit
xstr[1]='0'+((x/1000U)%10U); // thousands digit
xstr[0]='0'+((x/10000U)%10U); // myriads digit
unsigned long x;
char xstr[]="0000000000";
xstr[9]='0'+(x%10UL); // ones digit
xstr[8]='0'+((x/10UL)%10UL); // tens digit
xstr[7]='0'+((x/100UL)%10UL); // hundreds digit
xstr[6]='0'+((x/1000UL)%10UL); // thousands digit
xstr[5]='0'+((x/10000UL)%10UL); // myriads digit
xstr[4]='0'+((x/100000UL)%10UL); // lakhs digit
xstr[3]='0'+((x/1000000UL)%10UL); // millions digit
xstr[2]='0'+((x/10000000UL)%10UL); // crores digit
xstr[1]='0'+((x/100000000UL)%10UL); // "eok" or "oku" digit
xstr[0]='0'+((x/1000000000UL)%10UL); // billions digit

Check itoa.c at

...\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\cores\arduino\

For example:

The equivalent for

xstr[8]='0'+((x/10UL)%10UL); // tens digit

is

ltoa((x/10UL)%10UL,xstr, 10);

I am not sure if this help.