Jasonmcbee
Posts: 4
Joined: Mon Sep 04, 2017 12:54 pm

RPi 3 to control dc motor

Mon Sep 04, 2017 1:12 pm

Ok so I'm new to raspberry pi. The task I am completing is rather simple. However I need some advice on what to purchase.

So I am making an annealing machine to anneal by ammo brass. Here is a sample of what I will be building so you can see the speed and functionality.

https://youtu.be/csgCJsWgrxQ

As of right now I have raspberry pi 3 B. I see several forums on how to connect them to the GPIO pins. From what I'm reading they do not supply enough power to run off them directly. Plus could damage the pi. I dont want to buy a bunch of stuff and not need it. So I was thinking of buying these.

https://www.amazon.com/gp/aw/d/B014KMHS ... oard&psc=1

https://www.amazon.com/dp/B01N1JQFYX?aa ... LFVTRONa8Q

It's high torque but speed is still to much. I know you can control the speed of regular dc motors, but can you on these? I did find it as low as .6 rpm.

I'm not trying to spend a lot of money. However I do want it to function properly.

Any advice on what parts I will need would be great.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RPi 3 to control dc motor

Mon Sep 04, 2017 9:11 pm

The H-Bridge that you linked is a super commonly used H-bridge for driving smallish motors. I did have a really quick scan over the motor but didn't see the required amps, you will have to ensure that your H-Bridge is capable of the amount of power the motor will draw (that h bridge is 25w 2A continuous)

The H-bridge in pins are switching on/off and reversing direction and braking of the Motor, the PMW pins r for speed control

The RPi only has 1 hardware PWM pin but I do believe the pigpio libiary will be able to create software PWM that will be fine for speed control of a motor. :) .

Jasonmcbee
Posts: 4
Joined: Mon Sep 04, 2017 12:54 pm

Re: RPi 3 to control dc motor

Mon Sep 04, 2017 10:19 pm

For the motor I should stay below the 2A right. So if I find one at .5A that's fine right? Also what do you guys think the minimum should be for this purpose? Should I look at other boards instead of this one for the PWM?

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: RPi 3 to control dc motor

Mon Sep 04, 2017 10:40 pm

OutoftheBOTS wrote:
Mon Sep 04, 2017 9:11 pm
The RPi only has 12 hardware PWM pins but I do believe the pigpio libiary will be able to create software PWM that will be fine for speed control of a motor. :) .
FTFY :)

Also, technically the Pi has two hardware GPIOs. Each of them can be assigned to different pins. PWM0 can be assigned to GPIO18 (pin12) , GPIO12 (pin12) or GPIO40 (only available on CM). PWM1 can be assigned to GPIO13 (pin 33), GPIO19 (pin 35), GPIO41 (only available on CM) or GPIO45 (only available on CM).

To use those GPIOs as PWM will mean you have to disable the audio out on the A/V jack as that uses the hardware PWM.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RPi 3 to control dc motor

Tue Sep 05, 2017 3:45 am

For the motor I should stay below the 2A right. So if I find one at .5A that's fine right?
U never know till you try. Technically you can work out how much torque and rpm you need then match the motor specs to your need, unfortunely it doesn't always work because lots of manufactures lie about the specs of their products.

But looks at the vid it doesn't look like it needs much power to spin a small turn table at low speed :)

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RPi 3 to control dc motor

Tue Sep 05, 2017 3:51 am

lso, technically the Pi has two hardware GPIOs. Each of them can be assigned to different pins. PWM0 can be assigned to GPIO18 (pin12) , GPIO12 (pin12) or GPIO40 (only available on CM). PWM1 can be assigned to GPIO13 (pin 33), GPIO19 (pin 35), GPIO41 (only available on CM) or GPIO45 (only available on CM).
I am new to Linux so still learning. I assume to be able to use both hardware PWM then you need to modify the device tree to switch the second PWM from the audio jack tot he GPIO pins ?

Also even though hardware PMW is better than software PWM considering he is just going to be using it for motor speed control (not a super critical PWM like audio DAC) could it be easier for hoim just to use the software PWM in the pigpio library, although I haven't yet used this library I assume there is already examples for PWM motor speed control?

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: RPi 3 to control dc motor

Tue Sep 05, 2017 4:43 am

OutoftheBOTS wrote:
Tue Sep 05, 2017 3:51 am
I am new to Linux so still learning. I assume to be able to use both hardware PWM then you need to modify the device tree to switch the second PWM from the audio jack tot he GPIO pins ?
No, all you need to do is disable the audio driver by removing or commenting out the "dtparam=audio=on" in /boot/config.txt. This applies to BOTH PWM channels as the audio uses both of them for stereo output.
Also even though hardware PMW is better than software PWM considering he is just going to be using it for motor speed control (not a super critical PWM like audio DAC) could it be easier for him just to use the software PWM in the pigpio library, although I haven't yet used this library I assume there is already examples for PWM motor speed control?
I agree, software PWM is probably going to be sufficient for speed control. I haven't used joan's pigpio library yet, but I believe it has good support for software PWM.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RPi 3 to control dc motor

Tue Sep 05, 2017 6:23 am

I have also just had a thought, I am mainly using RPi zero w for my robots and the Zero doesn't have an audio jack so both PWM could be used for the GPIO pins

Jasonmcbee
Posts: 4
Joined: Mon Sep 04, 2017 12:54 pm

Re: RPi 3 to control dc motor

Tue Sep 05, 2017 5:42 pm

Thanks for the help so far guys. All my parts should be in today and tomorrow. Can't wait to start assembling. Since starting this project I have already decided on starting other builds now.

Jasonmcbee
Posts: 4
Joined: Mon Sep 04, 2017 12:54 pm

Re: RPi 3 to control dc motor

Wed Sep 06, 2017 12:25 am

Ok so I picked this up,

https://www.ebay.com/p/haiworld-rpi-sta ... &rdtsrc=vi

My question is the screen takes up 2/3 the gpio pins. Can I use both this and the H- ridge I mentioned earlier plus the dc motors?

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: RPi 3 to control dc motor

Wed Sep 06, 2017 9:00 pm

It doesn't give any info about the screen at all so no way to tell what it requires but at a guess I would assume it is a SPI screen or HDMI screen.

The SPI screens usually using all the SPI pins including both CS pins for the screen and touch pins GPIO 10, GPIO09, GPIO11, GPIO08 and GPIO07.

The HDMI screens use the HDMI port then usually the I2C pins for the touch GPIO02, GPIO03 but I2C can have multi things plugged into ti as long as they have different addresses similar to a usb port.

The main problem is most of these screens r designed to plug down on the GPIO header and cover all the unused pins making them hard to access, most of the time you need somesort of GPIO adapter to access the pins

Return to “Automation, sensing and robotics”