I am collecting data using a Due that need to be transmitted to a Mega for filing. They share a power supply using 5V and GND jumpers that connect both boards and a USB cable to the Mega. Mega SDL and SDA jumpers (with 3K pullup connections) are connected to the Due SDL and SDA connectors near the reset button.
There are two sets of SDL and SDA connectors on the Due, how do I select which one I am using?
The code I use on the Due is:
//Arduino Due, Slave Device for 2 channel data collection.
#include <Wire.h>
#include "Arduino.h"
void setup() {
Wire.begin(2);// join i2c bus, address for this unit is #2 as a slave (#1 is master)
Serial.begin(9600);
}
unsigned long NData=0;
String logd(150);
int ils ;
int i ;
char x;
void loop() {
NData=NData+1;
logd="";
logd +=NData;
logd +=", ";
logd +=analogRead(A0);
logd +=", ";
ils= logd.length(); // This is the length of the string
Wire.beginTransmission(1); // transmit to device #1 (master, stores data)
Wire.write('
There is no response on the Mega receiving end what so ever.Some where I must be making a major mistake. Any ideas anyone? Thanks!
The Mega code is below:
//Master Device used for Data Collection with an Arduino Mega 2560
#include <Wire.h>
#include "Arduino.h"
/*
Read measurements from other Arduino slave devices using I2C/TWI procedures.
This Master is device #1
Data is collected by device #2 (Arduino Due) and transmitted to this unit.
*/
void setup() {
Wire.begin(1);// join i2c bus as Master,address= #1 (used, but not needed)
Wire.onReceive(ReceiveData); // register event
// initialize serial communication:
Serial.begin(9600);
}
unsigned long NData=0;
String logd="";// what gets filed.
int i ; //Length of the measurement string
char x;
void loop()
{
delay(100);
}
// function that executes whenever data is received from slave
// this function is registered as an event, see setup()
void ReceiveData(int howMany)
{
logd="";
// Start the message at the $ sign as this is the start byte.
if(Wire.read() == '
); // sends recognizable start byte
for(i=0;i< ils;++i) {
char x = logd[i];
Wire.write(x);
}
Wire.endTransmission('#'); // sends recognizable stop byte
}
There is no response on the Mega receiving end what so ever.Some where I must be making a major mistake. Any ideas anyone? Thanks!
The Mega code is below:
§DISCOURSE_HOISTED_CODE_1§
){
for(i=0; i<100; i++){
logd[i] = Wire.read();
// check if this message ends and we need to store the line:
if(logd[i]=='#')
break;
}
Serial.print("Transmitted: ");
Serial.print(logd);
Serial.println();
}
}
); // sends recognizable start byte
for(i=0;i< ils;++i) {
char x = logd[i];
Wire.write(x);
}
Wire.endTransmission('#'); // sends recognizable stop byte
}
There is no response on the Mega receiving end what so ever.Some where I must be making a major mistake. Any ideas anyone? Thanks!
The Mega code is below:
§DISCOURSE_HOISTED_CODE_1§