Page 1 of 1

Esp32 Pico Mini

Posted: Sat Feb 22, 2025 12:27 pm
by bordacs
There are very few information available about Esp32 Pico Mini. I want to use it as it is the smallest one I guess.
But developing software for this, encounters problems.
Arduino IDE 2.x ot 1.8x.
Selected board is ESP32 DEV (there is no this pico mini)
The problem is, that I am unable to control regular pwm servos. No esp pin generates PWM signal. They work if I make high/low, but no pwm. Analogwrite works.
I tried almost all servo espservo library without success. I read that esp api changed from 2x to 3x and it caused some library stopped working. I changed api to 2x, but still no pwm signal on gpio.
What can be wrong?
Thanks for help.

Re: Esp32 Pico Mini

Posted: Sun Feb 23, 2025 6:50 pm
by lbernstone
I'd recommend you use the mcpwm driver included in esp-idf. It is far more powerful than any of the arduino servo libraries, and will be well documented with examples. This code uses the older (v4.4) driver, which is a bit easier to understand, but functions exactly the same for this purpose. I just tested it on a pico.

Code: Select all

#include <driver/mcpwm.h>

#define SERVO_MIN_PULSEWIDTH_US (1000) // Minimum pulse width in microsecond
#define SERVO_MAX_PULSEWIDTH_US (2000) // Maximum pulse width in microsecond
#define SERVO_MAX_DEGREE        (90)   // Maximum angle in degree upto which servo can rotate

#define SERVO_PULSE_GPIO        (21)   // GPIO connects to the PWM signal line

uint32_t convert_servo_angle_to_duty_us(int angle)
{
    return (angle + SERVO_MAX_DEGREE) * (SERVO_MAX_PULSEWIDTH_US - SERVO_MIN_PULSEWIDTH_US) / (2 * SERVO_MAX_DEGREE) + SERVO_MIN_PULSEWIDTH_US;
}

void setup() {
  Serial.begin(115200);
  mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, SERVO_PULSE_GPIO);

  mcpwm_config_t pwm_config;
  pwm_config.frequency = 50;
  pwm_config.cmpr_a = 0;
  pwm_config.counter_mode = MCPWM_UP_COUNTER;
  pwm_config.duty_mode = MCPWM_DUTY_MODE_0;

  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config);
}

void loop() {
  for (int angle = -SERVO_MAX_DEGREE; angle < SERVO_MAX_DEGREE; angle++) {
      Serial.printf("Angle of rotation: %d\n", angle);
      mcpwm_set_duty_in_us(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, convert_servo_angle_to_duty_us(angle));
      delay(100); //Add delay, since it takes time for servo to rotate, generally 100ms/60degree rotation under 5V power supply
  }
  delay(1000);
}

Re: Esp32 Pico Mini

Posted: Sun Feb 23, 2025 9:36 pm
by lbernstone
The ESP32Servo library appears to be working as well.
https://wokwi.com/projects/323706614646309460

Re: Esp32 Pico Mini

Posted: Mon Feb 24, 2025 8:08 am
by bordacs
I was experimenting and I found, servos work on other gpio, but not on GPIO0. Documents said that PWM output work on every gpio. They work but not on GPIO0. It is ESP32-PICI-MINI-02.
What is the reason, how to solve it?

Re: Esp32 Pico Mini

Posted: Tue Feb 25, 2025 5:01 am
by lbernstone
gpio0 has an internal pullup. It is the programming strapping pin. It is a poor choice for anything other than the button that is ALWAYS attached to it on a dev board. That said, the code above works fine for me with a servo attached on 0.

Re: Esp32 Pico Mini

Posted: Tue Feb 25, 2025 8:05 am
by bordacs
gpio0 has an internal pullup. It is the programming strapping pin. It is a poor choice for anything other than the button that is ALWAYS attached to it on a dev board. That said, the code above works fine for me with a servo attached on 0.
Yes, the servo works on other ports. But please try if servopin = 0
It is not a dev board, so the programming button is not there, only for programming.