Go Down

Topic: Arduino Duemilenove and Mega 2560 communication (Read 783 times) previous topic - next topic

C222

I have owned two Arduino Duemilenove for quite some time and they have always worked as I expected them to. I recently purchased an Arduino Mega 2560 and I have been trying to get it to talk to both the Arduinos.
My ultimate goal is to control all three over Ethernet using the Mega as the master. However, they have not been communicating properly.
Here is a quick sketch of the wiring.
http://web.engr.oregonstate.edu/~randb/A2009toAM.png
The result of everything is no blinking when there is only a usb plugged into the Mega (both boards get power though). If I plug in another usb to the Duemillemove also, it blinks irregularly about 15 times then stops.

Arduino 2009 code:
Quote

void setup()
{
  Serial.begin(9600);
 
  pinMode(13,OUTPUT);
}

char waitForCMD()
{
 while(!Serial.available()){}
 return(Serial.read());
}

void doAction(char a)
{
 switch(a)
 {
   case '1':
   digitalWrite(13,HIGH);
   break;
   case '0':
   digitalWrite(13,LOW);
   break;
   default:
   break;
 }
}

void loop()
{
 doAction(waitForCMD());
}


Arduino Mega Code:
Quote

char stuff[] ={1,1,1,1,1,1};
char inte[] = {0,0,0,0};

void TXcommand(char action, char data[])
{
 digitalWrite(13,HIGH);
 Serial3.write(action);
 Serial.write(action);
 if(data)
 {
   while(digitalRead(2)!=HIGH){}
   Serial3.write(data);
   Serial.println(data);
   memset(inte,0,4);
 }
 digitalWrite(13,LOW);
}

void setup()
{
 pinMode(2,INPUT);
 Serial.begin(9600);
 Serial3.begin(9600);  //TXcommand('l',stuff);
 randomSeed(analogRead(0));
}

int lux=0;

void loop()
{
 TXcommand('1',0);
 delay(10);
 TXcommand('0',0);
 delay(10);
}


Go Up