I am student in University and my group and I are trying to construct a bluetooth EMG device. We built a circuit to condition the signal, then sent the data through Arduino BT to a computer. At the computer the data was saved in Matlab and manipulated to plot an EMG Signal. We built our own Matlab code because the arduino-matlab interface on the mathworks website was too slow.
Our problem with this process was that our sampling rate was only 200 hz. This is because we had to put in a delay of 5 ms in the arduino code because the serial connection kept terminating at lower delays. For a true EMG device, the sampling frequency must be at least 500 hz. I could not figure out if the termination of the serial connection was due to the arduino board or matlab acquiring the data.
I was looking at different options to increase this frequency such as
1.) sd card storage and then transmission.
2.) Using a bigger board with more EEPROM memory
3.) Different program than Matlab
The analogRead() returns an int which is turned into a string by the arduino before being send and a return is added.
e.g 567 (2 bytes) ==> "567\n" (4 bytes) so you loose factor 2 in communicating.
Try this:
#define SENSORPIN 2 // can't be changed :)
void setup()
{
Serial.begin(115200);
}
void loop()
{
int sensorValue = analogRead(sensorPin);
Serial.write((uint8_t) (sensorValue >> 8)); // some bit masking to get the highbyte
Serial.write((uint8_t) (sensorValue & 0xFF)); // and the low byte
// delay(5); should not be needed
}
y=zeros(6000,1);
for ii=1:6000
y(ii) = fread(s1, 2); // read 2 bytes as one int16 into y(ii)
end
volt = .0049.*y;
plot(volt);
ylabel('Volts');
xlabel('Sample');
(the #button is for code tags)
if that not works you might try
y(ii) = fread(s1, 2); // read 2 bytes as one int16 into y(ii)
high = fread(s1,1) *256; // read MSB byte
low = fread(s1,1); // read LSB byte
y(ii) = high + low;
I would suspect that you're overrunning something on the PC end. Try just running the data into the serial monitor or a terminal program and see if that works without the delay then you'll know it's not the arduino or some hardware issue.