min and max pulse widths for machine.PWM?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
ghukill
Posts: 4
Joined: Sun Feb 28, 2021 11:56 am

min and max pulse widths for machine.PWM?

Post by ghukill » Tue Jun 15, 2021 9:52 am

I'm trying to port some Arduino code to micropython that drives a brushless motor using an ESC module. Using an esp8266mod board.

The arduino code sets up the pin that writes to ESC like this:

Code: Select all

#include <Servo.h>
...
ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds) 
Then writes like this:

Code: Select all

potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)    
Use a 10k pot, I can twist from full open to full close, and power the motor. But with micropython, I'm seeing a much more delicate range, which leads to problems calibrating.

I've got some micropython code that gets me very close, but I'm feeling like those "min pulse width" and "max pulse width" parameters in the Arduino code help smoothing things out.

I'm setting up the pin this way in Micropython:

Code: Select all

p = machine.Pin(14)
pwm_p = machine.PWM(machine.Pin(14), freq=500, duty=0)
Apologies for burying the lead, but am I missing something fundamental about the machine.PWM (https://docs.micropython.org/en/latest/ ... e.PWM.html) class that might allow these kind of min/max values?

ghukill
Posts: 4
Joined: Sun Feb 28, 2021 11:56 am

Re: min and max pulse widths for machine.PWM?

Post by ghukill » Tue Jun 15, 2021 11:01 am

Stumbled on this forum post that may have some details/approaches that could be helpful:
viewtopic.php?f=2&t=10494&p=57979&hilit ... tio#p57980

ghukill
Posts: 4
Joined: Sun Feb 28, 2021 11:56 am

Re: min and max pulse widths for machine.PWM?

Post by ghukill » Wed Jun 16, 2021 7:12 am

This post also has some helpful / relevant information:
viewtopic.php?t=1920

Post Reply