Arduino Mega to Flash

Ok so I need help NOW Plfor getting Arduino Mega to talk to Flash. I have been working from a tutorial for arduino diecimila. I have the serial proxy working and working with diecimila. I have a led flashing with the arduino mega so I know its working but i cant get flash to read it. I have changed the inputs to 30 because thats how many sensors i need in both flash and arduino.

Heres the code I have…arduino…
char serInString[40];
char tempString[4]; // temp string for reading the pwm & output values
int tempVal; // temp int for reading pwm values
int val; // temp int for reading analog en digital inputs
int stringLength = 1; // expected length of string received from Flash
int serInStringLength; // length of string received by Flash.
int digOut = 0; // Number of digital outputs
int digIn = 0; // Number of digital inputs
int digInputs[30]; // array that stores which pins are used as digital inputs max 12.
int digOutputs[30]; // array that stores which pins are used as digital outputs max 12.
int digOutLastValues[30]; // array that stores the last values, an output only updates when there is a change

char pinConfig = {
// array with the pin configuration of Arduino. Don’t forget to change in Flash.
// pin 0 and 1 are not used because they are used by the Serialport (RX/TX)

// COPY-PASTE PIN CONFIGURATION BELOW ALSO TO FLASH –

‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,
‘i’,

// ----------------------------------------------------
};

void setup() {
Serial.begin(57600); // start serial port

// set pinconfiguration according to the pinConfig array
for (int i =0; i < 30; i++) {
//Serial.print(pinConfig*);*
_ if (pinConfig == ‘i’) { // input_
* pinMode(i+2, INPUT);*
* digInputs[digIn] = i+2;*
* digIn++;*
* } *
_ if (pinConfig == ‘o’) { // output
* pinMode(i+2, OUTPUT);
digOutputs[digOut] = i+2;
stringLength +=2; // output string part will have 2 characters*
* digOut++;
}
if (pinConfig == ‘p’) { // pwm output
pinMode(i+2, OUTPUT);
digOutputs[digOut] = i+2;
stringLength +=4; // pwm string part will have 4 characters*

* digOut++;
}
}
}
// Function to read a string from the serialport and store it in an array*

void readSerialString (char *strArray)
{
* int i = 0;
if(Serial.available()){
while (Serial.available()) {
strArray = Serial.read();
i++;
}

}
serInStringLength=i;
}
// Function to find out wether the array is empty or not*

boolean isStringEmpty(char *strArray)
{
* if (strArray[0] == 0) return true;
else return false;
}
void sendInputsToFlash(boolean error)
{
if(error) {
Serial.print(“e,”);
Serial.print(stringLength);
Serial.print(",");
Serial.print(serInStringLength);
Serial.print(",");
}
else Serial.print(“i,”);
// read the defined digital inputs*

* for (int i=0; i < digIn; i++) {
val = digitalRead(digInputs);
if (val == HIGH) {
Serial.print(val,BIN);
}
if (val == LOW) {
Serial.print(val,BIN);
}
Serial.print(",");
}
// read the 6 analog inputs
for (int i=0; i < 6; i++) {
val = analogRead(i);
Serial.print(val,DEC);
Serial.print(",");
}
Serial.println(0, BYTE); // close with a zero byte for XML Flash
}
void updateArduinoOutputs()
{ // position of the current character in the serInstring*

* int serInStringPosition = 1;
// set the defined outputs*

* for (int i=0; i < digOut; i++) {
// check if next character is ‘,’ then it is a digital output*

* // because a pwm value has three characters*
* if (serInString[serInStringPosition + 1]==’,’ ) {
tempString[0] = serInString[serInStringPosition];
tempString[1] = 0;
tempString[2] = 0;
tempVal = atoi(tempString);
// check if this output has changed*

* // this prevents outputs to “flicker”
if(digOutLastValues!=tempVal)
{
if(tempVal==1) digitalWrite(digOutputs, HIGH);
if(tempVal==0) digitalWrite(digOutputs, LOW);
digOutLastValues=tempVal;
}
serInStringPosition += 2;
}
// next pin is not ‘,’ so its a pwm value*

* else {
tempString[0] = serInString[serInStringPosition];
tempString[1] = serInString[serInStringPosition+1];
tempString[2] = serInString[serInStringPosition+2];
tempVal = atoi(tempString);
if(digOutLastValues!=tempVal)
{
analogWrite(digOutputs,tempVal);
digOutLastValues=tempVal;
}
serInStringPosition +=4;
}
}
}
void eraseStrings()
{ // erase contents in the serInString array*

* for (int i=0; i < 40; i++) {
serInString=0;
}
// erase contents in the tempString array*

* for (int i=0; i < 4; i++) {
tempString=0;
}
}
void loop () {
// Serial.println(“Arduino is alive !!!”);
// read the serial port and create a string out of what you read*

* readSerialString(serInString);
// check if there data is received if isStringEmpty is true do nothing.
if(isStringEmpty(serInString) == false) {
/ check if the received string starts with an o

* check if string length is the same as expected length (defined outputs)
if true : return I (input), send input info to flash and update the Arduino outputs*

* if false: return E (error) and the part of the string that is received (to debug)*_

* check if the received string start with an n*
* send only input information ( no new info from Flash ) *
_ /
if(serInString[0]==111) //o*

* {
if(serInStringLength>=stringLength)
{ //the received information is complete*

* updateArduinoOutputs();
sendInputsToFlash(false);
}
// receive info incomplete error is true*

* else sendInputsToFlash(true);
}
else if(serInString[0]==110) //n*

* {
sendInputsToFlash(false);
}
// no o or n as start character, start with error info*

* else sendInputsToFlash(true);
eraseStrings();
}
// short delay before making sure serial.read is not called to soon again*

* delay(20);
}
And Flash…
stop(); // the movieclip stops. ActionScript controls the display
import ArduinoXML; //Class file for communication with Arduino by Flash XMLsocket
import ArduinoFO; // Class file for the arduino board (functions and configuration) uses the ArduinoXML object
/ ------------------ Declaration and initialisation_

Create needed objects for arduino and Flash’s XMLSocket. Create needed Listeners
Variable port needs to be the same as in SerialProxy */
var port:Number = 5331;
var axml:ArduinoXML = new ArduinoXML(port); // the XML-socket object.
// The update time in miliseconds don’t make it lower then 20
var updateTime:Number = 40; // 40 is 25 frames per second
var pinConfig:Array = Array(
// COPY-PASTE PIN CONFIGURATION BELOW ALSO TO ARDUINO –

* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’,*
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *
* ‘i’, *

// -----------------------------------------------------
);
var arduino:ArduinoFO = new ArduinoFO(updateTime, pinConfig); // the Arduino Board object
var arduinoListener:Object = new Object(); // The listener that checks the serial communication with arduino
createArduinoListener(); // configuration of the Arduinolistener
buildGui(); // show the user interface
// ------------------ The functions
function makeVisible() {
_ /--------- Make input data visible on the screen --------------------
This function is called when Arduino has send information to Flash.*_

* You can call the arduino.io[] elements and use the value of it to*
* change the display. You can also update the outputs by setting values*
* in the array.*

* The array index responds with the in-output numbers on the Arduino.*
* - IO 0 and 1 are not used (RX/TX).*
* - arduino.io_array[2] is io pin 2 on the Arduino*
* - arduino.io_array[14] is analog pin 0*
* - arduino.io_array[19] is analog pin 6*
* The values between (15-18) represent analog pin 1-5*
_ */ _

ball.x = 10+((460/1023)*arduino.io_array[14]);
}_

Did you change the device name in the serproxy.cfg file?

How about to remove last comma after last "i" 'i', 'i', 'i' in arduino and in flash

I have same problem, but i notice that after starting the swf file Mega board react and RX led starts to flashing. But only RX. Any ideas?

a day later question for me now is “How to modify this code for Arduino Mega” (it works perfect on Duemilanove):

/* Arduino communication with Flash

  • Use Arduino as an interfaceboard for Flash applications.
  • This code should be used with the following flash files :
  • Flash_arduino.fla
  • ArduinoFO.as
  • ArduinoXML.as
  • More information in the readme.txt
  • Art & Technology - Saxion University of Applied Sciences
  • copyleft Kasper Kamperman / Rene Heijnen, Enschede - The Netherlands - september 2008
  • http://www.kasperkamperman.com
  • code based on :

  • General Purpose computer serial IO
  • copyleft Stephen Wilson http://userwww.sfsu.edu/~swilson/
  • Created October, 2006
  • SERIAL COM - HANDELING MULTIPLE BYTES inside ARDUINO - 04_function development
  • by beltran berrocal created 16 Decembre 2005;
  • copyleft 2005 Progetto25zero1 http://www.progetto25zero1.com

  • Make sure that the pinConfig Array in this file is exactly the same as in the flash fla file.
    */

// variabels
char serInString[40]; // the received string with output information max 40 characters
char tempString[4]; // temp string for reading the pwm & output values
int tempVal; // temp int for reading pwm values
int val; // temp int for reading analog en digital inputs
int stringLength = 1; // expected length of string received from Flash
int serInStringLength; // length of string received by Flash.
int digOut = 0; // Number of digital outputs
int digIn = 0; // Number of digital inputs
int digInputs[12]; // array that stores which pins are used as digital inputs max 12.
int digOutputs[12]; // array that stores which pins are used as digital outputs max 12.
int digOutLastValues[12]; // array that stores the last values, an output only updates when there is a change

char pinConfig = {
// array with the pin configuration of Arduino. Don’t forget to change in Flash.
// pin 0 and 1 are not used because they are used by the Serialport (RX/TX)

// COPY-PASTE PIN CONFIGURATION BELOW ALSO TO FLASH –

‘i’, // Pin 2 ‘i’ for in ‘o’ for out
‘i’, // Pin 3 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 4 ‘i’ for in ‘o’ for out
‘o’, // Pin 5 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 6 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 7 ‘i’ for in ‘o’ for out
‘o’, // Pin 8 ‘i’ for in ‘o’ for out
‘o’, // Pin 9 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 10 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 11 ‘i’ for in ‘o’ for out or ‘p’ for pwm
‘o’, // Pin 12 ‘i’ for in ‘o’ for out
‘o’ // Pin 13 LedPin ‘i’ for in ‘o’ for out

// ----------------------------------------------------
};

void setup() {
Serial.begin(57600); // start serial port

// set pinconfiguration according to the pinConfig array
for (int i =0; i < 12; i++) {
//Serial.print(pinConfig*);*
_ if (pinConfig == ‘i’) { // input_
* pinMode(i+2, INPUT);*
* digInputs[digIn] = i+2;*
* digIn++;*
* } *
_ if (pinConfig == ‘o’) { // output
* pinMode(i+2, OUTPUT);
digOutputs[digOut] = i+2;
stringLength +=2; // output string part will have 2 characters*
* digOut++;
}
if (pinConfig == ‘p’) { // pwm output
pinMode(i+2, OUTPUT);
digOutputs[digOut] = i+2;
stringLength +=4; // pwm string part will have 4 characters*

* digOut++;
}
}
}
// Function to read a string from the serialport and store it in an array*

void readSerialString (char *strArray)
{
* int i = 0;
if(serialAvailable()){
while (serialAvailable()) {
strArray = serialRead();
i++;
}

}
serInStringLength=i;
}
// Function to find out wether the array is empty or not*

boolean isStringEmpty(char *strArray)
{
* if (strArray[0] == 0) return true;
else return false;
}
void sendInputsToFlash(boolean error)
{
if(error) {
Serial.print(“e,”);
Serial.print(stringLength);
Serial.print(",");
Serial.print(serInStringLength);
Serial.print(",");
}
else Serial.print(“i,”);
// read the defined digital inputs*

* for (int i=0; i < digIn; i++) {
val = digitalRead(digInputs);
if (val == HIGH) {
Serial.print(val,BIN);
}
if (val == LOW) {
Serial.print(val,BIN);
}
Serial.print(",");
}
// read the 6 analog inputs
for (int i=0; i < 6; i++) {
val = analogRead(i);
Serial.print(val,DEC);
Serial.print(",");
}
Serial.println(0, BYTE); // close with a zero byte for XML Flash
}
void updateArduinoOutputs()
{ // position of the current character in the serInstring*

* int serInStringPosition = 1;
// set the defined outputs*

* for (int i=0; i < digOut; i++) {
// check if next character is ‘,’ then it is a digital output*

* // because a pwm value has three characters*
* if (serInString[serInStringPosition + 1]==’,’ ) {
tempString[0] = serInString[serInStringPosition];
tempString[1] = 0;
tempString[2] = 0;
tempVal = atoi(tempString);
// check if this output has changed*

* // this prevents outputs to “flicker”
if(digOutLastValues!=tempVal)
{
if(tempVal==1) digitalWrite(digOutputs, HIGH);
if(tempVal==0) digitalWrite(digOutputs, LOW);
digOutLastValues=tempVal;
}
serInStringPosition += 2;
}
// next pin is not ‘,’ so its a pwm value*

* else {
tempString[0] = serInString[serInStringPosition];
tempString[1] = serInString[serInStringPosition+1];
tempString[2] = serInString[serInStringPosition+2];
tempVal = atoi(tempString);
if(digOutLastValues!=tempVal)
{
analogWrite(digOutputs,tempVal);
digOutLastValues=tempVal;
}
serInStringPosition +=4;
}
}
}
void eraseStrings()
{ // erase contents in the serInString array*

* for (int i=0; i < 40; i++) {
serInString=0;
}
// erase contents in the tempString array*

* for (int i=0; i < 4; i++) {
tempString=0;
}
}
void loop () {
// Serial.println(“Arduino is alive !!!”);
// read the serial port and create a string out of what you read*

* readSerialString(serInString);
// check if there data is received if isStringEmpty is true do nothing.
if(isStringEmpty(serInString) == false) {
/ check if the received string starts with an o

* check if string length is the same as expected length (defined outputs)
if true : return I (input), send input info to flash and update the Arduino outputs*

* if false: return E (error) and the part of the string that is received (to debug)*_

* check if the received string start with an n*
* send only input information ( no new info from Flash ) *
_ /
if(serInString[0]==111) //o*

* {
if(serInStringLength>=stringLength)
{ //the received information is complete*

* updateArduinoOutputs();
sendInputsToFlash(false);
}
// receive info incomplete error is true*

* else sendInputsToFlash(true);
}
else if(serInString[0]==110) //n*

* {
sendInputsToFlash(false);
}
// no o or n as start character, start with error info*

* else sendInputsToFlash(true);
eraseStrings();
}
// short delay before making sure serial.read is not called to soon again*

* delay(20);
} [/size]*

With this code i have only Rx from the board, testing with Serial Monitor (Arduino 0015 and 0016). I test with ASCIITable code and Tx works just fine. The same is situation with flash aplication - only Rx blinks._

Please someone! Please… :’( :’( :’(

Ok i found the solution. The problem is in the old code for arduino. So the solution is just replacing old code with this one:

void readSerialString (char *strArray) 
{ 
int i = 0; 
if(Serial.available()){ 
while (Serial.available()) { 
strArray[i] = Serial.read(); 
i++; 
}
}
serInStringLength=i; 
}

also the value in char tempString[4]; shoult be more than 4, i try with 100 and it works fine.

Now comunication Arduino Mega <> Flash works fine.