Hi everyone, i am currently working on an EMG project and i am trying to send a accurate emg signal from the photon to my computer application, when i am using only one ADC and send the data of it, it looks ok, but when i try to send the data from four adcs it looks like the data from the four ADC’s mix up.
Actually i made a test and even when i set the value of vA0, vA1, vA2, vA3 for 4000,3000,2000,1000 the data i receive is mixed between this values.
here is my code:
//SYSTEM_MODE(SEMI_AUTOMATIC);
TCPClient client;
byte server[] = { 192, 168, 25, 5 };
int an0 = A0;
int an1 = A1;
int an2 = A2;
int an3 = A3;
int an4 = A4;
int16_t n;
byte vA0[200] = {};
byte vA1[200] = {};
byte vA2[200] = {};
byte vA3[200] = {};
unsigned long t1, t2, t3;
void setup()
{
if (client.connect(server, 11000))
{
Particle.publish("connected");
delay(1000);
}
else
{
Particle.publish("connection failed");
}
setADCSampleTime(ADC_SampleTime_56Cycles);
}
void loop()
{
t1 = millis();
for(int i = 0; i<10; i++){
for(int j = 0; j<100;j++){
n = analogRead(an0);
int k = j*2;
vA0[k] = n & 0xFF;
vA0[k+1] = (n >> 8) & 0xFF;
n = analogRead(an1);
vA1[k] = n & 0xFF;
vA1[k+1] = (n >> 8) & 0xFF;
n = analogRead(an2);
vA2[k] = n & 0xFF;
vA2[k+1] = (n >> 8) & 0xFF;
n = analogRead(an3);
vA3[k] = n & 0xFF;
vA3[k+1] = (n >> 8) & 0xFF;
}
client.write(vA0,200);
client.print("0<EOF>");
delay(5);
client.write(vA1,200);
client.print("1<EOF>");
delay(5);
client.write(vA2,200);
client.print("2<EOF>");
delay(5);
client.write(vA3,200);
client.print("3<EOF>");
delay(5);
}
if (!client.connected())
{
Particle.publish("disconnecting.");
client.stop();
for(;;);
}
}
Here is a video where the adc is connected to the same signal that the osciloscope is:
The value expected in the first channel was 0 in the beggining but the data looks like its mixed with the values from the other channels.
Sorry for my bad english.