One little doubt about AVR, what uses more dynamic memory,
String == String
or char a[] in strcmp(x[],a[]).
Its a Good Idea reprogram an code from Arduino UNO to Arduino MEGA.
One little doubt about AVR, what uses more dynamic memory,
String == String
or char a[] in strcmp(x[],a[]).
Its a Good Idea reprogram an code from Arduino UNO to Arduino MEGA.
Even an empty String takes 6 bytes of RAM, so two take 12.
My doubt its I have to use a sequential commands, from voice using 1Sheeld, and it return or a char array or already passed to String.
For dont get low memory and instability may I use
const String receptionCommandOn="turn it on";
if(VoiceRecognition.getCommandAsString()==receptionCommandOn )
to
if(VoiceRecognition.getCommandAsString()=="turn it on")
lakesidepark:
One little doubt about AVR, what uses more dynamic memory,String == String
or char a[] in strcmp(x[],a[]).
The problem with the String class (capital S) is not the amount of memory but the way it uses memory. Any form of dynamic memory allocation is risky in the small memory of an Arduino. Even if it uses a bit more SRAM it is much better to allocate space at compile time for all the cstrings that you will need.
There is only one program running on an Arduino so there is nothing else that can use any memory that might be temporarily un-allocated.
...R
Dear Robin what function may I use, for speed and accuracy, I'm testing with Arduino UNO, but it seems I need shift to Mega, soon as receive the board.
The memory in any avr is insufficient to run String in a fool proof way. It's made for a larger computer, with an operating system that cleans up after memory is no longer needed.
I know but onesheeld dont give any option and i d´like to optimize my code
lakesidepark:
I know but onesheeld dont give any option and i d´like to optimize my code
What code would that be?
Then you might consider using sString.reserve( x ) to assign your string a set amount of memory to use. Perhaps something like
String sString;
sString.reserve( 300 );
After setting the string reserved area to 300 then use a Serial.println ( sString.length() ) to get an idea of how many actual bytes the string is using and adjust accordingly. I like to add a few more bytes then the highest used amount as a safety.
sString = ""; will clear the sString buffer and sString.concate( " some junk " ) adds to the buffer.
It just takes a bit more xxxxx to use String with the Arduino Uno and the like.
lakesidepark:
Dear Robin what function may I use, for speed and accuracy,
Have you carefully studied the link I gave you in Reply #3?
Idahowalker:
sString = ""; will clear the sString buffer and sString.concate( " some junk " ) adds to the buffer.
That's when using the String class causes a problem in the small memory of an Arduino.
...R