PWM Servo control with ESPhome?

i understand but i have try to control servo with an additionnal esp8266 : wemos D1mini, not a esp32 or esp32cam :
i have put back the configuration for my esp32cam, that work fine, and want to put a wemos d1 mini for the servo, in the EspHome documentation, the esp8266 works with servo component, right?

Yes right, the 8-bit esp8266 works fine with the ESPhome servo component for most people.

Done… :slight_smile:

It take 2 hours lol but it works great : Tilt and Yaw on my esp32Cam :
https://www.thingiverse.com/thing:3579507

…it was “just” the trigger that doesnt work because i put :
'{{ trigger.to_state.state | int }}'
and it must be :
"{{ trigger.to_state.state | int }}"
the log help to fix it…
@Drew.B :wink:

thanks for your attention and help @mr.sneezy and @Drew.B

1 Like

Thanks guys,

with a bit of tweaking I got it working!
Only thing is my servo keep on spinning now and it does not stop?

ESPCONFIG

esphome:
  name: petfeeder
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "Mistery"
  password: "YouWishYouKnew"

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
    - service: control_servo
      variables:
        level: float
      then:
        - servo.write:
            id: my_servo
            level: !lambda 'return level / 100.0;'
ota:

servo:
  - id: my_servo
    output: pwm_output

 # PinPwm configuration entry servo rotate
output:
  - platform: esp8266_pwm
    id: pwm_output
    pin: GPIO02
    frequency: 50 Hz

If it’s a standard RC type servo and the motor spins continuously it normally means a gear has stripped inside.

I have 2 servo motors mg995 model.
One is modified to spin continuously and one just the original one. As for both the keep on working as the modified one just spins 360 degrees the othee one does not but you can hear by the sound it makes it is trying to spin more then possible.

I note now you are using the servo component unlike me (I’m using a ESP32).
What you might need to do is reduce the percentage a bit and see if the servos behave properly. Try a minimum of 20% and a maximum of 80% and see how that goes. Some servos don’t like being driven to the theoretical limits for RC servos (1mS to 2mS).

Thanks! I got it spinning again. But still to control it does not work. All I want to do is to open and close is for a few seconds a day.

this is what i want to manage. :smiley: So hope anybody can help or give me some new idea’s to finalize this before my holidays :smiley:

I love the simplicity of your implementation.

Is there a way you can enter the PPM values? 0.5ms for 0°, 1.5ms for 90°, and 2.5ms for 180°.
Or if it’s a percentage input, try max 12.5%.

It spins faster but still unable to control it please any help?

Did you mod this servo with the 2x 2.2k resistors?

Is he using a non standard servo (i.e. not for RC models), as they typically use 1mS to 2mS for full 0-100% travel and can become unstable outside that.

Servo PWM diagram link

To get a MG995 to spin continuously, you need to mod it by removing the position feedback pot normally. So you use two resistors in place of the pot to replicate a partial rotational movement. As the servo’s feedback loop never reaches the PPM input position, it just keeps spinning endlessly until you input the centre position signal (or a signal inside the value of the resistor you used) It can be really difficult to stop a servo rotating accurately once it’s been modded.

Ah thanks, I see. Yes I can imagine that without adjusting for more dead band, it would be devilishly hard to get it to stop. To make the feeder device he linked though, why would it need to spin 360 continuous, it looks like that one used a normal travel range ?
(a rhetorical question no need to answer :slight_smile:

I agree with you, probs not necessary to do a full 360. Hopefully @Khalid_Abu_Hamza got it sorted?

Got a feather huzzah32 and an sg90 servo; all I get is buzzing and some grinding when I move the servo control (as outlined on the esphome website).
Power is bypassing the esp (from the same wall wart 2.5a)…

“Experiment with” the values for min_level and max_level, but all it seemed to do is change the pitch at which the servo squealed (occasionally moving a bit).

Got this to work on the nodeMCU, but I need a small micro controller, tried the esp32 pico and couldn’t get it to work either (same deal)… is this a limitation on some controllers?

Any help would be greatly appreciated!

``
servo:

  • id: my_servo
    output: cerveau

output:

  • platform: ledc
    pin: GPIO21
    id: cerveau
    frequency: 50 Hz
    min_power: 2.5% # 5% at 50Hz is 1mS (20mS cycles) was 5
    max_power: 9% # 10% at 50Hz is 2mS (20mS cycles) was 10
    ``

Without giving your issue too much thought, the ‘grinding’ you describe sounds like what an SG90 does when it’s got stripped teeth on the main gear or spur. Might pay to take the 4 screws out of the bottom case and carefully inspect the gears just below the top case…

Thanks for responding!
I thought the same so I tried all the servos in the batch I got, and they all behave the same…
…if they are seizing what am I doing wrong?

Thanks again

Well not sure now. Although setting servo pulse outside the 1mS to 2mS range could have unknown effects on some of them.
Here’s my code for the ESP32 project I made, if it helps. Not been updated for a year or so.


# Using Light component to set a standard RC servo position
light:
  - platform: monochromatic
    output: gpio_21_servo
    name: "Servo actuator #1 - Servo Pos"
    default_transition_length: 0ms

output:
  - platform: ledc
    pin: GPIO21
    id: gpio_21_servo
    frequency: 50 Hz
    min_power: 5.0%    # 5% at 50Hz is 1mS  (20mS cycles)
    max_power: 10.0%   # 10% at 50Hz is 2mS (20mS cycles)

A snip of the IF/THEN action block...
          then:
            - output.turn_on: yellow_led
#            - output.turn_on: esp32_blue_led
            - output.set_level:
                id: gpio_21_servo
                level: 100.0% # 100% = 2mS as set by 'max_power'
            - delay: 3000ms #700ms     
            - output.set_level:
                id: gpio_21_servo
                level: 0.0%  # 0% = 1mS as set by 'min_power'