-
-
Re: Wiring a motor to the RPi?
wallarug Aug 17, 2012 4:59 AM (in response to ingramator)What do all the lines mean? (I know they are wires/joining components) Could you label all the individual parts please. This looks a bit complicated as well.
-
This reply has been hidden. This can happen if the message has been hidden by a moderator, or has been reported as abusive.
-
Re: Wiring a motor to the RPi?
wallarug Aug 17, 2012 5:12 AM (in response to ingramator)tom smith wrote:
I already did you faggot. I put all that effort in...
Srry, I should have been more specfic. Also, can someone explain why/how some connections go in three directions (I don't know how I would wire that).
Anything with a yellow circle. I worked out where the motors were.
PS: Please be nice to people on the forums, not everyone is an expert.
-
Re: Wiring a motor to the RPi?
michaelkellettAug 17, 2012 7:28 AM (in response to wallarug)
@ fergus, At the risk of being called something worse than you were - the schematic that Tom has posted is not suitable for a beginner to use to build a motor driver so I suggest you look elsewhere. The Gertboard has a motor driver section and the ciruit is published so you could either buy a Gertboard (best bet for the inexperienced) or build the relevant parts on stripboard if you are up to it. Either way you can use the software published for the Gertboard and have a bit more confidence that the design will work.
Michael Kellett
-
Re: Wiring a motor to the RPi?
ingramator Aug 17, 2012 9:45 AM (in response to michaelkellett)Yeah I agree with that guy, unless your a coding and electronics master I'd just use the gertboard!
-
-
-
-
-
-
Re: Wiring a motor to the RPi?
John BeetemAug 17, 2012 2:41 PM (in response to wallarug)
If all you want to do is turn a small DC motor on and off, all you need is Gert van Loo's circuit in this thread's 7th post: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=13473. The motor is driven by an NPN Darlington Pair (http://en.wikipedia.org/wiki/Darlington_pair), which is a great way to convert a small current into a really big current. The three diodes in series are for people are afraid the Darlington pair might accidentally conduct from collector to base. Gert says they're not necessary, but with 12V present I'd worry about framboise flambée and put them in.
The diode next to the motor coil is critically important. It's called a flyback diode (http://en.wikipedia.org/wiki/Flyback_diode). When you turn on the transistor, the flyback diode is reverse-biased and has no effect. However, when you turn off the transistor, the magnetic field in the motor will cause current to continue to flow for a while. If that current can't go anywhere (because the transistor is off), it will charge the node to a very high voltage and turn the transistor into a fuse and possibly destroy anything connected to the transistor. It's how spark plugs work. The flyback diode gives the current somewhere safe to go to prevent Spitzensparken. The diode should have a current rating higher than the current through the motor.
Gert doesn't give a value for the resistor between the GPIO and the base of the Darlington pair. I'd start with 1 KOhm which gives you 3.3 mA. But then, I usually start with 1K
-
Re: Wiring a motor to the RPi?
wallarug Aug 21, 2012 2:52 AM (in response to John Beetem)Could someone confirm if the GPIOs are a ground or send out signals. I think they are grounds but I can't be certain.
If they are grounds, then how would the transitor work if it is a NPN? wouldn't you need some positive current comming from somewhere?
Sorry if these are silly questions but I am only learning.
could someone also point me towards a sample code please. I have heard that the code is the tricky bit.
-
Re: Wiring a motor to the RPi?
Colin BarnardAug 21, 2012 5:11 PM (in response to wallarug)
The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 3v3 or be held at 3v3 and switch low. You get the choice of deciding which level equals on or off.
If you decide low (0v) is to be off then if using an NPN transistor switching the output high (3v3) would turn the transistor on. If you wanted it the other way around you'd would then use a PNP. However in your case it probably is better for you to start by using an NPN transistor, as from a beginners point of view they work in a more logical fashion.
Do you have a circuit in mind that you've seen where you could provide a link so that we can see if it achieve what you are hoping it will.
Do you know the type of motor - voltage, current requirements you are going to use?
As for code, I think the code for the Gertboard would be a good start especially as it also can run a small motor. I'll have to find the link but on the Pi forums is some example code. are you looking for code in Python or C ?
Colin
P.S. I live in the same country as you, so feel free to contact me if you need any further assistance.
Message was edited by: Colin Barnard corrected maximum voltage to show 3v3 instead of the incorrect 5v
-
Re: Wiring a motor to the RPi?
wallarug Aug 21, 2012 6:54 AM (in response to Colin Barnard)bodgy wrote:
The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 5v or be held at 5v and switch low. You get the choice of deciding which level equals on or off.
If you decide low (0v) is to be off then if using an NPN transistor switching the output high (5v) would turn the transistor on. If you wanted it the other way around you'd would then use a PNP. However in your case it probably is better for you to start by using an NPN transistor, as from a beginners point of view they work in a more logical fashion.
Do you have a circuit in mind that you've seen where you could provide a link so that we can see if it achieve what you are hoping it will.
Do you know the type of motor - voltage, current requirements you are going to use?
As for code, I think the code for the Gertboard would be a good start especially as it also can run a small motor. I'll have to find the link but on the Pi forums is some example code. are you looking for code in Python or C ?
Colin
P.S. I live in the same country as you, so feel free to contact me if you need any further assistance.
Firstly, what firmware do I need to swap between 5v and 0v. Currently I am using GPIO-0.2.0 which does not have this capability.
Secondly, I would like it to be in python becasue I know that a lot better than C.
I am thinking of using a motor rated at 12 volts, 14A.
wallarug
-
Re: Wiring a motor to the RPi?
Colin BarnardAug 21, 2012 7:57 AM (in response to wallarug)
I'm about to go to bed, so this will be quick
To switch 14A you would be better off using either a MOSFET or an IGBT. You'd need to find a BJT (an NPN transistor) that has a maximum collector current rating of more than 14A, probably 20A for a safety margin, that is to cover the possibility of keeping the transistor happy.
An MJH6284G for example would require at least 800mA into its base to switch it on, so you would need either as has been suggested a Darlington instead, or a smaller transistor between the GPIO and the base of the main BJT to switch it on. There are other BJTs that would work but they have a less beginner friendly footprint being TO-3s such as the PMD16K80. Personally I would use what are called logic gate MOSFETS, or you could use a dedicated motor driver chip which would save you some work.
Others of course might see things differently, there is always more than one answer to solve an electronics problem.
Colin
-
Re: Wiring a motor to the RPi?
wallarug Aug 22, 2012 5:51 AM (in response to Colin Barnard)How do I install the RPi-GPIO-0.3.1a library onto my Raspberry Pi? This is very important right now so that I can code some LEDs.
-
-
Re: Wiring a motor to the RPi?
John BeetemAug 21, 2012 1:47 PM (in response to wallarug)
Fergus Byrne wrote:
bodgy wrote:
The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 5v or be held at 5v and switch low. You get the choice of deciding which level equals on or off.
Firstly, what firmware do I need to swap between 5v and 0v. Currently I am using GPIO-0.2.0 which does not have this capability.
Secondly, I would like it to be in python becasue I know that a lot better than C.
I am thinking of using a motor rated at 12 volts, 14A.
wallarug
First, I'm sure bodgy meant that RasPi GPIO outputs can switch between 0V and 3.3V, not between 0 and 5V. GPIOs can be configured as inputs or outputs, along with pin-specific special functions. RasPi GPIOs are not 5V tolerant.
There's a nice treatment of RasPi GPIOs including software examples in C and Python at the RasPi Hardware Wiki: http://elinux.org/RPi_Low-level_peripherals.
If you're switching 14A you might be better off with a mechanical or solid-state relay. You'd still need an NPN transistor (or Darlington pair) or N-channel MOSFET to control the relay from RasPi, and you'd need a flyback diode across the relay. This is assuming you just want to turn the motor on and off. If you want to do variable torque and/or switch direction, you'll need more interesting circuits.
-
Re: Wiring a motor to the RPi?
Colin BarnardAug 21, 2012 5:29 PM (in response to John Beetem)
Ooops, sorry about the 5v confusion, I was still in 5v micro land, I forgot the Pi is a 3v3 beast.
Thinking about it, a TOP or PROFET made for vehicle electronics would probably work here with the advantage it has short circuit, thermal protection and flyback all built in.
BTS555 might be worth checking out.
http://au.element14.com/infineon/bts555/transistor-profet/dp/4109260
A small transistor would still be needed to be able to switch the PROFET on, and the collector of this transistor should be connected to the 12v rail.
Here is a link to how you could set this up, however as John says, if you just want the motor to switch on and off then a small transistor driving a relay or solid state relay would eb the cheapest option.
http://www.picotech.com/applications/pwm_drivers/#chap7
Colin
-
Re: Wiring a motor to the RPi?
wallarug Aug 21, 2012 8:24 PM (in response to Colin Barnard)Just another Questions,
How much current can each GPIO pin carry? On the wiki it says "The maximum permitted current draw from the 3.3 V pin is 50 mA." Does this mean in total or for each pin?
How do you set the GPIO pins as 0v or 3v3. Also I have been unsuccessful in installing the python 0.3.1a GPIO library (http://pypi.python.org/pypi/RPi.GPIO/0.3.1a#downloads). It says it is a C extension so I don't know whether I have to install another library or what?
Thanks for all this advice!
-
Re: Wiring a motor to the RPi?
John BeetemAug 21, 2012 11:00 PM (in response to wallarug)
Fergus Byrne wrote:
Just another Questions,
How much current can each GPIO pin carry? On the wiki it says "The maximum permitted current draw from the 3.3 V pin is 50 mA." Does this mean in total or for each pin?
50 mA is for the 3.3V power pin (P1-01) which is the output of RasPi's 3.3V regulator RG2. You can use it for +3.3V ICs and pull-ups on an external board provided that the total current is under 50 mA. There is also a 5V power pin (P1-02) which can be used for 5V parts or a regulator to get lower voltages. The 5V pin is connected to RasPi's main 5V (TP1) and current comes from your power supply and must not overload polyfuse F3. Be very careful not to accidentally short the 5V pin to any other P1 pin -- this could damage your RasPi. If you're not planning to use 5V strip off a short piece of insulation and slide it over the 5V pin.
According to http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29, the GPIO pins can be configured to drive from 2mA to 16 mA. How to do this is not in the main BCM2835 peripherals data sheet, but may be in the supplemental data sheet referenced. The GPIO software libraries should have a way to configure those pins.
I don't know how to use the Python libraries.
-
Re: Wiring a motor to the RPi?
wallarug Aug 22, 2012 2:25 AM (in response to John Beetem)Is there a program that I can use to build circuits?
Also, is there a program I can use to test python GPIO code? So I tell the program that I have an LED connected 9which could be displayed on the screen) and then it can output the data?
-
Re: Wiring a motor to the RPi?
obcd Aug 22, 2012 3:08 AM (in response to wallarug)The first question is confusing. Do you mean a program that simulates a hardware circuit?
To test the gpio, most people use the pi and a breadboard setup with some leds mounted on it.
If you are looking for a program to draw the schematics of the circuits and design the pcb, you can try the eagle program.
-
Re: Wiring a motor to the RPi?
wallarug Aug 22, 2012 3:52 AM (in response to obcd)Luc Cool wrote:
The first question is confusing. Do you mean a program that simulates a hardware circuit?
To test the gpio, most people use the pi and a breadboard setup with some leds mounted on it.
If you are looking for a program to draw the schematics of the circuits and design the pcb, you can try the eagle program.
I am looking for a simulator. I have a breadboard but I do not want to keep re-wiring it.
-
Re: Wiring a motor to the RPi?
wallarug Aug 25, 2012 5:53 AM (in response to obcd)Fergus Byrne wrote:
How do I install the RPi-GPIO-0.3.1a library onto my Raspberry Pi? This is very important right now so that I can code some LEDs.
i have installed the above python library. But I still don't know how to wire the motor to the raspberry pi.
-
Re: Wiring a motor to the RPi?
KenSeymour Aug 25, 2012 6:27 PM (in response to wallarug)Look up an H Bridge circuit. I have had good luck with this kit with an Arduino. I made a roller robot. I tried and failed with TIP102 and TIP107 but I am clumsier than most. If you go this route,
buy extra transistors in case you fry them.
Look at http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/. Follow the links to basic transistor etc.
The H bridge would have one output for forward and one for backwards. The kit controls 2 motors.
-
Re: Wiring a motor to the RPi?
wallarug Sep 8, 2012 12:47 AM (in response to KenSeymour)Ken Seymour wrote:
Look up an H Bridge circuit. I have had good luck with this kit with an Arduino. I made a roller robot. I tried and failed with TIP102 and TIP107 but I am clumsier than most. If you go this route,
buy extra transistors in case you fry them.
Look at http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/. Follow the links to basic transistor etc.
The H bridge would have one output for forward and one for backwards. The kit controls 2 motors.
Could you draw up a schematic diagram for me if I use this: https://www.adafruit.com/products/807. My friend has informed me that a H-Bridge is required and I found this IC and I think that it could work nicely.
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 8, 2012 9:26 PM (in response to wallarug)I have not created schematics except with pencil and paper. I noticed that his is a 5 Volt chip and the Pi outputs are 3.3 Volt.
I am working on a schematic with 2N3906 transistors to level-shift the outputs. If you power the motors off 5V as well, it avoids two power supplies.
-
Re: Wiring a motor to the RPi?
wallarug Sep 8, 2012 10:51 PM (in response to KenSeymour)Motors are powered off 12volts. Did you look at the Double H-Bridge IC I posted earlier?
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 9, 2012 12:38 PM (in response to wallarug)Here is the schematic. JP1 is meant to be the motor. I should mention that the transistor logically invert their signals.
When the GPIO is high, the chip input is low. So from the Pi's perspective, they are active when they are zero.
You need two power supplies. The solarbotics board has an on board regulator to provide the +5 volts.
The Pi only has one PWM output, so you could do PWM in software but get the motor going fast first.
Make sure the motor fits within the chip's power output max or just buy extra chips.
The 2N2222A2N2222A is cheap. Buy extra. I live in the US so I would get them here. http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_38236_-1.
Or use Newark/element 14, or Digikey, or Mauser.
-
sch1.png 11.4 KB
-
Re: Wiring a motor to the RPi?
wallarug Sep 9, 2012 5:59 PM (in response to KenSeymour)Thanks Ken. Great work. I will test later
What about the double H-Bridge chip in the earlier post?
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 9, 2012 7:28 PM (in response to wallarug)The schematic is for TI's L293D chip, which was posted above in a link from Adafruit.
It is a dual H-Bridge motor driver.
The E on the end of the part number is from the Eagle part library, but the pinout is the same.
-
Re: Wiring a motor to the RPi?
wallarug Sep 9, 2012 10:45 PM (in response to KenSeymour)Thanks for informing this of that fact.
-
Re: Wiring a motor to the RPi?
wallarug Sep 10, 2012 4:37 AM (in response to KenSeymour)Ken Seymour wrote:
The schematic is for TI's L293D chip, which was posted above in a link from Adafruit.
It is a dual H-Bridge motor driver.
The E on the end of the part number is from the Eagle part library, but the pinout is the same.
How can I get PWM working on the motors? Can you please give me instructions on software and/or extra hardware required (input device) for PWM to work.
Thanks for all your help so far.
Hardware such as what gert used in his video (the slider at 3:40):
-
Re: Wiring a motor to the RPi?
wallarug Sep 10, 2012 5:52 AM (in response to KenSeymour)Just an update on what I am going to use to built this circuit:
2 x 12v motors
1 x 12v power supply (batery pack)
1 x L293D (double H-bridge chip) http://www.adafruit.com/datasheets/l293d.pdf < Datasheet
1 x ULN2003 (Darlington Transistor - instead of normal transistors) http://www.jaycar.com.au/products_uploaded/ZK8855.pdf < Datasheet
Whatever restiors anyone suggests (I will buy when necessary)
Headers & PCB
1 x Raspberry Pi
Can someone let me know if anything else is required.
I have just bought some more stuff that I though you should know:
Just an update on what I am going to use to built this circuit:
4 x 100ohm 1 Watt 5% Carbon Film Resistor - Pk. 2
4 x 680ohm 1 Watt 5% Carbon Film Resistor - Pk. 2
4 x 2K2ohm 1 Watt 5% Carbon Film Resistor - Pk. 2
1 x ULN2003 Darlington transistor array IC
Any of this can be used in the circuit. If anything else is required, let me know.
-
-
-
Re: Wiring a motor to the RPi?
michaelkellettSep 10, 2012 2:46 AM (in response to KenSeymour)
@Ken
There is an error in this diagram: pin 8 should be connected to 12V and pin 16 to 5V - why - because pin 16 is what ST (the chip maker) calls Vss and is the logic supply voltage and pin 8 is Vs which is the motor supply voltage.
This circuit would be improved by changing the 100R resistors for a higher value, 2k2 would be fine and would reduce the current in the 2N2222A2N2222A transitors from 50mA to 2.3mA while still being able to pull the L293 inputs high. (They need 100uA max).
Michael Kellett
-
Re: Wiring a motor to the RPi?
wallarug Sep 10, 2012 3:30 AM (in response to michaelkellett)Just an update on what I am going to use to built this circuit:
2 x 12v motors
1 x 12v power supply (batery pack)
1 x L293D (double H-bridge chip) http://www.adafruit.com/datasheets/l293d.pdf < Datasheet
1 x ULN2003 (Darlington Transistor - instead of normal transistors) http://www.jaycar.com.au/products_uploaded/ZK8855.pdf < Datasheet
Whatever restiors anyone suggests (I will buy when necessary)
Headers & PCB
1 x Raspberry Pi
Can someone let me know if anything else is required.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Re: Wiring a motor to the RPi?
evan.stoddard Aug 26, 2012 6:10 PM (in response to wallarug)I think with the new gert board, it comes with software so you should be able to run it just fine.
-
Re: Wiring a motor to the RPi?
wallarug Aug 26, 2012 6:17 PM (in response to evan.stoddard)i have bought one
I guess I will just wait.
-
Re: Wiring a motor to the RPi?
evan.stoddard Aug 26, 2012 6:25 PM (in response to wallarug)Hope it all works out for you
I don't have a gertboard or an RPi so I'm afraid I can't offer a great amount of help.
-
Re: Wiring a motor to the RPi?
wallarug Aug 27, 2012 2:10 AM (in response to evan.stoddard)That's ok, I have a friend helping me work this out. I think he has almost got it. I will post the results when he completes the build.
-
-
-
-
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 15, 2012 7:45 PM (in response to wallarug)Sorry, I have been out of town most of the week.
I have an update to the schematic to correct errors caught by Michael Kellet.
He made me think about small amount of current heeded by the L239D chip.
Another way to think of it is a high impeadance input. So we don't need
a lot of current gain in the transistor.
While darlingtons are high current gain.
The current on the chip input/transistor output will be set low by the high chip input impeadance.
When you use a transistor as a switch, you set the Ib * Hfe to be larger than where the ciruit
will operate in order for the transistor to alternate between cut off and saturation.
So I upped the resistor values but did not set Ib * Hfe to match the current needed by the
chip but rather to provide 10 or more times as much.
The real current will by limited by the chip input impeadance and you have a low voltage
dropped across R4/R5/R6.
Ib is the transistor base current.
Hfe is the transistor current gain.
By lowering the base current, we ask the Raspberry Pi to provide less current.
I drove motors with an Arduino. It runs on 5 Volts. It has analog inputs. It has lots of PWM
outputs. It won't run Linux or Python.
I have not yet tried the one PWM output on the Pi. I don't know if a PWM driver is ready or not.
An 8 but micro-controller normally has PWN hardware outputs.
Software pwm is where you turn the GPIO output off and on and increase the speed
by having it on a higher percentage of the time.
I've thought of connecting an Arduino to the PI with 5 Volt serial or I2C and having the
Arduino do motor control but probably not get to it.
I have driven stepper motors directly of a GPIO with Darlingtons but without an H bridge chip.
Any way here is the updated schenmatic in PNG. I am trying to attach the Eagle schematic.
-
Re: Wiring a motor to the RPi?
wallarug Sep 16, 2012 4:25 AM (in response to KenSeymour)How would I subsitute in a Darlington Pair into your schematic? I have a ULN2003 Darlington IC transistor array. See the datasheet below: http://www.jaycar.com.au/products_uploaded/ZK8855.pdf
Also, If I want to run two motors through PWM, then I would have to 'piggy back' off the circiut that is already present. See My Schematic (experimental) based off yours below. I think this becasue the raspberry Pi (as far as I know) only supports 1 'connection' of PWM. Am I correct?
One other thing, is the 5 volts coming out of the Raspberry Pi or an externatal source?
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 16, 2012 6:22 PM (in response to wallarug)I couldn't find an Eagle part model for the darlingtons.
The seen to have all the bias resistor internally. You are not connecting them to the motor directly,
so you don't need external diodes.
So 5 Volt supply to ULN2003 pin 9.
Ground to ULN2003 pin 8.
Rasberry Pi pin 7 to ULN2003 pin 1.
Rasberry Pi pin 5 to ULN2003 pin 2.
Rasberry Pi pin 3 to ULN2003 pin 3.
ULN2003 pin 16 to L293D pin 1.
ULN2003 pin 15to L293D pin 2.
ULN2003 pin 14to L293D pin 7.
You don't need the external resistors.
-
Re: Wiring a motor to the RPi?
wallarug Sep 16, 2012 10:04 PM (in response to KenSeymour)Thanks Ken,
I haven't got the H-bridge yet, but I will test when I get it.
-
-
-
Re: Wiring a motor to the RPi?
KenSeymour Sep 17, 2012 9:13 AM (in response to wallarug)You need to tie pins 4, 5, 12, and 13 to ground.
-
Re: Wiring a motor to the RPi?
wallarug Sep 17, 2012 5:34 PM (in response to KenSeymour)I know that.
It was to much time to add to the diagram.
-
-
-
-
-
Re: Wiring a motor to the RPi?
wallarug Sep 27, 2012 5:05 AM (in response to KenSeymour)I have not yet tried the one PWM output on the Pi. I don't know if a PWM driver is ready or not.
An 8 but micro-controller normally has PWN hardware outputs.
Software pwm is where you turn the GPIO output off and on and increase the speed
by having it on a higher percentage of the time.
I need to know how PWM will work in the circuit. So the Raspberry Pi has ONE (1) PWM channel. Does this work in a pair or on a single wire tied to ground?
If I want to control the two motors individually then I will need a mircocontroller. Correct?
-
Re: Wiring a motor to the RPi?
wallarug Sep 27, 2012 5:57 AM (in response to KenSeymour)Ok. I just read this article: https://projects.drogon.net/raspberry-pi/wiringpi/software-pwm-library/ Which says this:
WiringPi includes a software-driven PWM handler capable of outputting a PWM signal on any of the Raspberry Pi’s GPIO pins.
Is this even possible?
-
Re: Wiring a motor to the RPi?
michaelkellettSep 27, 2012 6:34 AM (in response to wallarug)
It's certainly possible - the article explains that it is limited because it is a software controlled PWM so can only do 100Hz with a minimum pulse width of 100uS for a range of 100:1. A modest micro might be expected to manage 40kHz, 1uS minimum pulse width and 256:1 range. Fancy micros and DSPs can do much better.
The software aaproach should be just about OK for lamp control but I'd be a bit cautious with motors - some will be OK but not all.
The RPi IO is pretty hopeless - the sodtware PWm is making the best of a bad job but it could well be OK for some things.
Michael Kellett
-
Re: Wiring a motor to the RPi?
wallarug Sep 27, 2012 11:10 PM (in response to michaelkellett)The RPi IO is pretty hopeless - the sodtware PWm is making the best of a bad job but it could well be OK for some things.
I will give software PWM a miss. It looks like a messy job and probaby will not work with 12v motors that spin @160rpm.
-
-
-
-
Re: Wiring a motor to the RPi?
yvanttt Sep 27, 2012 11:37 AM (in response to wallarug)One option is to use the gertboard and drop in an atmega 328.
With this setup the PI will be the brain part and the arduino the muscle portion of the setup.
the Gertboard has already 2 motor interface on it.
And the arduino has 6 PWM build in.
It will then be easy for the PI to just send the PWM values to the arduino via the serial port or I2C as you wish.
-
Re: Wiring a motor to the RPi?
wallarug Sep 27, 2012 11:08 PM (in response to yvanttt)48. Sep 27, 2012 4:37 PM (in response to Fergus Byrne)
Re: Wiring a motor to the RPi?
One option is to use the gertboard and drop in an atmega 328.
With this setup the PI will be the brain part and the arduino the muscle portion of the setup.
the Gertboard has already 2 motor interface on it.
And the arduino has 6 PWM build in.
It will then be easy for the PI to just send the PWM values to the arduino via the serial port or I2C as you wish.
The problem is: How do I do that?
-
Re: Wiring a motor to the RPi?
wallarug Oct 6, 2012 3:40 AM (in response to yvanttt)Ok,
I have bought a freetronics 'Eleven' which is exactly the same as the Uno. Here is what I want to do:
1. Two motors + one servo:
The two motors will be moving the robot and will be changing speed according to the position of a Joystick. The servo will either be the steering or for the camera (depending on whether or not it is possible to turn with the two motors and PWM). Both will be connected
2. The Joystick:
It will be connected to a PC running Linux (which I still have to setup) and controlling the direction and speed of the robot on the x-axis (forward/backward) and y-axis(left/right).
3. Camera
I have not got the camera working correctly yet (speed issues) but I will get this to work. I think that it is a combination of incorrect settings and network lag (I will see to this).
4. The Eleven
All the motors will be connected to this including the servo. The Two motors will be connect to PWM channel via the double H-bridge chip. I have a schematic to do this.
5. Software
I have no clue on how the software will work except that I need 3 pieces: Ardunio, raspberry Pi and PC. All I know is that I want dynamic speed control with the joystick. The formula that I came up with was:
(100/255)*i
where 'i' = position of co-ordinate of Joystick on the y-axis.
This will give out a percentage number which I want to replicate the percentage that motors are "ON" through PWM. I don't know if this can be done but I would like advice on how to go about it.
-
Re: Wiring a motor to the RPi?
ingramator Oct 7, 2012 7:10 PM (in response to wallarug)Hey Cdog, we have changed this to using a Windows Client and interfacing the joystick through Pygame. The joystick movement will then result in a changing modulation.
-
Re: Wiring a motor to the RPi?
wallarug Oct 11, 2012 4:57 AM (in response to wallarug)I have started a new thread here:
http://www.element14.com/community/thread/20181
and here:
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=19725
If anyone can help me with the issues in these threads I will be happy.
-
-
-
Re: Wiring a motor to the RPi?
yvanttt Oct 2, 2012 11:48 AM (in response to wallarug)as an example use pins 5 and 6 (pins 20 and 22 on J25) on the atmega328 and connect them to the motor_a and motor_b input (J5) on the gertboard.
Then the uart TXD (gpio pin22) of the raspberry to the RXD (pin 2 of the atmega, pin 1 of J64)
Then it is a simple mater to program the atmega328 to intercept the bytes sent from the raspbery and copy them to the 2 PWM ports.
-
Re: Wiring a motor to the RPi?
wallarug Oct 3, 2012 2:53 AM (in response to yvanttt)Don't have a gertboard and won't get it for a while (Farnel issue). But I am going to get an adruino eleven with ATMEGA328p which will help me do what I want. I will look at your links though.
The only problem I have with coding such a chip. I have no experience and will require massive amount of help with the coding in python (I know some already) or C (which sounds easy to learn).
-
-
Re: Wiring a motor to the RPi?
yvanttt Oct 3, 2012 7:34 AM (in response to wallarug)These Arduino are the easiest to program.
They made an IDE package that works on Windows, OS max and Linux 32 or 64 bits. These devices uses C
They have all the major function already available on their site "www.arduino.cc".
Plus they have "sheild" that can get you started then use the sheild schematics to build your permanent setup.
-
Re: Wiring a motor to the RPi?
wallarug Oct 3, 2012 9:08 PM (in response to yvanttt)Ok, here is my idea:
Using some of the set-up features that @aonsquared used with his Robot/Rover thing.
Using a 5 volt supply to power the Raspberry Pi and the Powered hub.
The Raspberry Pi will send commands to the Ardunio Eleven (which I still have to get), which will control the Two Motors through a H-bridge and PWM.
That camera will be powered through the 10 port hub, along with the Ardunio and the W/LAN dongle.
The Motors will be powered though a 12 volt supply (8 AA batteries).
All the commands will be sent through an Ad-Hoc Network to a Laptop running Windows 7 Pro 64 bit. I think that I will use by Joystick to move the Motors but I don't know how that is going to work as @aonsquared used a PS3 controller instead. (Saitek ST90 is the Joystick).
The LCD display will have the IP address so that I know exactly what it is whenever.
The Raspberry Pi will host a live webcam feed though an old Logitec Camera I have lying around.
One question is: Will PWM work on the motors through the Ardunio if I have the 12 volts going directly into the H-bridge Chip?
What do you think?
-
-
Re: Wiring a motor to the RPi?
yvanttt Oct 5, 2012 11:50 AM (in response to wallarug)Yes it can be done.
Look at this chip the L298, it can accept input voltage for the motor up to 46 volts. The logic side is at 5 votls so it is safe for your Arduino.
You can drive up to 2 amps per output.
This chips can 2 motors or you can connect the outputs in parallel to double the current.
The datasheet even has some circuits examples to try.
http://www.datasheetcatalog.org/datasheet2/2/052daje928cw7pc0uqs1ipyryppy.pdf
-
Re: Wiring a motor to the RPi?
yvanttt Oct 5, 2012 12:02 PM (in response to wallarug)For the motor control via the joystick it is easy if you can convert the joystick position into values from 0 to 255.
for example:
move the stick forward, both PWM will increase simulatneously. this will increase your speed.
move the stick to the left or right, then deduct the values on one motor to make it turn.
-
Re: Wiring a motor to the RPi?
wallarug Oct 5, 2012 8:26 PM (in response to yvanttt)Would you be able to help me code this?
Also, if the neutral position of the stick is (0,0) then that would mean the range would be from -255 to +255 on both the x- and y-axis. Right?
-
Re: Wiring a motor to the RPi?
wallarug Oct 5, 2012 8:33 PM (in response to wallarug)Every position going up and down the x- / y-axis (+/- 255) will increase the motor speed by an incriment of
100/255 = 0.392157
Is this formula able to be included to decide on the speed of the motor? I will improve it so that it works for all situations.
-
-
Re: Wiring a motor to the RPi?
wallarug Oct 5, 2012 9:11 PM (in response to yvanttt)Yvan Turcot wrote:
For the motor control via the joystick it is easy if you can convert the joystick position into values from 0 to 255.
for example:
move the stick forward, both PWM will increase simulatneously. this will increase your speed.
move the stick to the left or right, then deduct the values on one motor to make it turn.
I just wiped up this python script.
# Converting Joystick Position to a Percentage that the PWM
# Channel can simluate on the motors
# By Wallarug
# Change the input value "i" to something that relates to the Joystick
f = float(100)/float(255)
i = input("Enter a number between -255 and +255: ")
while i!="":
x = float(f)*int(i)
print "PWM, " + str(x) + "%"
i = input("Enter a number between -255 and +255: ")
# By Wallarug
Should work if it is converted to a different language and add in the motor commands and Joystick.
-
What do I need?
I am told that I need some transitors. I have a 12v powerpack and 2 x12v motors. How do I set this up so that I don't blow-up the RPi and that I can control the motors through the GPIO?
I have a gertboard on the way but I would like to see if I can do it without it first.
I have little knowlegde about transitors and electronics but I do know how to build circuits.