I’m assuming I’m missing a library?
error: 'toCharArray' was not declared in this scope
I’m assuming I’m missing a library?
error: 'toCharArray' was not declared in this scope
You might have to share your code for a minimal example that displays the problem. Here’s a sketch I knocked up just now for an Uno. The main file is located in src/main.cpp
. If your sketch is in a *.c
file then you don’t get Strings.
#include "Arduino.h"
void setup() {
Serial.begin(9600);
}
void loop() {
String aString = "Hello World";
char aBuffer[15];
aString.toCharArray(aBuffer, aString.length()+1);
Serial.println(aString);
Serial.println(aBuffer);
Serial.println();
delay(2000);
}
This works fine for me, can you compile this code?
Also, you have to beware of using String
variables in Arduino code. This is because there’s only a limited amount of Static RAM and amending String
s is fraught with dynamic memory allocations. It’s best to use char *
or char []
wherever “strings” are required. Useful as the String
data type is on other platforms with more Static RAM.
Cheers,
Norm.