In the past I build several Raspberry Pi robots with a L298N Dual H-Bridge. With the L298N motor driver the Raspberry Pi is able to control the spinning direction and speed independently of two DC motors. But the problem for the Raspberry Pi is the generation of a clear PWM signal. From time to time I see the motors not spinning correct because of the software generated PWM signal by the Raspberry Pi. To generate a clear and constant PWM signal I decided to buy the cheap Adafruit PCA9685 servo controller board. With this board it is easy to generate a PWM signal for up to 16 servos.

The idea was to use a L298N H-Bridge connected to the PCA9685 board instead of a servo and to control the speed of two DC motors with the PWM signal generated by the PCA9685 servo controller.

The picture below shows the setup with a L298N H-Bridge, a Step-Down converter, the servo controller, an I2C level-shifter, a Raspberry Pi 3 Model B and two DC motors.

L298N H-Bridge with a PCA9685 overview

L298N H-Bridge with a PCA9685 overview

List of components

This is the list of components I used for my setup.

  • PCA9685
Adafruit 16-Kanal 12-Bit PWM/Servo-Treiber - I2C-Schnittstelle - PCA9685
Preis: EUR 19,89
1 neu von EUR 19,890 gebraucht
Sie möchten einem coolen Roboter vielleicht ein hexapod Walker, oder vielleicht auch nur ein Kunstwerk mit vielen beweglichen Teilen. Oder vielleicht wollen Sie fahren viele LEDs mit präzise PWM-Ausgang. Dann erkennt man, dass Ihre Mikrocontroller eine begrenzte Anzahl von PWM Ausgänge hat! Was nun? Sie könnte aufgeben oder bekommst du nur diese handliche PWM und Servo-Treiber-Ausbruch.
Als wir sahen, dass dieser Chip, erkannten wir schnell was ein ausgezeichnetes Add-on dies wäre. Mit nur zwei Pins, Steuern Sie 16 freilaufenden PWM Ausgänge! You can even chain up 62 breakouts to control up to 992 PWM outputs (which we would really like to see since it would be glorious)
Es handelt sich um eine i2c-gesteuerte PWM-Treiber mit einer eingebauten Uhr. Dass bedeutet, dass im Gegensatz zu der Familie der TLC5940 Sie nicht benötigen ständig senden binden Ihre Mikrocontroller, die völlig frei laufen Signal!
Es ist 5V konform, das heißt, Sie können steuern, wie es von einem 3,3V Microcontroller und noch sicher fahren bis 6V Ausgänge (das ist gut für wann Sie steuern weiß möchten oder blaue LEDs mit 3.4 + weiterleiten Spannungen)
6-Adresse wählen Sie Stifte, damit können Sie bis zu 62 davon bei einem einzigen i2c-Bus insgesamt 992 Ausgänge - Draht, die ist eine Menge von Servos oder LEDs
Einstellbare Frequenz bis zu ca. 1,6 KHz PWM
Auflösung von 12 Bit für jeden Ausgang - für Servos, das heißt über 4us Auflösung bei 60Hz Aktualisierungsrate
Konfigurierbare Push-Pull- oder Open-Drain Ausgang
Ausgang aktivieren Pin zu schnell deaktivieren alle tEr gibt
Wir dieser schönen Chip in einem Breakout-Board mit ein paar netten Extras eingewickelt
Anschlussblock für Power-Eingang (oder die 0,1" Ausbrüche können Sie auf der Seite)
Verpolungsschutz am Eingang terminal block
Grüne Energie-gut-LED
3-Pin-Anschlüsse in Gruppen von 4, so dass Sie auf einmal 16 Servos anschließen können (Servo Stecker sind leicht
  • Step-Down converter
SMAKN® DC 7V-24V To DC 5V 3A USB Output Converter Step Down Module KIS-3R33S
Price: $7.99
1 new from $7.990 used
This 5V USB output converter module is based on the KIS3R33S module specific design- the input voltage 7V to 24V- output voltage 5V 2.5A peak output current of 4A continuous output. Able to provide 3A continuous load current. The majority of players professional testing- with high efficiency- ultra-low loss characteristics- beyond perfect lm2596 power module. This module has a USB recognition. This module uses the original Sanyo low ESR filter capacitor voltage as low as possible so that the ripple 30mV- fully capable and linear power comparable. IN-(input negative)- IN + (positive input)- OUT-(negative output)- OUT + (positive output) must be connected to the right- otherwise may cause damage to the module. The USB output converter module has short circuit protection- 5A current automatic protection. Specification: Modules nature: non-isolated buck Rectification: non-synchronous rectification Input voltage: DC 7V - 24V Output voltage: DC 5V Output current: 4A(short time) Conversion efficiency: 96% (MAX) Switching frequency: 340KHz Output ripple: 30mV(max) Load regulation: ± 0.5% Voltage regulation: ± 2.5% Operating temperature: -40°C to +85°C With overcurrent protection Size: 60 x 21 x 14mm Notice: DIY mobile power supply- to achieve 5V output for charging Phone- MP3- MP4- PSP etc. Please connect right as the printed: IN-- IN+- OUT-- OUT+- or the Module will be burned May not charge for the IPAD Package included: 1 x KIS3R33S USB output converter module
  • L298N H-Bridge
SODIAL(R) L298N Dual H Bridge Motor Driver Controller Board Module
Price: $3.76
3 new from $3.760 used
* SODIAL is a registered trademark. ONLY Authorized seller of SODIAL can sell under SODIAL listings.Our products will enhance your experience to unparalleled inspiration.
SODIAL(R) L298N Dual H Bridge Motor Driver Controller Board Module.
The Dual H-Bridge Motor Driver module Board, using ST's L298N chip can directly drive two 3-30V DC motor, and provides a 5V output interface can 5V single-chip circuitry to supply, support 3.3VMCU control, you can easily control the DC motor speed and direction, you can also control the 2-phase stepper motor, smart car essential.
Driver: L298N Dual H Bridge DC Motor Driver IC
Drive Terminal Power Supply: +5 V ~ +35 V;
(if others need to be powered by the board, power supply should be +7V~+35V)
Drive Part of the Peak Current: 2A
Logic Terminal Power Supply: +5 V ~ +7 V (Power supply within the board: +5 V)
Logic Part of the Operating Current: 0 ~ 36mA
Control Signal Input Voltage Range: Low:-0.3V;
High: 2.3V
Enable Signal Input Voltage Range: Low: -0.3;
High: 2.3V
Storage Temperature: -25 ~ +130 deg C
Other Extensions: Control indicators, logic unit power supply interface
Size(L x W x H): 55 x 60 x 30mm
Package Includes: 1 x L298N Stepper Motor Driver Controller Board Module
Waring:
Because of the fin size, in the high voltage, high current usage, please use the means of forced cooling
Power is limited by the 78M05, if the driver is more than 15V motor, please use the external 5V power supply.
  • I2C level shifter
ADAFRUIT INDUSTRIES 757 LOGIC LEVEL CONVERTER, 4CH, ARM DEVELOPMENT BOARD (1 piece)
Price: $7.33
10 new from $6.990 used
ADAFRUIT INDUSTRIES 757 LOGIC LEVEL CONVERTER, 4CH, ARM DEVELOPMENT BOARD
  • Raspberry Pi 3 Model B
Vilros Raspberry Pi 3 Complete Starter Kit---Enthalt: Raspberry Pi 3 Model B (1GB) + 5 Wesentlich Zubehör
Preis: EUR 69,99
1 neu von EUR 69,990 gebraucht
Get Your First Taste Of raspberry Pi with this Complete Starter Kit from Vilros.

This Is the Raspberry Pi 3 Model B Complete Starter Kit From Vilros
It includes the new Raspberry Pi 3 Model B (Latest Version Released on 02/29/2016)

Raspberry Pi 3 Model B Technical Specifications:
• Broadcom BCM2837 64bit ARMv8 Quad Core Processor powered SingleBoard Computer running at 1.2GHz
• 1GB RAM
• BCM43143 WiFi on board
• Bluetooth Low Energy (BLE) on board
• 40pin extended GPIO
• 4 x USB2 ports
• 4 pole Stereo output and Composite video port
• Full size HDMI
• CSI camera port for connecting the Raspberry Pi camera
• DSI display port for connecting the Raspberry Pi touch screen display
• MicroSD port for loading your operating system and storing data
• Upgraded switched Micro USB power source (now supports up to 2.4 Amps)

Kit Content:
Raspberry Pi 3 Model B
Raspberry Pi Enclosure Case (Clear)
16GB Sandisk class 10 Micro Sd Card Preloaed with NOOBS
SD card Adapter
2500 mA EU Micro USB Power Supply -- 5-Feet Long
High Quality HDMI Cable
Heatsink for Raspberry Pi - Set of 2 Heat Sink


NOTE: The Micro SD card may appear as to be of smaller capacity when inserted into a PC as it is pre-partitioned, If formatted it will then show the full capacity which can be expanded as desired.

WEEE-Reg.-Nr. DE 29056374
  • Two DC motors
DC 12V 120RPM Micro Getriebe Motor Geschwindigkeitsreduzierung Antriebswelle
Preis: EUR 11,65
1 neu von EUR 11,650 gebraucht
Beschreibung:
Kompakte DC Getriebe Box Motor Kombination mit 37mm Durchmesser Getriebe und hat 2 Terminals Anschlüsse.
Leerlaufdrehzahl: 120 u/min; Aktuell: 0,15A.
Leerlaufdrehzahl: 84u/min; Aktuell: 0,7A.
D förmige Welle mit 6mm Durchmesser, 15mm lang.
Kleine Größe DC Getriebe Motor mit niedriger Drehzahl, geringe Geräuschentwicklung und hohes Drehmoment.
Dieser Motor ist solide gebaut.
Guter Ersatz für die rostigen oder beschädigte DC Motor auf der Maschine.
Typische Anwendungen: Vending Ausrüstungen, Kamera, Spielautomat, Detektor, Münze Rückerstattung Geräte, automatische Türen, peritoneal Maschine usw. Spielzeug motor schwenken.
L
25mm
  • Female to female jumper
2x 40pcs Female to Female 2.54mm 0.1 in Jumper Wires F/F (2x40pcs)
Price: $5.99
7 new from $3.270 used
Description: 40pcs chromatic color female to female dupont lines 100% brand new . High quality and in good working condition .
Durable and reusable Easy to install and use A popular choice for construction or repair Be used for electronic project and Genuine Arduino product.
Specification: Length 20cm 1p-1p pin female to female header Compatible with 2.54mm spacing pin headers
Package includes: 2 x A row of 40pcs female to female dupont line
  • Wires
20ga 25' Red/Black Hookup Wire 12V DC
Price: $8.90
You save: $0.09 (1 %)
4 new from $5.460 used
Roadpro RPCBH-25 25' Hardwire Replacement 2 Wire Cb Power Cord

Software PCA9685 Adafruit library

All the programs you need to control the DC motors are written in Python. First you need to activate the I2C Bus on your Raspberry Pi and to install the Adafruit PCA9685 library.

Adafruit PCA9685 library

To install the Adafruit library for the servo controller visit the GitHub page from Adafruit or just execute the following commands each after the other in the terminal window on your Raspberry Pi. 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 is optional instead of the four commands before.

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.

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

Now you could download the two Python programs I developed to control two DC motors with a L298N H-Bridge and a PCA9685 servo controller.

With the “RobotControlPCA9685.py” program you control the speed and spinning direction of the two DC motors via your keyboard. Start the program in the terminal window.

Download: Robot Control PCA9685 Python program

The Python module “L298NHBridgePCA9685.py“encapsulate the logic to speak with the Adafruit servo controller and with the L298N H-Bridge. This module is imported by the “RobotControlPCA9685.py” program.

Download: L298N H-Bridge PCA9685 Python module

The software is available on GitHub too: https://github.com/custom-build-robots

The next picture shows the setup from another perspective.

L298N H-Bridge with a PCA9685 wiring

L298N H-Bridge with a PCA9685 wiring

Video

The video shows the two DC motors spinning.

Summary

This setup works perfect for complex robots like my Big Rob robot I build. With the PWM signal generated by the PCA9685 servo controller I am now able to control the speed of DC motors with an H-Bridge very accurate. The setup I build is very cheap compared to motor drivers which have an I2C interface on board.

(Visited 438 times, 3 visits today)