In this lesson, we will teach you how to install the OSOYOO V2.0 Raspberry Pi Robot Car basic frame work.

Circuit Connection:

The most important part in this project is OSOYOO Model-Pi motor drive board- an improved L298N module which can power motor and  Raspberry Pi at the same time.

OSOYOO Model-Pi L298N board is perfect motor driver board for Raspberry Pi portable applications such as robots, RC cars , drones , mini weather station etc.

This board supports all the features of L298N DC motor driver, in addition, it also has a USB 5V output port which can provide stable voltage to Raspberry Pi board.

I/O pins fully compatible with L298N including EnableA/IN1/IN2/IN3/IN4/EnableB.  Two Channels of PWM output and   to control left and right wheels. Each Channel has two output sockets (K1/K2 for right side wheels and K3/K4 for left side wheels)

Input power source can be 7.5v-24v batteries (we suggest using 2pcs tandem 18650 batteries etc, or 6pcs AAA Tandem AAA batteries, or , 2pcs Parallel 9V batteries for robot project).

USB port gives stable 5V/2.4A output.

Brief introduction of the I/O pins:
PCA9685 connection:

There are 6 input-signal pins ENA,IN1,IN2,IN3,IN4,ENB and two pairs of output socket (K1/K2, K3/4) which connect to left and right motors.

ENA connect to PCA9685 PWM0,ENB connect PCA9685 PWM1.

K1 and K2 are same, K3 and K4 are same, see following pictures:

Picture 1:
Motor to Model-Pi board connection map K3/K4 connect to left motors, K1/K2 connect to right motors

ENA gets PWM signal (analog current signal) from raspberry pi or Arduino. If ENA current is high, K1,K2 will have higher rotation speed.
ENB gets PWM signal (analog current signal) from raspberry pi or Arduino. If ENB current is high, K3,K4 will have higher rotation speed.

IN1,IN2 digital input pins determine  the rotation direction of K1,K2 motor. If IN1=HIGH(1), IN2= LOW (0),motor in K1 or K2 moves forward. If IN1=LOW, IN2= HIGH, K1 or K2 motor moves backward. If IN1,IN2 has same voltage , K1/K2 motor does not move.

IN3,IN4 digital input pins determine  the rotation direction of K3,K4 motor. If IN3=HIGH(1), IN4= LOW (0),motor in K3 or K4 moves forward. If IN3=LOW, IN4= HIGH, K3 or K4 motor moves backward. If IN3,IN4 has same voltage , K3/K4 motor does not move.

Picture 2: Model Pi connection map to Battery and Raspberry Pi board

Sample Application:

In following  example , we will use Python to make a simple program to make two motors in K1 and K3 move forward for 2 seconds then move backwards for two seconds.

First ,please connect the Raspberry Pi GPIO pins to Model Pi six control pins as picture 3:
Picture 3:(ENA改到PCA9685 PWM 0 ,ENB 改接PCA9685 PWM 1 )

Then turn on the battery and use putty or ssh to connect your raspberry Pi.

Software Installation:

If you have not enable I2C, please run following command to enable I2C

sudo raspi-config

Then select Interfacing Options->I2C->Yes->Ok->Finish

Step 1) If you  don’t have rpi.gpio and adafruit-pca9685 library, use following command to install the library:

sudo apt-get install rpi.gpio
sudo pip install adafruit-pca9685

Step 2)Type following command to download the sample code:

wget http://osoyoo.com/driver/picar/picar-basic.py
python picar-basic.py

After above python is running, you motors will move forward for 0.75 seconds and then move backward for 0.75 seconds, and turn left for 0.75 seconds and turn right for 0.75 seconds then stop.

We have write full comments in the sample python code http://osoyoo.com/driver/picar/picar-basic.py . If you have some basic python knowledge, you can easily understand how to customize the code for your own application.