print -- String instruction ???

i'm trying to run the "Virtual etch" instance in the Arduino booklet, but on -- printString(“A”); -- instruction it comes out the error: -- stray '' in program -- what's the meaning? By the way, I see for the first time "printString" and "printInteger"... there is no trace of "print" neither of "String" in the official references... anyone can help? Or even better suggest wher I can found a complete reference of the WHOLE set of instructions usable in Arduino environment?

/* Virtual Etch A Sketch using 2 Potentiometers
This program reads two analog sensors via serial and draws
their values as X and Y

Arduino Code
Christian Nold, 22 Feb 06
int potPin = 4; // select the input pin for the potentiometer
int potPin2 = 5; // select the input pin for the
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from
the sensor
int val2 = 0; // variable to store the value coming from
the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
void loop() {
val = analogRead(potPin); // read the value from the sensor
val2 = analogRead(potPin2); // read the value from the

printInteger(val); // Example identifier for the sensor

printInteger(val2); // Example identifier for the sensor

Ok sorry, I've realized that the "stray " issue was only a stupid keyboard matter - that is a wrong " copied from the booklet and pasted.. but what about printString? Furthermore, in the following sketch (page 44) String looks to be used as a type declaration (String buff = “”; ) while the compiler returns a "String does not name a type" error...

printString() is an old function that's been replaced by Serial.print(): Serial.print() - Arduino Reference. We just forgot to update the booklet. Sorry about that. As for using "String" as a data type: it works in Processing (which is based on Java), but not in Arduino (which is based on C/C++). There is a String library for Wiring - you should be able to use it in Arduino (an older version for Arduino is at: String() - Arduino Reference). Failing that, using strings in Arduino is rather complicated - at least for certain things.

thanks for the help mellis :slight_smile: what do you exactly mean about strings in Arduino environment? Do you think I'll come out of the task of reading 3 joysticks and send the 3 values through a 433 radio module to another Arduino board? The purpose is a simple remote control of a 3 axis cc motor system: do you think that - beside the in/out pins, that are enough indeed - the hardware (and programming...) features are suitable for managing data from 3 different reads in the serial bus?


if I am right, Dave means that the Arduino environment (the software you use to program the boards) compiles the programs in C++ and not in Java as Processing does. This is the reason why some of the Java types, classes and objects (like String) do not work in Arduino.

If you want to work with a string as a data type, you have to make an array of characters or bytes.

When you say that you want to read three joysticks, I guess that you will get 6 values (2 per joystick) in case those joysticks are based on two potentiometers each. Then you will have to encode the information coming from those joysticks and send it through the radio module to the other board.

Let’s say then that you have a serial-to-radio module. What I would do would be to send packaes containing the data fromthe joysticks in the form of packages of 6 bytes (one byte per potentiometer). The sending program would be something like:

int count = 0;

void setup() {
    Serial.begin(9600);  // choose the right speed for your serial port

void loop() {
    for (count = 0; count < 6; count++) {
        Serial.print(analogRead(count)/8, BYTE);
    Serial.print(255, BYTE);

The previous program reads all the analog inputs and sends them through the serial port. Note that it divides the value by 8. The reason for this is that in this way we encode the data from each potentiomenter into an integer between 0 and 127, letting the other numbers: 128 to 255 as possible commands to send through the radio. In this way, we send the byte 255 as the command “end of package” that will help the radio receiving board to know when the package is done.

The program on the receiving side should be something like:

int val = 0;
byte received[6] = {0,0,0,0,0,0};  // make an array of bytes and initialize it to zeroes
int count = 0;

void useReceivedInfo() {
    // this is the function that makes use of
    // the array received to control your motors

void setup() {
    Serial.begin(9600);  // choose the right speed for your serial port

void loop() {
    val =;
    if (val != -1) {
        if (val != 255) {
            received[count] = val;
        } else {
            useReceivedInfo();  // this is the function you have to write to use the data
            count = 0;
    if (count > 6) {
        // this situation means there was an error in the transmission

Now the only thing you have left is to write the method that will take care of the data sent over the radio.



Cool!!! Many thanks David… For the first time I have a bit of clearness in the complicate field hidden beyond the “let’s blink a led” startUp stage… The thing is even more simple and pin-saving, because I plan to use 1-channel joysticks (in reality simple potentiometers), each of one controls the fwd/rev and progressive speed of the dc motor. This is obtained converting the 0/1024 coming from Analog inpt in a double 0/255 range, leaving a dead zone at the center of the pot’s ride (e.g. from 500 to 524) and swapping the fwd/rev control HIGH or LOW as well as the pot value is <500 or >524 Thi section seems to work very well, now I’ll start to work on the new serial perspective… Do you have any advice for the 433 MHZ radio module?Are there compatibility issues with Arduino, like protocols, tx speed etc?

thanks a lot

About radio modules... depending what sort you have, they babble when there is no transmission. With that in mind you need to encode your data in some way that transmits a bunch of transitions before your data and then some sort of mark to let you know when your data starts.

There are many fancy and complicated ways of encoding bits onto radio signals that have nice properties like balancing the 0 and 1 time which is important for some radios, or minimizing the transmission time within the constraints of the radio switching, but I think you will get by with a UART and a wake up sequence.

Maybe something like sending "UUUUw" before your data to wake up the receiver and let it adjust its gain. Some of the 'U's will be corrupted or missed, but by the time you see "UUw" you should be fairly sure that data follows. Those 'U' characters are 0x55 which is a lot of 0-1 bit pairs and the "?" is a solid block of 5 ones. It seems an unlikely sequence to get out of the babbling receiver and a good one for the receiver to adjust its gain. Obviously if you are controlling a death ray you might want to use a checksum on the data too.

Keep your bit rate under the bit rate of the radios. This is probably either 2400bps or 4800bps.

Try to use the hardware UARTs. The SoftwareSerial in 0007 has unreliable timing and using the read side of software serial requires your code to be waiting in the read routine when the data arrives.

thank Jims, the UUUUw and '?' tricks sound worth... since it's just a speed and fw/rev control (no digital positioning, for now) a certain amount of data loss is probably manageable with a good redundancy of the data start code, as you suggest. Now I'll try to find out the right radio in the wide mess of the 433 Mhz module (any suggestion is welcome...) and I'll keep the forum informed of progresses.