Hello,
I am currently trying to use a Mega to interface an EMG sensor with a device connected to through one of the external serial ports on the board.
I have been able to do the functions I need separately, so I can receive EMG data through one of the analog pins (A0) and I can send commands to the serial device when testing with separate programs no problem, but when I try and interface the two I am running into a strange issue.
Essentially, the external device is powered separately and when I plug the device in, it makes the serial monitor display 5V constantly. If I unplug the device, the serial goes back to reading the EMG data as expected. I've tried a few different things and I am a bit lost at the moment.
The code I am using is here (the Serial1.write functions are used to control my external device):
void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(sensorPin);
delay(20);
float currentVoltage = sensorValue * (5.0/1023);
Serial.println(currentVoltage); // prints voltage to monitor
if(currentVoltage > voltageThreshold){
// trigger actions
//Serial.println("CONTRACTION!"); // prints string + new line
digitalWrite(onboardLED, LOW); //this sends 5V, turning on LED
Serial1.write("#W0,1\n");
delay(50);
// Serial.println("ON");
}
else{
Serial1.write("#W0,0\n");
delay(50);
// Serial.println("OFF");
}
delay(50);
}
If anyone has any ideas or has encountered anything similar please let me know!