KS0218 keyestudio RPI L298P Motor Drive Shield: Difference between revisions
Keyestudio (talk | contribs) No edit summary |
Keyestudio (talk | contribs) No edit summary |
||
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<br> | |||
==Introduction== | ==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. <br> | 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. <br> | ||
The shield is fully compatible with various versions of Raspberry Pi. Meanwhile, | 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.<br> | ||
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.<br> | 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.<br> | ||
<br>[[File:KS0218-1.png|500px|frameless|thumb]]<br> | |||
<br> | |||
==Specification== | ==Specification== | ||
* Logic part input voltage: 5V | * Logic part input voltage: 5V | ||
Line 19: | Line 20: | ||
* Working temperature: -25℃~+130℃ | * Working temperature: -25℃~+130℃ | ||
* Driver form: Dual power H bridge driving | * Driver form: Dual power H bridge driving | ||
<br> | |||
<br>[[File:KS0218~10.jpg|600px|frameless|thumb]]<br> | |||
<br> | |||
==Connection Diagram == | ==Connection Diagram == | ||
Connect the motors and batteries to the terminal block of RPI L298P shield. | Connect the motors and batteries to the terminal block of RPI L298P shield.<br> | ||
<br>[[File:0218.png|800px|frameless|thumb]]<br> | |||
<br>[[File: | |||
<br> | |||
==Sample Code== | ==Sample Code== | ||
<pre> | <pre> | ||
Line 32: | Line 34: | ||
#include <stdio.h> | #include <stdio.h> | ||
#include <string.h> | #include <string.h> | ||
#include <stdlib.h> | |||
#include <stdint.h> | |||
#include <errno.h> | #include <errno.h> | ||
#include <wiringSerial.h> | #include <wiringSerial.h> | ||
#include <softPwm.h> | |||
#define PIN 27 | #define PIN 27 | ||
#define IO digitalRead(PIN) | #define IO digitalRead(PIN) | ||
Line 40: | Line 46: | ||
unsigned char data[4]; | unsigned char data[4]; | ||
char a; | char a; | ||
long up = | long up = 0x46; | ||
long back = 0x15; | long back = 0x15; | ||
long stop = | long stop = 0x40; | ||
long left = 0x44; | long left = 0x44; | ||
long right= 0x43; | long right= 0x43; | ||
long esc= 0x4a; | long esc= 0x4a; | ||
#define ENA 22 | |||
#define ENB 30 | |||
int main() | int main() | ||
Line 55: | Line 62: | ||
pinMode(1,OUTPUT); | pinMode(1,OUTPUT); | ||
int fd ; | int fd ; | ||
pinMode(26,OUTPUT); | pinMode(26,OUTPUT); | ||
pinMode(21,OUTPUT); | pinMode(21,OUTPUT); | ||
pinMode(22,OUTPUT); | |||
pinMode(30,OUTPUT); | pinMode(30,OUTPUT); | ||
softPwmCreate(ENA, 0, 100); | |||
softPwmCreate(ENB, 0, 100); | |||
printf("L298P test......\n"); | printf("L298P test......\n"); | ||
for(a=0;a<2;a++) | for(a=0;a<2;a++) | ||
Line 65: | Line 73: | ||
digitalWrite(21,HIGH); | digitalWrite(21,HIGH); | ||
digitalWrite(26,HIGH); | digitalWrite(26,HIGH); | ||
softPwmWrite(ENA,100); | |||
softPwmWrite(ENB,100); | |||
delay( | delay(2000); | ||
softPwmWrite(ENA,0); | |||
softPwmWrite(ENB,0); | |||
delay( | delay(2000); | ||
digitalWrite(21,LOW); | digitalWrite(21,LOW); | ||
digitalWrite(26,LOW); | digitalWrite(26,LOW); | ||
delay( | softPwmWrite(ENA,50); | ||
softPwmWrite(ENB,50); | |||
delay(2000); | |||
delay( | softPwmWrite(ENA,0); | ||
softPwmWrite(ENB,0); | |||
delay(2000); | |||
} | } | ||
printf("IRM Test Program ... \n"); | printf("IRM Test Program ... \n"); | ||
Line 118: | Line 128: | ||
if(data[0]+data[1] == 0xFF && data[2]+data[3]==0xFF) //check | if(data[0]+data[1] == 0xFF && data[2]+data[3]==0xFF) //check | ||
printf("Get the key: 0x%02x | printf("Get the key: 0x%02x ",data[2]); | ||
if (data[2] == up ) | if (data[2] == up ) | ||
{ | { | ||
printf("up\n"); | |||
digitalWrite(21,HIGH); | digitalWrite(21,HIGH); | ||
digitalWrite(26,HIGH); | digitalWrite(26,HIGH); | ||
softPwmWrite(ENA,30); | |||
softPwmWrite(ENB,30); | |||
delay(1000); | delay(1000); | ||
} | } | ||
if (data[2] == back ) | if (data[2] == back ) | ||
{ | { | ||
printf("back\n"); | |||
digitalWrite(21,LOW); | digitalWrite(21,LOW); | ||
digitalWrite(26,LOW); | digitalWrite(26,LOW); | ||
softPwmWrite(ENA,60); | |||
softPwmWrite(ENB,60); | |||
delay(1000); | delay(1000); | ||
} | } | ||
if (data[2] == stop ) | if (data[2] == stop ) | ||
{ | { | ||
printf("stop\n"); | |||
softPwmWrite(ENA,0); | |||
softPwmWrite(ENB,0); | |||
delay(1000); | delay(1000); | ||
} | } | ||
if (data[2] == left ) | if (data[2] == left ) | ||
{ | { | ||
digitalWrite(21, | printf("left\n"); | ||
digitalWrite(26, | digitalWrite(21,LOW); | ||
digitalWrite(26,HIGH); | |||
softPwmWrite(ENA,90); | |||
softPwmWrite(ENB,90); | |||
delay(1000); | delay(1000); | ||
} | } | ||
if (data[2] == right ) | if (data[2] == right ) | ||
{ | { | ||
digitalWrite(21, | printf("right\n"); | ||
digitalWrite(26, | digitalWrite(21,HIGH); | ||
digitalWrite(26,LOW); | |||
softPwmWrite(ENA,50); | |||
softPwmWrite(ENB,50); | |||
delay(1000); | delay(1000); | ||
} | } | ||
Line 177: | Line 190: | ||
</pre> | </pre> | ||
<br> | |||
< | |||
Note:<br> | |||
1.Pin 21 and 26 in the code are used for controlling the direction of two motors. The motor will rotate clockwise when high level, and they will rotate anticlockwise when low level.<br> | |||
2.Pin 22 and 30(wPi interface) are used for controlling the speed of two motors.<br> | |||
softPwmCreate(ENA, 0, 100); | |||
softPwmCreate(ENB, 0, 100); | |||
The maximum speed value is 100. | |||
softPwmWrite(ENA,50); | |||
softPwmWrite(ENB,50); | |||
50 is the value of speed adjustment, the larger the data is set, the faster the speed(less than 100) | |||
==Using Method== | ==Using Method== | ||
''' | '''A.''' Use the WinSCP to place rpi_L298P folder into the Raspberry system. Shown as below.<br> | ||
<br>[[File:KS0218-3.png| | <br>[[File:KS0218-3.png|700px|frameless|thumb]]<br> | ||
<br>[[File:KS0218-4.png| | <br>[[File:KS0218-4.png|700px|frameless|thumb]]<br> | ||
''' | '''B.''' On the terminal input cd rpi_L298P to enter the folder. <br> | ||
''' | '''C.''' On the terminal execute make, it will generate a L298P executable file inside the folder. <br> | ||
''' | '''D.''' Wire it up as the above diagram, then enter rpi_L298P folder, on the terminal execute the '''sudo ./L298P''', firstly test two motors, and two DC motors will turn forward for one second,stop for one second, reverse for one second, then stop for one second, loop twice. Then, aimed at the infrared receiver, press down the button on the infrared remote control, you will see the Raspberry Pi terminal display the corresponding data. <br> | ||
''' | When press down the up, down, left, right and OK key of remote control, the shield will control the two motors run, to simulate the car go forward, backward, turn left, turn right and stop. <br> | ||
'''E.''' '''Ctrl + C''' can exit the processing. | |||
<br>[[File: | <br>[[File:0218---xin.png|600px|frameless|thumb]]<br> | ||
<br>[[File:0218- 2.png|600px|frameless|thumb]]<br> | |||
<br> | |||
== Resources== | == Resources== | ||
*'''File and Source Code:''' <br> | |||
https://fs.keyestudio.com/KS0218 | |||
<br> | |||
== Get One Now == | == Get One Now == | ||
*[https://www.keyestudio.com/keyestudio-rpi-l298p-motor-drive-shield-for-arduino-raspberry-pi-p0343.html '''Official website''' ] | |||
*[https://www.aliexpress.com/store/product/Keyestudio-RPI-L298P-Motor-Drive-Shield-For-Arduino-Raspberry-Pi/1452162_32884737696.html?spm=2114.12010612.8148356.5.533b60ffCK0OcA '''Shop on aliexpress''' ] | |||
[[Category:Raspberry Pi]] | [[Category:Raspberry Pi]] |
Latest revision as of 10:29, 6 March 2023
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.
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
Connection Diagram
Connect the motors and batteries to the terminal block of RPI L298P shield.
Sample Code
#include <wiringPi.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <errno.h> #include <wiringSerial.h> #include <softPwm.h> #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<<cnt); if(cnt == 7) { cnt = 0; idx++; } else cnt++; } if(data[0]+data[1] == 0xFF && data[2]+data[3]==0xFF) //check printf("Get the key: 0x%02x ",data[2]); if (data[2] == up ) { printf("up\n"); digitalWrite(21,HIGH); digitalWrite(26,HIGH); softPwmWrite(ENA,30); softPwmWrite(ENB,30); delay(1000); } if (data[2] == back ) { printf("back\n"); digitalWrite(21,LOW); digitalWrite(26,LOW); softPwmWrite(ENA,60); softPwmWrite(ENB,60); delay(1000); } if (data[2] == stop ) { printf("stop\n"); softPwmWrite(ENA,0); softPwmWrite(ENB,0); delay(1000); } if (data[2] == left ) { printf("left\n"); digitalWrite(21,LOW); digitalWrite(26,HIGH); softPwmWrite(ENA,90); softPwmWrite(ENB,90); delay(1000); } if (data[2] == right ) { printf("right\n"); digitalWrite(21,HIGH); digitalWrite(26,LOW); softPwmWrite(ENA,50); softPwmWrite(ENB,50); delay(1000); } } } printf("Bluetooth Test Program ... \n"); if ((fd = serialOpen ("/dev/ttyAMA0", 9600)) < 0) { fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ; return 1 ; } // Loop, getting and printing characters while(1) { putchar (serialGetchar (fd)) ; fflush (stdout) ; } }
<
Note:
1.Pin 21 and 26 in the code are used for controlling the direction of two motors. The motor will rotate clockwise when high level, and they will rotate anticlockwise when low level.
2.Pin 22 and 30(wPi interface) are used for controlling the speed of two motors.
softPwmCreate(ENA, 0, 100); softPwmCreate(ENB, 0, 100);
The maximum speed value is 100.
softPwmWrite(ENA,50); softPwmWrite(ENB,50);
50 is the value of speed adjustment, the larger the data is set, the faster the speed(less than 100)
Using Method
A. Use the WinSCP to place rpi_L298P folder into the Raspberry system. Shown as below.
B. On the terminal input cd rpi_L298P to enter the folder.
C. On the terminal execute make, it will generate a L298P executable file inside the folder.
D. Wire it up as the above diagram, then enter rpi_L298P folder, on the terminal execute the sudo ./L298P, firstly test two motors, and two DC motors will turn forward for one second,stop for one second, reverse for one second, then stop for one second, loop twice. Then, aimed at the infrared receiver, press down the button on the infrared remote control, you will see the Raspberry Pi terminal display the corresponding data.
When press down the up, down, left, right and OK key of remote control, the shield will control the two motors run, to simulate the car go forward, backward, turn left, turn right and stop.
E. Ctrl + C can exit the processing.
Resources
- File and Source Code:
https://fs.keyestudio.com/KS0218