Closed bharath1000 closed 5 years ago
Hi,
You did not set your boolean variable updateEMG = false;
again in your if (updateEMG ==true){}
condition, so this is always entered and executed, which slows it down.
And I would try using AsyncUDP for the Wifi like in the example ESP32 Async UDP.
The Wifi TCP protocol always has to wait for the handshake with the server and that possibly slows the main loop down.
Best, Katrin
Thank you for your reply!
yes sorry that is fixed in the actual running code, must have removed it when copying by accident. Running the code even without any networking, without any extra functions, just doing a single analog read in the loop and nothing else is maxing out at around 300 Hz. This is confusing to me as the documentation says that it can go up to 6KHz and while through googling I've seen people go even higher than that.
Below is an example of the code we're using (with most of the extra features cut out), still giving us a very slow sampling rate. We are tracking this sampling rate by using the micros() function.
` // Include Libraries
// Initialize Analog Pins uint16_t EMGLeftRA_pin = 39; //A3
// Initialize Mapping for EMG data uint16_t Min = 0; uint16_t Max = 4095; uint16_t Map_Min= 0; uint16_t Map_Max= 2200;
// Initialize EMG Aquisition Variables uint16_t EMGleftRA=0;
// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. void setup() { Serial.begin(115200); delay(10); }
// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. void loop() {
EMGleftRA = analogRead(39);
delayMicroseconds(1);
EMGleftRA=constrain(EMGleftRA*1.814,Min,Max);
EMGleftRA=map(EMGleftRA,Min,Max,Map_Min,Map_Max);
Serial.println(micros());
} `
Hi bharath1000! I hope you need some suggestions after all. I was struggeling with the analog read too and i managed to find a piece of code on a group in facebook a couple of weeks ago. I wanted to measure a 3Khz signal. The thing is if you want to measure a signal you need twice reading speed than the measured one. So the code in Arduino ide is capable to measure with 44Khz but unfortunatelly this is slows down everything on the esp except the measure. Because if we measure we have to disable all interrutps wich of course affect the wifi and things like that that are on your loop.
//================================ ADC Setup =================================
int offset = 1757; //middle DC level reading int vReal[1024]; const double samplingFrequency = 44000; //Hz unsigned int sampling_period_us; unsigned long microseconds; int samples = 1024; //================================ ADC Setup ================================= void setup(){ Serial.begin(115200); }
void loop(){
portDISABLE_INTERRUPTS();
microseconds = micros();
sampling_period_us = round(1000000*(1.0/samplingFrequency));
for(int i=0; i<samples; i++) { vReal[i] = analogRead(CHANNEL)/-offset/; while(micros() - microseconds < sampling_period_us){ } //empty loop microseconds += sampling_period_us; } portENABLE_INTERRUPTS();
}
Iam sending the measured data via websocket to a webserver for ChartJS visualization. Iam able to measure properly a 4Khz sinus or square wave signals with this. I hope i was able to help you a little bit. And if anyone know a better way iam listening :D
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This stale issue has been automatically closed. Thank you for your contributions.
Hardware:
Board: Adafruit Huzzah feather board, wroom-32 IDE name: Arduino IDE
Description:
Hi all,
I'm pretty novice at both arduino, esp-idf, and programming in general, but I am working on a project to take EMG signals (muscle activity) and send it over WiFi to a computer for analysis. So far, I seem to have gotten it working overall, except for the fact that I cannot get a sample rate faster than 125 Hz! Ideally, I need to reach at least 1000 Hz sample rate to get a good signal.
I have tried interrupts, and rtos for multitasking, but nothing has worked. I have even tried an empty loop simply printing micros() since the last loop, and even that only goes ~600 Hz Everywhere I look online, everyone is able to reach 30k+ Hz sample rate. What am I doing wrong?
I've attached my code that uses interrupts (again, much of this is pasted from resources online). Using the adafruit feather board, wroom-32
Thank you!