@jimw Please try this code.
Serial speed 115200
and the firmware (1.2.3-en) for micropython
It is not for Arduino.
#include <M5Stack.h>
int servoPin = 5;
void servoSet(int Angle, int Time) {
int pulseWidth;
int TimeCount;
TimeCount = Time / 20;
for (int i = 0; i <= TimeCount; i++) {
pulseWidth = map(Angle, 0, 180, 544, 2400);
digitalWrite(servoPin, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(servoPin, LOW);
delayMicroseconds(20000 - pulseWidth);
}
}
void setup() {
M5.begin();
M5.Lcd.printf("M5Stack Servo test:\n");
pinMode(servoPin, OUTPUT);
}
void loop() {
M5.Lcd.printf("Angle 45deg\n");
Serial.println("Angle 45deg");
servoSet(45, 1000); //45deg
M5.Lcd.printf("Angle 135deg\n");
Serial.println("Angle 135deg");
servoSet(135, 1000); //135deg
}