Hi everyone, I am working with a Nextion screen to input a specific RPM value for a geared DC motor with the use of a L298N driver and PWM. The driver is connected to pins 7 (IN1), 8 (IN2) ,9 (ENA) of an Arduino Nano. With the TX & RX pins of the Nano connected to the Nextion screen.
For the Nextion screen I am making use of the EasyNextionLibrary by @Seithan . It has a simple numeric keypad similar to this one with enter and cancel buttons that start and stops the motor for the desired RPM once pressed. This part works fine and I am able to start and stop the motor at the desired RPM's.
The problem that I am having is while I am busy entering the numbers on the Nextion screen, all of the pins on the Nano is suddenly set to HIGH, thus turning on the DC motor, which is not the desired action. When the RPM value is "entered" with myNex.writeStr() and sent to the Nano, the pins return to the designated states as per the code and the motor can be started and stopped as desired for the entered RPM value.
I did some troubleshooting and found that it was only when the myNex.writeStr() function is used that the pins are set to HIGH. When the buttons on the Nextion are programmed as simple toggle switches there were no issues and the pins stayed in the defined states.
Does anyone have an idea why the pins are set to HIGH? And how caN I set the pins to low while entering the numbers? A simple digitalWrite(pin,LOW) did not work.
I first suspected that the serial communication is causing the Nano to auto reset, setting the pins in a HIGH state. I disabled the auto reset and this still gave the same problem.
Below is the code for the "trigger" for Nano to convert the string from the Nextion to a float value for the RPM. This code forms part of a much larger project and is the only segment that is giving the problem and it is also the only segment that contains the myNex.writeStr() function.
void trigger1() { // TRIGGER FOR THE ENTER BUTTON FOR RPM ENTRY
String Target = myNex.readStr("temp_Target.txt");
Target_float = Target.toFloat(); //TARGET RPM
if (Target_float > Target_max || Target_float < Target_min) {
Target_Valid = false;
Target_float = 0;
String Target_string = String (Target_float, 1);
myNex.writeStr("textTarget.txt", Target_string);
//Display error if above max or below min RPM
myNex.writeStr("textNumber.txt", "err002");
delay(400);
myNex.writeStr("textNumber.txt", "");
delay(400);
myNex.writeStr("textNumber.txt", "err002");
delay(400);
myNex.writeStr("textNumber.txt", "");
delay(400);
myNex.writeStr("textNumber.txt", "err002");
delay(400);
myNex.writeStr("textNumber.txt", "");
delay(1000);
_running = false;
}
else {
String Target_string = String (Target_float, 1);
myNex.writeStr("textTarget.txt", Target_string);
_running = true;
}
}