servo-angle.ino

Arduino Portenta H7 · File : servo-angle.ino · Language : Arduino · Use case : Piloter un servo avec la bibliothèque Servo sur Portenta

The Mbed core Servo library generates the 50 Hz pulse in hardware on H7 timers. A full 0-180° sweep validates the chain before mounting it on a robot arm driven by RPC.

Hardware

An Arduino Portenta H7 (ST STM32H747 dual-core module Cortex-M7 @ 480 MHz + M4 @ 240 MHz, 8 MB SDRAM, high-density connector), powered by USB-C or 5 V. 1 hobby servo (SG90/MG90S) + external 5 V supply.

Wiring

Signal to D13 (see carrier schematic), + to external 5 V, common grounds. The board 5 V must not power several servos.

How it works

myservo.write(angle) converts the angle into a timer-managed pulse width; the sweep loop runs at 50 steps/s.

Running it

Arduino IDE with the « Arduino Mbed OS Portenta Boards » core: pick « Portenta H7 » (M7 core), the USB-C port, then Upload. The DFU mode M7/M4 selector also loads the M4 core.

Variants

Command the angle from the M4 or an X8 Linux, or chain a position sequence stored in flash.

servo-angle.ino

// Balayage servo sur D13 avec la lib Servo du core Mbed.
#include <Servo.h>

Servo myservo;
int angle = 0, sens = 1;
unsigned long t0 = 0;

void setup() {
  myservo.attach(13);
  myservo.write(0);
  Serial.begin(9600);
}

void loop() {
  if (millis() - t0 < 20) return;
  t0 = millis();

  myservo.write(angle);
  angle += sens;
  if (angle >= 180) sens = -1;
  if (angle <= 0) sens = 1;
}

// Le core Portenta implemente Servo sur les timers Mbed :
// la frequence du signal reste a 50 Hz quelle que soit la
// frequence du CPU (avantage sur un emulation par delay).

← Back to the board