Buchempfehlung:
Roboter-Autos mit dem Raspberry Pi

Roboter Autos mit dem Raspberry Pi

I build several Raspberry Pi robots over the last years. All of them are using a L298N H-Bridge as motor controller. To generate a perfect PWM signal for the motor controller I decided to generate the PWM signal outside the Raspberry Pi. With a special controller which only generates the PWM signal. With such a controller I will get an extremely accurate signal then the Raspberry Pi could generate it. The best solution would be a chip on a board with an I2C bus. I searched for such a solution and found a servo controller board with a PCA9685 chip. The PCA9685 chip is perfect for this kind of LED dimmer job. Besides controlling the speed of DC motors with a L298N H-Bridge my setup should be able to set the brightness of a LED strip as well.

I connected a short LED strip to the out connector of the L298N H-Bridge. It is a 12V LED strip with white LEDs. It is not an RGB LED strip.

The picture below shows my setup with a PCA9685 servo controller and a L298N H-Bridge as LED driver.

Raspberry Pi - LED dimmer

Raspberry Pi – LED dimmer

The picture below shows the LED dimmer active. The Python program I developed is available for free in the download section.

Raspberry Pi - LED dimmer active

Raspberry Pi – LED dimmer active

List of Components:

Raspberry Pi 3 Model B

Loading ...

I2C Level Converter from Adafruit

Loading ...

L298N H-Bridge as motor driver or LED driver

Loading ...

PCA9685 servo Controller

Loading ...

Software PCA9685

First you need to install the Adafruit library to control the PCA9685 servo controller. This servo controller will generate the PWM signal to dim the LED strip.

Adafruit PCA9685 library

To install the Adafruit library for the servo controller you have to execute some commands in the terminal window. For more details visit the GitHub page from Adafruit or just execute the following commands each after the other. I was connected via SSH with a terminal window on my Raspberry Pi for the installation process. I used for my setup the Raspbian Jessie.

Adafruit GitHub URL: https://github.com/adafruit/Adafruit_Python_PCA9685

Commands to install the Adafruit PCA9685 library:

Command: sudo apt-get install git build-essential python-dev

Command: cd ~

Command: git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git

Command: cd Adafruit_Python_PCA9685

The next command has to be executed in the “Adafruit_Python_PCA9685” folder.

Command: sudo python setup.py install

After installing the library and wiring everything up you could check if the servo controller is available on the I2C bus. Execute the following command and you should see the PCA9685 servo controller with the address 40 or a different address.

Command: sudo i2cdetect -y 1

Now you schould see the servo controller with the address 40 on your I2C bus.

i2c detect bus result

i2c detect bus result

I wrote a small Python program to control the brightness of the LED strip with a PCA9685 and a L298N H-Bridge as LED driver.

Download: Raspberry Pi – LED dimmer

Fritzing Layout

This overview helps you to connect all the wires correctly.

LED dimmer layout

LED dimmer layout

Video:

The video shows a short LED strip which is connected to the L298N H-Bridge. The PCA9685 generates the PWM signal and controls the H-Bridge.

(Visited 1,470 times, 1 visits today)