# KS0218 keyestudio RPI L298P Motor Drive Shield ![](media/wps1.png) ## 1. Introduction Keyestudio RPI L298P motor drive shield adopts high-power motor driver chip L298P, which can directly drive two DC motors, with drive current up to 2A, and motor output terminal uses eight high-speed Schottky diodes as protection. The shield is fully compatible with various versions of Raspberry Pi. Meanwhile, the shield has leaded out each interface for simple connection of other sensors. This shield also has an IR receiver, so you can use infrared remote control to communicate with it. To make it easier for you to mount the shield to your Raspberry Pi, we have specially provided you with 4 M2.5 * 20MM round-head screws, 4 double-pass M2.5 * 10MM copper pillars and 4 M2.5 nickel-plating Nuts. ## 2. Specification - Logic part input voltage: 5V - Driving part input voltage: 4.8 ~ 24V - Logic part working current Iss: ≤36mA - Driving part working current Io: ≤ 2A - Maximum power dissipation: 25W (T=75℃) - Control signal input level: - High level: 2.3V ≤ Vin ≤ 5V - Low level: 0V ≤ Vin ≤ 1.5V - Working temperature: -25℃~+130℃ - Driver form: Dual power H bridge driving ![](media/wps2.png) ## 3. Connection Diagram Connect the motors and batteries to the terminal block of RPI L298P shield. ![](media/wps3.jpg) ## 4. Sample Code Download code : [Code](./Code.7z) ```c #include #include #include #include #include #include #include #include #define PIN 27 #define IO digitalRead(PIN) unsigned char i,idx,cnt; unsigned char count; unsigned char data[4]; char a; long up = 0x46; long back = 0x15; long stop = 0x40; long left = 0x44; long right= 0x43; long esc= 0x4a; #define ENA 22 #define ENB 30 int main() { wiringPiSetup(); pinMode(PIN, INPUT); pullUpDnControl(PIN, PUD_UP); pinMode(1,OUTPUT); int fd ; pinMode(26,OUTPUT); pinMode(21,OUTPUT); pinMode(22,OUTPUT); pinMode(30,OUTPUT); softPwmCreate(ENA, 0, 100); softPwmCreate(ENB, 0, 100); printf("L298P test......\n"); for(a=0;a<2;a++) { digitalWrite(21,HIGH); digitalWrite(26,HIGH); softPwmWrite(ENA,100); softPwmWrite(ENB,100); delay(2000); softPwmWrite(ENA,0); softPwmWrite(ENB,0); delay(2000); digitalWrite(21,LOW); digitalWrite(26,LOW); softPwmWrite(ENA,50); softPwmWrite(ENB,50); delay(2000); softPwmWrite(ENA,0); softPwmWrite(ENB,0); delay(2000); } printf("IRM Test Program ... \n"); while (data[2] != esc ) { if(IO == 0) { count = 0; while(IO == 0 && count++ < 200) //9ms delayMicroseconds(60); count = 0; while(IO == 1 && count++ < 80) //4.5ms delayMicroseconds(60); idx = 0; cnt = 0; data[0]=0; data[1]=0; data[2]=0; data[3]=0; for(i =0;i<32;i++) { count = 0; while(IO == 0 && count++ < 15) //0.56ms delayMicroseconds(60); count = 0; while(IO == 1 && count++ < 40) //0: 0.56ms; 1: 1.69ms delayMicroseconds(60); if (count > 25)data[idx] |= (1<