Go Down

Topic: Arduino Portenta H7 Servo  (Read 471 times) previous topic - next topic

SpaseRe

 Hello guys,

I recently bought a Protenta h7 to use it as a brain in my "self-driving" quadcopter. I had tried something similar with a Mega board, but was lacking processing power.

The problem is that I can't use the Servo.h library, because it is not yet supported for that board. (I need the Servo library to send the desired pulse to ESCs.)

ESCs get a standard 50Hz PWM pulse.
Code: [Select]

#include <Servo.h>
Servo servo;     // create servo object

void setup() {
    // Attach the ESC on my pin
    servo.attach(A0,1000,2000); // (pin, min pulse width, max pulse width in microseconds)
}
void loop() {
 
    servo.write(1200);    // Send PWM to ESC
}



The above code would set the motor to 20% speed.

Anything to suggest?
If not, any idea whether and when they add it to supported boards?

Thanks!

sbhklr

Hi SpaseRe! Thanks for pointing this out. It's definitely something we want to support asap. Let me investigate the timeframe for this. I'll keep you posted.

sbhklr

Hi SpaseRe!

I had a look at the Servo library and it seems that there was a small bug that prevented the library from compiling for Portenta. I've submitted a fix which we'll merge once reviewed. You can check the PR here:
https://github.com/arduino-libraries/Servo/pull/60

jerteach

Hi SpaseRe!

I had a look at the Servo library and it seems that there was a small bug that prevented the library from compiling for Portenta. I've submitted a fix which we'll merge once reviewed. You can check the PR here:
https://github.com/arduino-libraries/Servo/pull/60
Any word on if this fix is working. I have Servo.h version 1.1.6 and I am still getting compile errors. Even if I use the Servo.h file found at

https://github.com/arduino-libraries/Servo/blob/master/src/Servo.h


pert

The necessary change is in src/mbed/Servo.cpp:
https://github.com/arduino-libraries/Servo/pull/60/files
You only need to add an #include directive for mbed.h.

Have you done that @jerteach? If so, please post the full error output. If you haven't done it, and want more detailed instructions, I'm happy to provide them.

jerteach

Pert, that was the issue. Until the library is updated you only have to change that one line of code. Strangely hard on windows because the directory was locked. Had to load notepad in administrator mode. The file was at


C:\Program Files (x86)\Arduino\libraries\Servo\src\mbed\Servo.cpp

and I just needed to add this line after the other #includes in the file:


Code: [Select]
#include <mbed.h>


I have listed my running Servo code on my Portenta Github site at   https://github.com/hpssjellis/my-examples-for-the-arduino-portentaH7/blob/master/my11-servo.ino



Go Up