Chapter 4 – wiring:
This chapter is about the wiring of all electronic components inside the Raspberry PI RC car. The focus of this chapter is to connect the L298 H-Bridge with the Raspberry Pi. To wire everything together the best way is to use female to female jumpers. This type of wire works best, save without loos contacts and easy. To power up the Raspberry Pi we need an USB plug with a micro USB connector. To supply the motor driver we need a 6V to 9V charger with 2A. Maybe you can use an old smartphone charger with 5V and 1 A. This would be good enough for the first tests.
From my experience the 5V out from the L298 H-Bridge is not stable enough to supply the Raspberry Pi with energy. The variations are to strong and in my case the Raspberry Pi always crashed while switching on the four motors.
Components you need:
- Wire – Female to Female Jumper
- 1 x charger 6V to 9V with 2 A for the motor driver
- 1 x charger 5V micro USB for the Raspberry Pi
- a small screwdriver
- soldering iron
Raspberry Pi GPIO connectors
It is important to note the following points and to wire everything very carefully together not to burn the Raspberry Pi.
Hint 1: The Raspberry Pi is a 3.3V Linux computer. You should not use higher voltages then 3.3V on the GPIO pins.
Hint 2: The GPIO connectors are not buffered and not secured against wrong wiring. If you make a mistake and connect a wire wrong the Raspberry Pi will never forgive this failure. Take care not to fry the little computer with a short circuit.
Hint 3: There are differences in the assignment of the GPIO ports between the version A, B and B+ of the Raspberry Pi. For this HowTo papers I am using the Raspberry Pi B with 512 MB RAM. To wire everything correct it is important to know the differences in the versions which are available. For each version a GPIO diagram is available in the internet.
Logical wiring of the L298 H-Bridge:
This section is about the wiring of the L298 H-Bridge. We need 8 GPIO pins from the Raspberry Pi to connect the L298 H-Bridge to head on the two motors ( 2 x 2 motors parallel in this case = 4 motors are connected). We need 4 pins to supply the L298 H-Bridge with the PWM signal to control the speed of the motors. Further 4 pins are needed to set the spinning direction of the motors (forward / backwards).
PWM stands for Pulse width modulation. The Pulse width modulation is our control element to control the speed of the motors.
The next picture shows the final wiring of the Raspberry PI with the L298 H-Bridge.
The next picture shows how I connected my motors and how I will control (speed / direction) them in future. I used the jumper names printed on the L298 H-Bridge to explain everything.
L298 H-Bridge PWM assignment
For the PWM signal please use the pins ENA and ENB which are in line with the pins IN1 to IN4.
- Motor 1
- Motor 2
L298 H-Bridge direction assignment
- Moto 1
- Motor 2
It is important to connect the for example the ground pin 6 from the Raspberry Pi with the ground from the L298 H-Bridge. On the L298 H-Bridge you can use the 5V – connector. This is important to ensure that the L298 H-Bridge knows what a high signal is and what a low signal is. If you do not connect the ground from the Raspberry Pi with the ground from the L298 H-Bridge normally nothing will happen.
The picture is a little bit different to the actual wiring. The Raspberry Pi is no longer powered over the L298 H-Bridge. The 5V out from the L298 H-Bridge was not stable enough to power the RaPi. I bougth a PowerBank for the Raspberry Pi. This is the reason why the picture is not correct in the upper left corner.
The next picture shows how to wire the Raspberry Pi and the L298H Bridge.
If the L298N H-Bridge is connected with the Raspberry Pi now the motors will be connected to the L298N motor driver itselfe.
Shopping list of the components:
The following link will open the shopping list of the components I used for my Raspberry Pi car: component list
First I connected the Raspberry Pi with the 5V power supply to check if the PI works correct. Next I connected all wires as shown in the picture above.
It does not matter how you connect the ENA1 + ENA2 as well the ENB1 + ENB2 pins with the L298H Bridge. It is only important the ENA and ENB is connected as pairs. These pins are used for the PWM signal to control the speed of the motors.
This picture shows the final setup of. Fortunately the wires are long enough to easily connect everything. I had no problems with the female to female wires.
Until now everything was easy and worked very well. You can save a lot of work if you buy female to female wires. The wiring is done very fast and you have no loose contacts which causes problems. In the first setup I powered the Raspberry Pi with the 5V out from the L298 H-Bridge. But as mentioned above this doesn’t work very well. The 5V out is not stable enough to supply the Raspberry Pi with sufficient and constant current.
The next chapter is about the software setup of the Raspberry Pi and what we need to program the first script to control the L298 H-Bridge and the four motors.
Chapter 1: Raspberry Pi WIFI radio controlled rc vehicle – introduction
Chapter 2: Raspberry Pi WIFI radio controlled rc vehicle – component list
Chapter 3: Raspberry Pi WIFI radio controlled rc vehicle – chassis
Chapter 4: Raspberry Pi WIFI radio controlled rc vehicle – wiring
Chapter 5: Raspberry Pi WIFI radio controlled rc vehicle – software installation
Chapter 6: Raspberry Pi WIFI radio controlled rc vehicle – power supply
Chapter 7: Raspberry Pi WIFI radio controlled rc vehicle – programing
Chapter 8: Raspberry Pi WIFI radio controlled rc vehicle – live video streaming
Chapter 9: Raspberry Pi WIFI radio controlled rc vehicle – web-interface and smartphone
Chapter 10: Raspberry Pi WIFI radio controlled rc vehicle – cooling with passive heat sinks
Chapter 11: Raspberry Pi WIFI radio controlled rc vehicle – startup scripts
Chapter 12: Raspberry Pi WIFI radio controlled rc vehicle – cardboard car model
Chapter 13: Raspberry Pi WIFI radio controlled rc vehicle – power consumption