ESP32Cam and Servo Control

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

ESP32Cam and Servo Control

Postby MadScientist » Tue Jul 09, 2019 1:00 am

I'm sorry if this is the wrong forum to ask this in. A friend of mine gave me an ESP8266 a few months back and now I'm hooked no making gadgets and devices of all kinds. I recently bought several ESP32 boards and 2 ESP32Cam boards.

I'd like to use the ESP32Cam to be able to control it's own Pan/Tilt mount that I am building using 2 small servo motors (MS18). I have tested the servo control code and it works fine, and I have tested the camera streaming code and that works fine as well. However, when I build the sketch with the camera streaming enabled then the servo motors do not work.

I have been able to interface with other things while the camera is enabled, specifically the DHT11 Temperature/Humidity sensor. That works fine. It's almost like when the camera is in use the ESP32Cam is not able to do PWM (maybe the camera module is using up all of the available system timers? I honestly have no idea).

Is this by design and I just missed that somewhere? Is there something I need to do to make it work?

Thanks in advance!

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32Cam and Servo Control

Postby MadScientist » Tue Jul 09, 2019 2:19 am

I think I resolved it. It looks like I just need to specify higher numbered timers for the servos. I wasn't able to get the servos to work using timers 1 or 2, but 5 seems to work fine.

VladTheImpaler
Posts: 16
Joined: Fri Jul 05, 2019 4:35 am

Re: ESP32Cam and Servo Control

Postby VladTheImpaler » Tue Jul 09, 2019 6:30 am

Yep, first timer is used to generate the camera clock. Dont use timer1 and timer2 while running camera.

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32Cam and Servo Control

Postby HermannSW » Tue Jul 09, 2019 8:22 am

MadScientist wrote:
Tue Jul 09, 2019 1:00 am
... I'd like to use the ESP32Cam to be able to control it's own Pan/Tilt mount that ...
Different camera (Raspberry camera), and only tilt calibration (my camera has no Pan).
But the automatic calibration code in this posting might be interesting/useful to you with ESP32-CAM as well:
https://www.raspberrypi.org/forums/view ... 1#p1231151
Image

In this posting I added µs resolution waveform generation to FCameraWebServer:
https://www.esp32.com/viewtopic.php?f=1 ... 079#p46079

In this thread you can see how to add new features to Examples->ESP32->Camera->CameraWebServer:
https://www.esp32.com/viewtopic.php?f=19&t=11190

In this thread you can see how @VladTheImpaler did RC/PWM control a tank based on CameraWebServer:
https://www.esp32.com/viewtopic.php?f=19&t=11337

VladTheImpaler
Posts: 16
Joined: Fri Jul 05, 2019 4:35 am

Re: ESP32Cam and Servo Control

Postby VladTheImpaler » Tue Jul 09, 2019 12:26 pm

If the HTML RC wasnt slow / inaccurate i would fly copters with it.

An esp32-cam can do what this one does:
Image

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32Cam and Servo Control

Postby HermannSW » Tue Jul 09, 2019 1:51 pm

VladTheImpaler wrote:
Tue Jul 09, 2019 12:26 pm
If the HTML RC wasnt slow / inaccurate i would fly copters with it.
That is a good point, I will have to build in a heartbeat signal between intex.html(browser) and app_httpd.cpp(ESP32) and let the ESP32 do "full stop" automatically when no heartbeat received, at least for the 5m/s caterpillar robot.

For indoor use "full stop" will be different to what one normally thinks in order to minimize linear braking distance.
Robot will do full U-turn as shown here (robot did 2.5m/s, just revert one motor direction, keep speed of both motors).
And it will NOT stop the U-turn but keep turning.
While turning it will reduce speed of the motors to 0.
This will not reduce the total braking distance, but the linear braking distance since robot will keep turning locally until stopped.
https://forum.arduino.cc/index.php?topi ... msg3236016
Image

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32Cam and Servo Control

Postby HermannSW » Tue Jul 09, 2019 5:44 pm

> RC wasnt slow / inaccurate
>
I just tested a newly arrived ESP32-CAM module, and the FCameraWebServer reported framerates were much less than with my current working ESP32-CAM module. It turned out to be Wifi problems, since after I added an external Wifi antenna to the new ESP32-CAM module framerates are much higher, and the sketch became really reliable:
Image

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32Cam and Servo Control

Postby MadScientist » Thu Jul 11, 2019 5:34 pm

So just a followup, now that I've got the camera working with the servo I wanted to add a 2nd servo. However no matter what I do, as soon as I add the 2nd servo the unit just starts endlessly rebooting with brownout warnings. I've tried various USB cables, various power sources, etc. So far no matter what I do the unit will not handle 2 servos. I've also tried with just a Node32s (non-camera) board and got the same thing. Do I need a second power source just for the servos? That would be a little inconvenient for the project I had in mind but if it's required then it's required.

Thoughts, anyone?

Thanks for all the great feedback and sharing of projects so far. This is wildly fascinating to me and is a leading contributor to my lack of "going outside-ness" :)

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32Cam and Servo Control

Postby HermannSW » Fri Jul 12, 2019 4:05 pm

You need a separate power source for the servos:
https://forum.arduino.cc/index.php?topi ... msg3211401
Don't try to power servos or motors from the 5V output of an Arduino. You will damage the Arduino if you do so.

Use a separate power supply for the servos, and connect the grounds together.

Servos can consume 5 or more watts while moving.
...

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32Cam and Servo Control

Postby MadScientist » Fri Jul 12, 2019 6:53 pm

Thats more or less what I though... What I ended up doing last night, and this seemed to work, was to use a double headed USB cable from an older USB hard drive. This let me draw power from two usb ports but still only need ONE connection going to the ESP32 and servos. I then moved the servos draw off of the ESP32 and just had them draw directly from the power coming down the usb wire before it hit the ESP32. That seems to have worked and the unit is really stable. As a happy side effect the chip is running significantly cooler now too.

I guess that all makes sense now that I think about it.

Thanks, all. You've been a great help! This is fun!

Who is online

Users browsing this forum: Bing [Bot] and 57 guests