GithubHelp home page GithubHelp logo

nachtravevl / pca9685-arduino Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vitska/pca9685-arduino-library

86.0 86.0 32.0 782 KB

Arduino Library for the PCA9685 16-Channel PWM Driver Module.

License: GNU General Public License v3.0

C++ 100.00%

pca9685-arduino's People

Contributors

dominikauras avatar jamesmyatt avatar kasperskaarhoj avatar nachtravevl avatar rubienr avatar vitska avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pca9685-arduino's Issues

The readRegister operation obscures next write with SoftwareI2C

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.

Examples won't compile on ESP32 ?

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.

confirmed for teensy 3.x

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

[Minor improvement] Adding keywords.txt to library

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.

Linear speed servo response

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:

  1. Is it possible to "model" somehow linear servo speed response with the Servo Evaluator?
  2. With limitting Servo MIN/MAX ticks range is it good approach to somehow fit in in such linear part of the Servo response characteristic?
  3. What is the best approach to achieve linear speed response for servos, which doesn't have this feature implemented?

Thanks in advance for answers :) ,
Have a nice weekend, Kindest Regards,
Daniel

[Improvement] Make setChannelsPWM work inside Timer0 CMP interrupt.

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?

[Feature Request] Dynamic phase balancer to remove LED flickering/channel update hiccup

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);
}

PCA9685-phasing-issue

Just to clarify what's going on here:

  • Yellow line represents the issue on channel 4
  • Cyan line is channel 8 and it shows internal cycle of PCA9685 (fall at 0, rise at 2048)
  • White vertical line is aligned with start of cycle
  • Violet&blue lines represent I2C communications

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.

Does not compile at328p on arduino 1.8.8

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.

Start with predefined servo position - for example stored in eeprom

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?

[Bug] Software I2C example not working

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:

  • I've ensured that all connections and designated pins for the software I2C are correct, and that the LED is functioning correctly.
  • Using the hardwired I2C example (SimpleExample), the LED operates as expected.
  • I have checked under an oscilloscope that the designated Software I2C pins are outputting signals, but the PCA9685 chip is not responding.
  • The #define PCA9685_ENABLE_SOFTWARE_I2C is uncommented, as instructed.
  • I've enabled #define PCA9685_ENABLE_DEBUG_OUTPUT and also used the printModuleInfo() function. I found that under hardwired I2C mode, the Mode1 Register returns 0x20, meaning that only PCA9685_MODE1_AUTOINC is enabled. However, under Software I2C mode, the Mode1 Register returns 0xFF (indeed all Registers return 0xFF), meaning all bits are enabled. This includes bit 4 for SLEEP MODE.
  • Using printModuleInfo() before initialisation in hardwired I2C shows NACK error in the Module Info output, which I think is expected as the printModuleInfo() was called before the initialisation. However in software I2C mode shows the same outputs as before, with 0xFF on all bits in all registers.

Thanks!

unterminated #ifndef - PCA9685.cpp

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.

[Improvement] Add I2C set address method

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?

Mistyped variable name

In PCA9685.cpp on line 645, you reference the variable name _readByes rather than _readBytes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.