Pages: [1]   Go Down
Author Topic: SOLVED Is itoa broken in 1.5.2?  (Read 1405 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 03, 2013, 04:13:59 pm by frogeye » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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!
Code:
/*
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);
}

   
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried adding
Quote
#include <itoa.h>
at the beginning of the code? Regards!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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-twist
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-twist


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
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
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

Code:
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
Logged

Venezuela
Offline Offline
God Member
*****
Karma: 17
Posts: 522
Ground, ground, always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Check itoa.c at
Quote
...\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\cores\arduino\

For example:

The equivalent for

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

is

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

I am not sure if this help.
Logged

Pages: [1]   Go Up
Jump to: