Problem with the Elemyo EMG sensor on ESP32 - infinite reboot

Hello everyone!

I use an EMG sensor from Elemyo. Everything works correctly on Arduino MEGA, the ELEMYO library is connected, filtering too.

But when connected to ESP32 (powered by 5 V, signal on GPIO 33, 32) and using the same library - the microcontroller infinitely reboots

I tried different pins and turned off filtering - the effect is the same.

Or do I need another way of filtering?

I will be very grateful for your help


#include <ELEMYO.h>
#define   CSpin         10
#define   sensorInPin1  32     // analog input pin for the first sensor
#define   sensorInPin2  33     // analog input pin for the second sensor

int sensorValue1 = 0;          // value read from the first sensor
int bandStopValue1 = 0;
int bandPassValue1 = 0;
int lowPassValue1 = 0;

int sensorValue2 = 0;          // value read from the second sensor
int bandStopValue2 = 0;
int bandPassValue2 = 0;
int lowPassValue2 = 0;

ELEMYO MyoSensor(CSpin);

void setup() {
  Serial.begin(115200);
  MyoSensor.gain(x1);
  pinMode(sensorInPin1, INPUT);
  pinMode(sensorInPin2, INPUT);
}

void loop() {
  // Read and process first sensor
  sensorValue1 = analogRead(sensorInPin1);
  bandStopValue1 = MyoSensor.BandStop(sensorValue1, 50, 4);
  lowPassValue1 = MyoSensor.LowPass(sensorValue1, 80, 2);
  bandPassValue1 = MyoSensor.BandPass(sensorValue1, 30, 80, 2);

  // Read and process second sensor
  sensorValue2 = analogRead(sensorInPin2);
  bandStopValue2 = MyoSensor.BandStop(sensorValue2, 50, 4);
  lowPassValue2 = MyoSensor.LowPass(sensorValue2, 80, 2);
  bandPassValue2 = MyoSensor.BandPass(sensorValue2, 30, 80, 2);

  // Print results to the Serial Monitor
  Serial.print("Sensor 1: ");
  Serial.print(sensorValue1);
  Serial.print(" ");
  Serial.print("Sensor 2: ");
  Serial.println(sensorValue2);
  
  delay(10);
}

Serial:

Thanks for posting your code correctly.

Serial monitor output should be posted the same way: copy the text from serial monitor and paste it into your post between code tags (not the same code tags as your code!).

You went to much trouble to highlight parts of the text of your post in bold. Doing this doesn't provide any additional information. Your time would be better spent posting, for example, a link to the tech specs of your sensor.

1 Like

Thank you very much, now. And next time I will observe everything to get useful knowledge

In addition to the link for the sensor, please post a link to the library you are using.

I am surprised it works on the Mega. If you look at the source code, there are calls into the arduino library in the constructor

ELEMYO::ELEMYO(byte pin) {
	_cs = pin;				// choose the chip select pin
	pinMode(_cs,OUTPUT);			// set the pin as output
    	digitalWrite(_cs,HIGH);			// set the pin to default HIGH state
    	SPI.begin();				// initiate SPI

	BS[0].INITIAL();
	}
...

which is NOT guaranteed to be ready when global variable instantiation is performed. That is why many libraries have the .begin() method.

Seems like a fundamental design flaw in the library.

I'm not sure if that is the cause...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.