-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LILYGO SIM7000G - Issue using PWM controlling a DC motor and a servo at the same time #1844
Comments
This is not Johnny-Five code. If it was working fine and then just started acting weird after no changes, I'd be inclined to look for a wiring issue or a short. Physically disconnect the motor controller connection. Does the servo still go wonky when you send a signal to pin 32? |
Hi... sorry for the late respons! The strange thing is that I get the same issue whether the motor driver is connected or not to pins 32, and also if I use pin 13 instead of 12 for the servo. As soon as I call the analogWrite(32,50); line, the servo goes all the way to one end and stops responding to the myservo.write(0) and (180) commands. If the analogWrite(32,50); line is removed, the servo continuously goes back and forth. It doesn't matter if I use pin 32 or 33 either, they both give the same issue. |
Okay, new theory. The analogWrite on pin 32 is changing the clock (the pins are sharing a clock). Servos are very particular about frequency, but motor controllers are not. Try initializing the motor with analogWrite(32, 0) and then initialize the servo. |
Yay... that actually made a difference. I changed the order of pinMode(33, OUTPUT); put a analogWrite(33, 0); after that, and then the myservo.attach(12, 1000, 2000); and then it operates as it should 😄 I will go back to my original project and hopefully get it to work again there too. |
Cool... but note there is a catch. Your motor will be operating on a PWM frequency of 50hz. If this were an LED, you might be able to perceive a flicker. I don't |
Hi there..
I have had some code working for a long time where I used a LILYGO SIM7000G unit connected to a DRV8871 motor driver through pins 32 and 33, and a servo connected to PIN 12. But suddenly/lately it has started to fail and the servo is pushed all the to one end as soon as I do a analogWrite to PIN 32 or 33. I have not done any changes that should have affected this. I also was able to reproduce the problem with a small test program.
#include <ESP32Servo.h>
Servo myservo;
#define SerialAT Serial1
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
myservo.attach(12, 1000, 2000);
pinMode(32, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Loop...");
myservo.write(0);
delay(2000);
myservo.write(180);
delay(2000);
//If I comment out the line below, the servo works fine "every loop",
//but the servo only works the first round when this line is active.
analogWrite(32, 50); //This starts the dc motor but also pushes the servo to the end and it stops working.
delay(2000);
}
Any ideas folks? :)
The text was updated successfully, but these errors were encountered: