Hi,
I’m not sure why exactly but whenever I try to use some basic libraries from the arduino framework they never are supported. I’m using an bluepill_f103c8 with STM32duino (or atleast I think that what it’s using)
This is my configuration:
I always get an compile error:
.pio\libdeps\bluepill_f103c8\Servo\src/Servo.h:77:2: error: #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."
Which is weird, because when I copy&paste my code to the Arduino IDE it compiles without any problem for that board. I’m only trying to use the <Servo.h> library.
My current guess is that STM32Duino isn’t really targeted due to a misconfiguration, though in another thread the addition of board_build.core fixed the issue which sadly didn’t help on my end.
I suspect you have been misled by the Arduino IDE when it comes to libraries. When you “add library” there, all that happens is a #include is added to your code.
At the build stage, the IDE works out which libraries you asked for,compiles them from source, and links them with your sketch to create the executable.
In PlatformIO you need to add the library using the home page, or – my preferred method – using lib_deps in platformio.ini.
If the library is built in, as Servo should be:
lib_deps = servo
Should do the necessary. If the library is not built in, search for it on the home page or on PlatformIO Registry where you will be able to specify the name and platform to get suitable results.
Pick one, click the examples, installation and headers tabs for instructions and examples.
Well yeah I tried that out, but it still picks the “wrong” servo library
All servo libraries that are in the registry either don’t work or also show the same compability issue (even if they show compability to my plattform ).
I’m not exactly sure where the Arduino IDE + STM32Duino picks out their servo library but whatever the stm32duino version/implementation in PlattformIO does it’s not compatible at all to all other libraries. (even normal arduino ones that don’t use any hardware specific features.)
#include "Arduino.h"
#include <Servo.h>
Servo myservo;
#define POT_PIN 0
void setup()
{
myservo.attach(9);
}
void loop()
{
int val = analogRead(POT_PIN); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
the LDF will pick up the internal library automatically since it sees #include<Servo.h> in the main file.
(verbose build output)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Servo> 1.1.2 (C:\Users\Max\.platformio\packages\framework-arduinoststm32\libraries\Servo)
Building in release mode
I’d suggest to reproduce my config and remove the .pio folder of the project completely and rebuild.
You’ve globally installed the general Arduino (AVR etc…) version of the Servo library. This will overshadow the correct Servo library from the framework.
To fix the error, please remove the Servo library from the global storage. Removing the folder C:\Users\Soland\.platformio\lib\Servo should suffice.
This is why global library dependencies are dangerous – I’d promote strict per-project library management per lib_deps without global libraries because of this.
I can’t even remember on which project I did that and how many years ago that was.
Yeah I did that in the beginning, I’m always using the per-project settings on current projects to avoid this problem .
From version 5.x.x of PlatformIO, global libraries went away – for this reason! Plus, library names got a “vendor” part to distinguish between libraries with thd same name.
Yeah i used global libraries back then because adding it to a specific project wasn’t automatic and a bit cumbersome. Though back then it was mostly with small projects.
It’s adding everything automatically now which is amazing (I mean like the lib_deps stuff)