I am new to arduino field. I am trying to construct an EMG sensor which transmits signals wirelessly. I am using nRF24l01 module for wireless transmission. Below code which is used for transmitter is not working fast.
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include “EMGFilters.h”#if defined(ARDUINO) && ARDUINO >= 100
#include “Arduino.h”
#else
#include “WProgram.h”
#endif#define TIMING_DEBUG 1
#define SensorInputPin A0EMGFilters myFilter;
SAMPLE_FREQUENCY sampleRate = SAMPLE_FREQ_500HZ;
NOTCH_FREQUENCY humFreq = NOTCH_FREQ_50HZ;//create an RF24 object
RF24 radio(9, 8); // CE, CSNstatic int Threshold = 1000;
unsigned long timeStamp;
unsigned long timeBudget;//address through which two modules communicate.
const byte address[6] = “00001”;void setup()
{ myFilter.init(sampleRate, humFreq, true, true, true);
Serial.begin(9600);
pinMode(SensorInputPin,INPUT);
radio.begin();
timeBudget = 1e6 / sampleRate;//set the address
radio.openWritingPipe(address);//Set module as transmitter
radio.stopListening();
}
void loop()
{ timeStamp = micros();int Value = analogRead(SensorInputPin); // filter processing int DataAfterFilter = myFilter.update(Value); int envlope = sq(DataAfterFilter); // any value under threshold will be set to zero envlope = (envlope > Threshold) ? envlope : 0; timeStamp = micros() - timeStamp; if (TIMING_DEBUG) { radio.write(&envlope, sizeof(envlope)); Serial.println(envlope); } delayMicroseconds(500);
}