Go Down

Topic: Fading LED using I2C and PCA9865 (Read 1 time) previous topic - next topic

matoex

Jul 09, 2016, 12:38 pm Last Edit: Jul 10, 2016, 10:21 am by matoex
Hi,
I' m new in i2c protocol. I have got PCA9685 (16-channel, 12-bit PWM Fm+ I2C-bus LED controller) and I would like to start using it, by for example fadind single LED.
I read something about i2c, but I still cannot write code for control led using this module.
My connections look like these:


When I use i2c-scanner I get:

Code: [Select]
I2C Scanner
Scanning...
I2C device found at address 0x40  !
I2C device found at address 0x70  ! done


How code to fading this LED can looks like?

PaulRB

#1
Jul 09, 2016, 03:34 pm Last Edit: Jul 09, 2016, 03:36 pm by PaulRB
Hi. Looks like you have an Adafruit module. Have you checked their website for example code and tutorials?

Also, do you have another i2c device attached? The scanner is finding two devices.

Paul

matoex

Now scanner is finding only one device (at address 0x40 ) and that's ok, earlier was my mistake.

Yes, my module is Adafruit PCA9685. I tried build some working code using tips from this thread: Interfacing with Adafruit I2C 16 Channel, 12 Bit, especially mentioned library but  something went wrong with "BasicLEDtest" example.

There's also tutorial about servos from adafruit: https://learn.adafruit.com/16-channel-pwm-servo-driver  but I am interested in LEDs.
My knowledge about i2c is not too big, but I would like to have some working code which is flashing LED and see how it works, later I will go depper in that..

Grumpy_Mike

#3
Jul 10, 2016, 12:19 am Last Edit: Jul 10, 2016, 12:22 am by Grumpy_Mike
You need a resistor in line with that LED.

Post what you have done so far use the code tabs icon </>

Wawa

The PCA9685 has more sink (25mA) than source (10 mA) capacity.
Maybe better to use your LED/resistor between VCC and PWM output.
Leo..

matoex

I used sketch "pwmtest" from Adafruit PCA9685 library with 0x40 adress and now LED is flashing. Moreover added resistor you were talking about.

Now I am trying to understand how it works and how control next diodes...

Grumpy_Mike

Did you also change the wiring to sink the current?

Quote
Now I am trying to understand how it works
You have two 16 bit counters. One defines when the LED is turned on, this can be set at zero, the other defines when it is turned off a value of 0 to 0xffff will control the brightness.

Wawa

I am currently using this library.
https://github.com/brunnels/PCA9685 (the 2012 version).
It changes 12-bit from the chip into 8-bit perceived brightness steps with a lookup table.
(Google "CIE lighting standards").
Some example code below to get you started.

The current version is a bit different.
I think you have to use  board_0.setChannel8bit(0, 255); and  board_0.setChannels8bit(0, 15, 255);
Not sure.  Look through the library files.
Leo..
Code: [Select]
#include <I2C.h> // might not be needed with newer version
#include <PCA9685.h> // 2012 version
PCA9685 board_0(0x5F); // I named the first board board_0 | I2C address is in the brackets
// PCA9685 board_1(0x5E); // second board, if used

void setup() {
  board_0.begin(); // starts the first board
  // board_1.begin(); // second board, if used
  board_0.setPWMFrequency(200); // boards default to 200hz PWM
  // board_1.setPWMFrequency(200);
}

void loop() {
  board_0.PWM(0, 15, 0); // turns all LEDs  (0-15) off
  board_0.PWM(0, 15, 255); // turns all LEDs on
  board_0.PWM(0, 3, 64); // sets the first four LEDs to 1/4 brightness
  board_0.PWM(7, 128); // sets LED 8 to 50% brightness
}

action_64


Grumpy_Mike

This library does not work
What libiary?
In what way does it not work? - Compile, produce any output or produce a wrong looking output.

You will have to up your game if you want to post successfully here, so first read How to use this forum

Wawa

#10
May 13, 2017, 11:05 pm Last Edit: May 13, 2017, 11:05 pm by Wawa
The Brunnels library has been updated at some stage with new commands.
The examples that come with the library have not been updated yet.
So they don't work with the newer library.
Some info here.
Post your code if you want detailed help.
Leo..


action_64

At start of check produces an error:

C:\Users\D395~1\AppData\Local\Temp\arduino_modified_sketch_163006\sketch_may17d.ino:1:60: fatal error: I2C.h: No such file or directory

 #include <I2C.h> // might not be needed with newer version

                                                            ^

compilation terminated.

exit status 1

Wawa

#12
May 17, 2017, 11:31 pm Last Edit: May 17, 2017, 11:32 pm by Wawa
I said I was using the old library and that the current version has different commands.
Did you look at the link in post#10.

The sketch in there compiles if... you install the two libraries and... edit the Wire/Wire.h to Wire.h in the PCA9685.h library.
Let us know if you have problems with any of those tasks.
Leo..

action_64

Tried to do as you wrote. I downloaded: https://github.com/rambo/I2C, https://github.com/brunnels/PCA9685. Now, when checking, another error occurs:
Arduino: 1.8.2 Hourly Build 2017/03/01 11:33 (Windows 10), Плата:"Arduino/Genuino Uno"

In file included from C:\Arduino\sketch_may18a\sketch_may18a.ino:2:0:

D:\Arduino\arduino-nightly\libraries\PCA9685/PCA9685.h:12:23: fatal error: Wire/Wire.h: No such file or directory

#include <Wire/Wire.h>

                     ^

compilation terminated.

exit status 1

How to solve this problem? Thank you very much for your help!!!!!

Wawa

#14
May 18, 2017, 01:28 pm Last Edit: May 18, 2017, 01:32 pm by Wawa
Did you edit the PCA9685.h library file, as explained in the other thread?
I use Notepad++ for that.

I have attached the edited file for your convenience.
Replace the existing PCA9685.h file with this one.

My installed library files are kept in Libraries>Documents>Arduino>sketchbook>libraries>  PCA9685-master
Your library files might be in a different place.
Leo..

Go Up