nachtravevl / pca9685-arduino Goto Github PK
View Code? Open in Web Editor NEWThis project forked from vitska/pca9685-arduino-library
Arduino Library for the PCA9685 16-Channel PWM Driver Module.
License: GNU General Public License v3.0
This project forked from vitska/pca9685-arduino-library
Arduino Library for the PCA9685 16-Channel PWM Driver Module.
License: GNU General Public License v3.0
I am testing PCA9685 library with SoftwareI2C and I've encountered an issue during initializaiton - setPWMFrequency does not work.
It turned out that at the end of readRegister operation, the I2C does not issue STOP bit; since the next writeRegister issues start bit, the entire transaction (write into the MODE1, which enables setting the prescaler) is rejected and subsequently the prescaler value will be ignored.
The call _i2cWrite->requestFrom() defaults to sending STOP bit after last expected byte from I2C is read.
I'am using an ESP32 and want to use the setChannelsPWM to set 6 Servos at one I2C-write.
But the BatchingExample producing compile-errors:
no matching function for call to 'PCA9685::setChannelsPWM(int, int, word [12])'
and also other examples fail:
S:\arduino-1.8.10_ESP32\portable\sketchbook\libraries\PCA9685-Arduino\PCA9685.cpp:208:45: error: 'BUFFER_LENGTH' was not declared in this scope
int maxChannels = min(numChannels, (BUFFER_LENGTH - 1) / 4);
Any Idea ?
Edit:
By replacing "word pwms[12];" --> "uint16_t pwms[12];" in example the 1st error is gone :-)
Only the missing BUFFER_LENGTH remains in moment.
thanks for this great library! it works perfect.
I tested it the other day with an teensy 3.5 with the batching example, only thing i had to change is word to uint16_t in the frontpage as the compiler gave an error which I think had something to do with converting the 32 bit word down to 16 bit.
i checked the output with a logic analyzer, the pulsewidth and phaseshift seem the same compared to a regular arduino.
cheers, niels
Hi!
Is there a reason not to include a keywords.txt file in the library?
I've created my own to avoid typos (and because it looks nicer ;-) :
PCA9685 KEYWORD1
init KEYWORD2
initAsProxyAddresser KEYWORD2
enableAllCallAddress KEYWORD2
resetDevices KEYWORD2
setPWMFrequency KEYWORD2
setChannelPWM KEYWORD2
getChannelPWM KEYWORD2
setChannelsPWM KEYWORD2
printModuleInfo KEYWORD2
setChannelOff KEYWORD2
setPWMFreqServo KEYWORD2
getChannelPWM KEYWORD2
pwmForAngle KEYWORD2
But maybe "Methods and Functions" (KEYWORD2) or "Constants" (LITERAL1) are incomplete.
Regards.
Hello,
I'm struggling since few mounts with the linear speed servo response for the continuos rotation servos (360 deg), which I thought to work by design. Now I've switched to this library fork for my project based on the PowerHD LF-20MG digital continuous rotation servo.
I have few questions:
Thanks in advance for answers :) ,
Have a nice weekend, Kindest Regards,
Daniel
Hi, how i can control a continuos servo?
Hi,
First of all thank you for the great library! Everything worked perfectly in my project that uses serial input to control PWM. At some point I got fed up with the loop(); including a delay(10); to run around 100 times per second.
I then moved all of the code that executes at 100x per second to a Timer0 CMP interrupt function. This works great, until I execute any of your library calls like pwm.setChannelPWM(); INSIDE the interrupt.
The Arduino (UNO) seems to completely freeze at this point. I even built a flashing LED in loop(); to see if that would continue to run, but that also freezes. I am clueless as to what is happening; might the I2C implementation break something when called from an interrupt?
If I call upon your library from loop(); that works perfectly. But as soon as I execute from the interrupt; then the Arduino dies again and hard reset seems the only way out.
Do you have any idea what might be going on?
I'm trying to create a fade in/out effect with a LED strip and found an interesting "bug". It leads to a noticeable LED flickering when I change PWM duty value quite often (dozens of time per second). It seems to be related to default phase balancer method used in this library.
Here's a minimal code to notice the issue using oscilloscope:
PCA9685 pwmController;
void setup() {
Wire.begin();
Wire.setClock(400000);
pwmController.resetDevices();
pwmController.init(B000000);
pwmController.setPWMFrequency(1511);
pwmController.setChannelPWM(8, 2048);
}
void loop() {
pwmController.setChannelPWM(4, 2700);
delay(1000);
pwmController.setChannelPWM(4, 3300);
delay(2000);
}
Just to clarify what's going on here:
On the left side we observe previous settings of duty=3300, which (using default PCA9685_PhaseBalancer_Linear
) leads to phaseBegin: 1024, phaseEnd: 228
. I2C transfer in the middle changes this to duty=2700, which is phaseBegin: 1024, phaseEnd: 3724
for channel 4. However, PCA9685 does not apply all the changes on the next cycle. Instead it drops channel at desired time and keeps it off up to end of the cycle. Starting from next cycle it behaves normally.
As I mentioned above, when I change PWM duty frequently to achieve a fade effect – this leads to flickering.
As I discovered, this issue could be avoided by setting balancer to PCA9685_PhaseBalancer_None
, but I'd like to know if there's a way to keep phase balancing enabled and get rid of this issue at the same time.
An example does not compile - Arduino returns the error below:
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.
first of all thank you for your library, it helped me a lot in my smart home projects ;-) Now I'm doing servo controlled ventilation flaps for my house ventilation system. It would be nice to store last value, and then start with last stored value, to avoid unnecessary movement on system restart (f.e. nights in bedroom you can really hear the movements). Is this possible with your library to avoid any movements before first set of setChannelPWM()? Eventually initialize with predefined position?
Problem: I'm able to use your example code to blink the connected LED when using the hardwired I2C connection. However, I am unable to make the LED blink even when using the example code supplied with the library (SoftwareI2CExample).
Circuit setup: Standard setup using Arduino Nano with Adafruit PCA9685 breakout and 10k pull resistors.
Troubleshooting:
Thanks!
I’m C++ noob and taking my first steps with the Arduino (IDE 1.8.5).
I’m running into an error compiling the “SimpleExample” provided with the library version 1.2.10:
:\Users\Mein Name\Documents\Arduino\libraries\PCA9685-Arduino-master\PCA9685.cpp:600:0: error: unterminated #else
#ifdef PCA9685_ENABLE_SOFTWARE_I2C
^
C:\Users\Mein Name\Documents\Arduino\libraries\PCA9685-Arduino-master\PCA9685.cpp:588:0: error: unterminated #else
#ifdef PCA9685_ENABLE_SOFTWARE_I2C
^
C:\Users\Mein Name\Documents\Arduino\libraries\PCA9685-Arduino-master\PCA9685.cpp:264:0: error: unterminated #else
#ifdef PCA9685_ENABLE_SOFTWARE_I2C
^
C:\Users\Mein Name\Documents\Arduino\libraries\PCA9685-Arduino-master\PCA9685.cpp:222:0: error: unterminated #ifndef
#ifndef PCA9685_EXCLUDE_EXT_FUNC
^
exit status 1
Fehler beim Kompilieren für das Board Arduino/Genuino Uno.
Do you have an idea what I could be doing wrong? Counting the closing #endif (45) for the opening # ifdef (40) and ifndef (9) in PCA9685.cpp indicates a mismatch but I’ve just started learning so I don’t know if my counting is valid.
Thank You for publishing this library.
I am using it to connect to multiple PCA9685 devices and I pass your class object as reference to my own classes (to save on mem consumption).
Could You please consider adding method:
void PCA9685::setI2CAddress(byte i2cAddress) { _i2cAddress = i2cAddress;} ;
to allow changing address before each setChannelPWM method call or extend setChannelPWM with ic2Address parameter?
I've noticed there are forks of this library available in platformio, however none for esp8266.
Can you make it available in platformio ?
https://docs.platformio.org/en/latest/librarymanager/creating.html
Thanks
In PCA9685.cpp on line 645, you reference the variable name _readByes rather than _readBytes.
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.