Hello,
I’ve rigged up an arduino mini-pro as a slave to a linkit one; I needed more interrupts for the data logger I’ve been building. I’ve got the slave sending anemometer data to the master via wire() & I2C, the problem I’m having is that only some of the data is getting sent.
I’ve attempted looping over the charArray, and the result at the master end and so far no luck. For illustration purposes I’ve removed the code that handles getting the anemometer data and hard-coded a string; the same format string construct before sending.
I send the string “S123.09D232.42” from slave to master but only “S123.09D” is received. I’ve tried setting the requested data to 32 bytes to no avail. and I’m not sure what exactly I’ve done incorrectly.
I appreciate your insight.
[attachment=0]DSC_0800.JPG[/attachment]
[attachment=1]DSC_0799.JPG[/attachment]
[attachment=2]DSC_0798.JPG[/attachment]
Byron
Slave:
[code]#include <Wire.h>
String tstStr = “S123.09D232.42”;
char copy[32];
void setup() {
Serial.begin(9600);
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
}
void requestEvent() {
tstStr.toCharArray(copy,32);//string to charArray.
//Wire.beginTransmission(8);//when this is uncommented NOTHING WORKS!
//for(int z = 0; z < sizeof(copy); z ++){//this? ya, it didn’t work either.
Wire.write(copy);
//}
//Wire.endTransmission();//when this is uncommented NOTHING WORKS!
} [/code]
Master:
[code]#include <Wire.h>
char t[32]={};//empty array where to put the numbers
//char x[32]={};//empty array where to put the numbers
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
requestOne();
//requestTwo();
}
void requestOne(){
delay(1);
Wire.requestFrom(8,32); // request 32 bytes from slave device #8
int i=0;
while (Wire.available()) { // slave may send less than requested
//for(int z = 0; z < 32; z ++){
t[i] = Wire.read();
//}
i=i+1;// receive a byte as character
}
Serial.println(t); //shows the data in the array t
delay(500);
} [/code]
This is just testing code so I don’t have to mess up the code project until it really works. And right now, it’s not really working.