Hi everybody,
I'm new on the i2c communication between 2 arduinos, but i've already mastered the basic communication of 1 byte.
I have one arduino which is getting data constantly from 8 capacitive sensors
What I want to do is send what are those sensors capting to the other arduino.
The idea i've came up with is sending 8 different values to 8 different "positions" of the slave-receiver arduino.
How could i do that?
for the moment i have:
#include <WSWire.h>
//#include <Wire.h>
#include <CapacitiveSensor.h>
CapacitiveSensor cs_7_2 = CapacitiveSensor(7,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor cs_7_3 = CapacitiveSensor(7,3); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor cs_7_4 = CapacitiveSensor(7,4); // R 10M entre pin 4 i 6. pin 6 en mode sensat
int sensor1 = cs_7_2.capacitiveSensor(30);
int sensor2 = cs_7_3.capacitiveSensor(30);
int sensor3 = cs_7_4.capacitiveSensor(30);
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
cs_7_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop() {
int opcion=1;
if (opcion==1){
int measure[]={sensor1,sensor2};
for(int thisMeasure; thisMeasure<2; thisMeasure++){
sensor1 = cs_7_2.capacitiveSensor(30);
sensor2 = cs_7_3.capacitiveSensor(30);
if (measure[thisMeasure]>25) {
switch (thisMeasure) { //escollim quin data enviem segons quina posició estiguem de measure
case 0:
Wire.beginTransmission(8);
Wire.write(sensor1);
Wire.endTransmission();
break;
case 1:
Wire.beginTransmission(8);
Wire.write(sensor2);
Wire.endTransmission();
break;
}
}
if (thisMeasure==1) thisMeasure=0;
}
}