Using Raspberry Pi to control electric devices


6 posts
by RaceOfAce » Fri Apr 27, 2012 11:17 pm
Hi everyone, I was just wonder if there is a way to use the Raspberry Pi to control (turn off and on) a DC motor. The DC motor needs 9 volts to spin at the rate I need to. Would this be something you could use GPIO and a transistor to achieve?

At any rate, I need to learn a lot more about electronics......
Posts: 2
Joined: Fri Apr 27, 2012 10:08 pm
by Techmeology » Fri Apr 27, 2012 11:48 pm
Yes it is, but be careful not to blow up your RPi! Consider using a Gertboard, or at the very least a buffering circuit. http://elinux.org/RPi_Tutorial.....n_Circuits
Check out cool stuff I'm doing, e.g my PIC Programmer for the Raspberry Pi: http://www.techmeology.co.uk/rpipic/
Posts: 30
Joined: Wed Mar 28, 2012 8:52 pm
by rew » Sat Apr 28, 2012 11:19 am
Or rpi_serial http://www.bitwizard.nl/catalo.....ucts_id=69 and a 3fets board

http://www.bitwizard.nl/catalo.....ucts_id=72 or

a 7fets board http://www.bitwizard.nl/catalo.....ucts_id=67

Chose the one that matches the amount of current you're going to need.

I'm still working on the kernel-space RPI drivers, but that should show some progress in the next two weeks or so.

In the meantime there are already commandline tools to send SPI commands to the boards, to make them do what you want.
Check out our raspberry pi addons: http://www.bitwizard.nl/catalog/
User avatar
Posts: 391
Joined: Fri Aug 26, 2011 3:25 pm
by Techmeology » Sat Apr 28, 2012 1:59 pm
If you choose to use GPIO16, you'll have to try a method like the C method (or possibly the Python method might work) which works by directly writing to the memory mapped registers, as echo 16 > /sys/class/gpio/export yields an error.
Check out cool stuff I'm doing, e.g my PIC Programmer for the Raspberry Pi: http://www.techmeology.co.uk/rpipic/
Posts: 30
Joined: Wed Mar 28, 2012 8:52 pm
by RaceOfAce » Sat Apr 28, 2012 11:53 pm
Is it necessary to use those boards for protection, or can I just use a resistor?? It's only one device and I'm not sure how much work I'll be doing after that.

As for controlling GPIO through code, I would prefer to use Python for the coding, but the package page says that the module is unsuitable for real time application. How fast is that?

Also, the C code is mapped to the SoC's GPIO outputs so how do those translate to the pins on the header?
Posts: 2
Joined: Fri Apr 27, 2012 10:08 pm
by bobc » Sun Apr 29, 2012 9:22 am
RaceOfAce said:


Is it necessary to use those boards for protection, or can I just use a resistor?? It's only one device and I'm not sure how much work I'll be doing after that.

As for controlling GPIO through code, I would prefer to use Python for the coding, but the package page says that the module is unsuitable for real time application. How fast is that?

Also, the C code is mapped to the SoC's GPIO outputs so how do those translate to the pins on the header?


Since this is the beginners section, I would recommend using an external board. Some of the boards are just a breakout board for a MOSFET, but at least you know they have a chosen a MOSFET suitable for the job.

At the very least, you will need a MOSFET which can be connected to a logic level voltage. If you are driving a relay or motor, then you need diode protection which may be built-in to the MOSFET or not. You probably also want a resistor to turn the MOSFET off when the CPU is not driving the GPIO.

Real time in this case really means anything much less than 100 ms, so if you just want to turn a motor on or off every few seconds then it should be fine.

There is a diagram of the header here http://elinux.org/Rpi_Low-leve.....eripherals.

(I find the description there really confusing, but the pin next to "P1" marked on the board actually is Pin 1 of connector P1 which is the 3V3 pin shown as yellow square on the diagram, which might help you get the orientation).

ETA: there is a cheap MOSFET board here http://proto-pic.co.uk/mosfet-.....ntrol-kit/.
Posts: 87
Joined: Fri Apr 06, 2012 8:01 am