5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10



Raspberry pi 4WD Robot Tutorial 3.2 advance

Posted by Fiona Su on

advance.c

advance.py

2.Raspberry Pi platform-------advance 

1) Preparation

image.png 

1-1  Raspberry Pi board

image.png 

1-2  4 motors

2) Purpose of Experimental

After running the advance executable in the Raspberry Pi system. After the car is still for two seconds, it keeps looping forward.

3) Principle of experimental

We use the TB6612FNG driver chip to drive the motor. Control the forward, reverse, and stop of the motor by controlling the level of AIN1, AIN2, BIN1, BIN2, PWMA, and PWMB of the driver chip.

In this experiment, we control robot car advance by controlling AIN1 to be high level, AIN2 is low level, BIN1 is high level, BIN2 is low level. And we control speed of the robot car by controlling PWMA, PWMB(0-255). One-channel PWM control the speed of the motor on one side of the robot car.

4) Experimental Steps

4-1 About the schematic

image.png 

4-1 Raspberry Pi interface circuit diagram

image.png 

 4-2  Motor drive chip---TB6612FNG

image.png 

4-3 Raspberry Pi 40 pins comparison table

4-2  According to the circuit schematic:

         AIN1-----40(Physical pin)----29(wiringPi)

         AIN2-----38(Physical pin)----28(wiringPi)

         PWMA-----36(Physical pin)----27(wiringPi)

         BIN1-----37(Physical pin)----25(wiringPi)

         BIN2-----35(Physical pin)----24(wiringPi)

         PWMB-----33(Physical pin)----23(wiringPi)

4-3  About the code

(Note: A software PWM library in the wiringPi is required for this experimental.)

(1) We need to compile this file in the Raspberry Pi system. (Note: we need to add -lwiringPi to the library file.)

We need to input:gcc advance.c -o advance -lwiringPi

image.png 

(2)We need to run the compiled executable file in the Raspberry Pi system.We need to input: ./ advance 

As shown in the figure below.

image.png 

(3)We can input: ctrl+c to stop this process, which mean is send a signal to the linux kernel to terminate the current process, but the state of the relevant pin is uncertain at this time, we also need to run a script to initialize all pins.

(Note:The initpin.sh script file is included in the SmartCar directory.)

You need to input:  chmod 777 initpin.sh

./initpin.sh

image.png 

After completing the above steps, the experiment is over.

0 comments

Leave a comment

Please note, comments must be approved before they are published