Arduino firmata receive string from flash problem

Hi all,

This is my setup:

Hardware → Arduino uno+ethernet shield (using firmata library for ethernet).
Software → Flash including as3Glue

I can send a string from arduino using: firmata.sendString(“hello world”); this works!

In my actionscript I use the following function to send a string to arduino:

public function writeString():void{
var str:String = “Hello world!”;


for(var i=0;i<str.length; i++){
var toSend:int = str.charCodeAt(i)

writeByte(toSend & 0x7F);

writeByte(toSend >> 7 & 0x7F);


This is the callback function on my Arduino that returns the received message to flash. This is just for testing to check if
data was recieved correctly.

void stringCallback(char* string){

char subbuff[strlen(string)];
memcpy( subbuff, &string[0], strlen(string)-1 );
subbuff[strlen(string)-1] = ‘\0’;


Hello world!7@o~) Y ** attempt 1** (using subbuff)
$) ?Hw;%x=|s^/}jt>Mi7QO^n8vo{EwiQz?I+dK >i~fP7^wx S=job#9/Mpm>~ XG3b9~`jOg_?-tufywtO 0MQw
Hello world!) ?Hw;%x=|s^/}jt>Mi7QO^n8vo{EwieB attempt 2 (using subbuff)
Hello world!}jt>Mi7QO^n8vo{EwieB attempt 3 (using subbuff)


Hello world!7Ro~) y attempt 1 (using string)
4) ?Hw;%X=}s^7}jt?Mi7Qo^n<~o{UsieA;p
Hello world!) ?Hw;%X=}s^7}jt?Mi7Qo^n<~o{UsieC1 attempt 2 (using string)
Hello world!}jt?Mi7Qo^n<~o{UsieC1 ** attempt 3** (using string)

firmata.sendString(“some string”); ← works fine everytime


I don’t know where this ghost data comes from. The original message “hello world” was received.

I have added this in the “as3 monitor example”. Everything works fine except sending strings from flash.
All i/o stuff is handled ok.

Can someone help me out?

Thanx in advance!

Why does the function need to make a copy of the string? Just call firmata,sendString() with string.

That is NOT the proper way to allocate space for the (useless) copy. Copying everything but the NULL, and then appending a NULL seems pointless. Why not use strcpy() which will handle copying the NULL?

Yes it is useless to return the same string but this is the first step for the rest of my code.

So to check if the data is received properly i return what was send.

I want to initiate some functions on the arduino by sending a string, on completion it must return this in a string to flash.

I will give the copy a shot.

The last 0 is added after i chopped the last byte of the char* string. Flash adds an extra character after the string.

thanx for your reply.

still the same issue..... :(

Deton: still the same issue..... :(

I wrote a new answer on a post it note. Hope that helps.