min and max pulse widths for machine.PWM?
Posted: 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:
Then writes like this:
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:
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?
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)
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)
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)