henriheimann / stm32-hal-pca9685 Goto Github PK
View Code? Open in Web Editor NEWDriver for the PCA9685 12-bit PWM driver using STM32Cube HAL
Driver for the PCA9685 12-bit PWM driver using STM32Cube HAL
My objective was to use this library to control SG90-TowerPro servo motors using a PCA9685.
When analysing the voltage on the pwm cable of the servo, I find fixed 0.033V where I should find a changing value orbiting around 0.3V.
Using a single SG90-TowerPro servo motor connected to the port 0 of the PCA9685. Using CubeMX and CubeIDE to code. No compiling error and everything seem to work according to the debugger. Coding on an STM32F303K8 nucleo board. Having the files correctly imported. Servo documentation: https://cdn.datasheetspdf.com/pdf-down/S/G/9/SG90-TowerPro.pdf
Replaced
#if (defined STM32L011xx) || (defined STM32L021xx) || \
(defined STM32L031xx) || (defined STM32L041xx) || \
(defined STM32L051xx) || (defined STM32L052xx) || (defined STM32L053xx) || \
(defined STM32L061xx) || (defined STM32L062xx) || (defined STM32L063xx) || \
(defined STM32L071xx) || (defined STM32L072xx) || (defined STM32L073xx) || \
(defined STM32L081xx) || (defined STM32L082xx) || (defined STM32L083xx)
#include "stm32l0xx_hal.h"
#elif defined (STM32L412xx) || defined (STM32L422xx) || \
defined (STM32L431xx) || (defined STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
defined (STM32L496xx) || defined (STM32L4A6xx) || \
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
#include "stm32l4xx_hal.h"
#else
#error Platform not implemented
#endif
with
#include "stm32f3xx_hal.h"
#include "pca9685.h"
#define SERVO_COUNT 1
uint8_t ActiveServo;
pca9685_handle_t handle = {
.i2c_handle = &hi2c1,
.device_address = PCA9865_I2C_DEFAULT_DEVICE_ADDRESS,
.inverted = false
};
pca9685_init(&handle);
pca9685_set_pwm_frequency(&handle, 50.0f);
HAL_Delay(2000);
pca9685_set_channel_duty_cycle(&handle, 1, 0.09f, false);
HAL_Delay(1000);
pca9685_set_channel_duty_cycle(&handle, 1, 0.06f, false);
HAL_Delay(1000);
According to the documentation, it should be on between 1 and 2 ms on a 20 ms pwm period (wich is 5 to 10% equivalent to 0.05 to 0.1) working at 50 hertz.
Made it work with an arduino nano
Made it (kinda) work with another library (just some vibrations problems to fix)
Watched very carefully the sleeping status of the PCA (did not sleep at all)
All of this had led me to think maybe the problem was not on my part but I certainly can be wrong as you seem far more knowledgeable than me.
Hoping for this issue to be helping,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.