Danittoo
Posts: 3
Joined: Fri Apr 09, 2021 9:52 am

I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Sat Jul 24, 2021 2:03 am

Dear Friends,
At first, I am so excited to work with RaspberryPi4 for my school project (Autonomous Robot for Leak Detection in a Dry Metallic Pipeline. I started with programming the Ultrasonic sensors, Camera, LEDs etc. However, I am getting a bit traumatized because I have not been able to program the controller to be able to drive 2 pairs of DC geared motors with encoders and 2 pairs of 298N Motor Driver shield which I bought with a Mecanum Wheel. I am running late to submission date. I don’t know if anyone could show me similar work done with these components or be able to look at my code and suggest possible ways to get me back on track. Thank you. Please help me. Thank you. You can also reach me via https://github.com/Danittoo/Automation/projects/1

Materials used: Please copy each link to your browser.
1. Buy a Raspberry Pi 4 Model B – Raspberry Pi
2. JGA25-371 DC Gearmotor with Encoder (126 RPM at 12 V) | Open ImpulseOpen Impulse
3. 2pcs 298N Driver Board Module Stepper Motor Smart Car Robot Breadboard Peltier High Power L298 DC Motor Driver Arduino E11943|Motor 4. Driver| - AliExpress
Mecanum wheel chassis DC motor car chassis with shock absorption omnidirectional mobile ROS flat DIY robot toy|RC Tanks| - AliExpress
Last edited by Danittoo on Wed Sep 15, 2021 8:25 pm, edited 1 time in total.

pcmanbob
Posts: 11633
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Tue Jul 27, 2021 9:17 pm

Hi.

First off all replies will be posted on the forum thread , it's unlikely any one will mail you direct.

You have posted no code or links so we have nothing to work with , not even an explanation of what problems you are having specifically,

so I suggest you look at this project which used the same type of motor controller as you have.

https://projects.raspberrypi.org/en/pro ... ld-a-buggy
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Danittoo
Posts: 3
Joined: Fri Apr 09, 2021 9:52 am

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Wed Sep 15, 2021 2:29 am

Hello Sir,

Thank you for your reply.

The major problem I have is with the Encoder connection and Programming. I am making use of a DC geared motor which has an encoder attached to its physical structure to boost the torque of the motor when in operation.

This is my link to my Project: https://github.com/Danittoo/Automation.git
There you will see the code I have programmed for the Motor part. But I need to know how to declare the Encoder on the RaspberryPi. The motor has 6 wires amongst which 2 wires are for the encoder. How then can I connect these wires to my RaspberryPi and the L298N Motor shield driver?

ame
Posts: 3519
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Wed Sep 15, 2021 2:50 am

Your GitHub is empty. And you really should delete your email address from the forum unless you want to get spammed.

It is also not clear what help you need.

Here is a pinout for that motor. Maybe it matches yours. The pins are numbered, but the functions are referred to by colour. Never mind, you can probably figure it out.

https://www.openimpulse.com/blog/wp-con ... ing-21.jpg

Two pins run the motor. These should be connected to the output of the L298 module.

The other four pins are for the encoder. These should be connected to the Pi. Probably 3.3V for "coding power supply +", and GND for "coding power supply -". Then the two "signal feedback" can be connected to Pi GPIO pins.

That is it for hardware.

For software, you can use the encoder if you want to. The technique is called quadrature encoding, and it is easy to decode. The encoder will generate pulses when the motor is turning. You can use the pulses to calculate speed and direction of the motor. Or you can ignore them. It is not necessary to use the encoder to make the motor work.

Danittoo
Posts: 3
Joined: Fri Apr 09, 2021 9:52 am

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Thu Sep 16, 2021 1:44 am

Thank you Mr Ame for your quick reply.

This link ( https://www.openimpulse.com/blog/wp-con ... ing-21.jpg )you sent has slight difference in the colours or wires and configuration.

The Exact DC Motor can be seen in this link: https://www.seeedstudio.com/JGA25-371-G ... -4125.html

CONNECTION MODE:
1 RED-MOTOR +
2 BLACK-MOTOR –
3 GREEN-HALL SENSOR GND
4 BLUE-HALL SENSOR VCC
5 YELLOW-HALL SENSOR A Vout
6. WHITE-HALL SENSOR B Vout

This motor has an encoder which monitors the speed of the motor through an optoelectronic, Hall or magnetic encoder chip. Using an encoder, we can use some complicated algorithms. For example, we can use the PID algorithm to monitor the speed of the motor. And controls such as speed off can keep the speed of the motor at a certain value. When the external load becomes larger, the speed of the ordinary motor will slow down, but when we know that it is slow, we can adjust it by an algorithm. Controlling the output voltage keeps the motor speed at a certain value.

I need to learn how to control the related algorithms. Pls see below codes which works for the Basic movement of the DC motor without an Encoder, so by introducing the Encoder ( with wires 3 and 4) How then will I modify the program.

Please, let me know also How the L298D Motor Driver will be connected to the Raspberry Pi and Motors physically.

import RPi.GPIO as GPIO
import time
IN1A=14 #output pins for motor 1
IN1B=15
IN2A=23 #output pins for motor 2
IN2B=24
IN3A=5 #output pins for motor 3
IN3B=6
IN4A=2 #output pins for motor 4
IN4B=3
GPIO.setmode(GPIO.BCM)
GPIO.setup(IN1A,GPIO.OUT) #setting all pins as output
GPIO.setup(IN1B,GPIO.OUT)
GPIO.setup(IN2A,GPIO.OUT)
GPIO.setup(IN2B,GPIO.OUT)
GPIO.setup(IN3A,GPIO.OUT)
GPIO.setup(IN3B,GPIO.OUT)
GPIO.setup(IN4A,GPIO.OUT)
GPIO.setup(IN4B,GPIO.OUT)
def fwd():#function for forward movement
GPIO.output(IN1A,GPIO.HIGH)
GPIO.output(IN1B,GPIO.LOW)
GPIO.output(IN2A,GPIO.HIGH)
GPIO.output(IN2B,GPIO.LOW)
GPIO.output(IN3A,GPIO.HIGH)
GPIO.output(IN3B,GPIO.LOW)
GPIO.output(IN4A,GPIO.HIGH)
GPIO.output(IN4B,GPIO.LOW)
def bwd(): #function for backward movement
GPIO.output(IN1B,GPIO.HIGH)
GPIO.output(IN1A,GPIO.LOW)
GPIO.output(IN2B,GPIO.HIGH)
GPIO.output(IN2A,GPIO.LOW)
GPIO.output(IN3B,GPIO.HIGH)
GPIO.output(IN3A,GPIO.LOW)
GPIO.output(IN4B,GPIO.HIGH)
GPIO.output(IN4A,GPIO.LOW)
def left(): #function for left turn
GPIO.output(IN1A,GPIO.HIGH)
GPIO.output(IN1B,GPIO.LOW)
GPIO.output(IN2B,GPIO.HIGH)
GPIO.output(IN2A,GPIO.LOW)
GPIO.output(IN3B,GPIO.HIGH)
GPIO.output(IN3A,GPIO.LOW)
GPIO.output(IN4A,GPIO.HIGH)
GPIO.output(IN4B,GPIO.LOW)
def right(): #function for right turn
GPIO.output(IN1B,GPIO.HIGH)
GPIO.output(IN1A,GPIO.LOW)
GPIO.output(IN2A,GPIO.HIGH)
GPIO.output(IN2B,GPIO.LOW)
GPIO.output(IN3A,GPIO.HIGH)
GPIO.output(IN3B,GPIO.LOW)
GPIO.output(IN4B,GPIO.HIGH)
GPIO.output(IN4A,GPIO.LOW)
def stop(): #function for stop
GPIO.output(IN1A,GPIO.LOW)
GPIO.output(IN1B,GPIO.LOW)
GPIO.output(IN2A,GPIO.LOW)
GPIO.output(IN2B,GPIO.LOW)
GPIO.output(IN3A,GPIO.LOW)
GPIO.output(IN3B,GPIO.LOW)
GPIO.output(IN4A,GPIO.LOW)
GPIO.output(IN4B,GPIO.LOW)

try:
while True:
print ("forward")
fwd()
time.sleep(2)
print("backward")
bwd()
time.sleep(2)
print("left")
left()
time.sleep(2)
print("right")
right()
time.sleep(2)
print("stop")
stop()
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()




'''connection in chasis
motor1---------------motor2
| |
| |
| |
| |
motor3---------------motor4'''

ame
Posts: 3519
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Thu Sep 16, 2021 2:03 am

Ok. So you are late with your homework. Unfortunately nobody will do your homework for you. That said, don't panic. Start from the beginning and add things as you learn.

Also, use Google. In about two seconds I was able to find this:

https://www.electronicshub.org/raspberr ... pberry-pi/

And when you publish code on this forum use the "Code" tags so that it will be displayed properly.

ame
Posts: 3519
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: I have not been able to program the controller to be able to drive 2 pairs of DC geared motors

Thu Sep 16, 2021 2:07 am

And don't worry about the encoders. If you can turn the motors on and off then that is a huge success.

And actually, if your robot is driving inside a pipeline I suspect you only need forwards/backwards control.

Return to “Automation, sensing and robotics”