robertsirwin
Posts: 5
Joined: Tue Jan 29, 2013 2:51 pm

Simple GPIO Example

Tue Jan 29, 2013 3:21 pm

Hi folks...first time here...hope this is an ok forum for this request. I have been trying to get something (anything) to happen out of a GPIO port. I don't have a breadboard but finally bought a kit (coming tomorrow)...in the mean time I'm dying to just get something to happen...very impatient.

I know quite a bit about computing but very little about electronics. My kids have an electronics kit with snap together circuits, lights, motors, switches, etc. That kit has a little power adapter that takes 2 AA batteries...I assume that's comparable to the 3.3v Pi uses. If I connect the motor to the power it runs.

I've been reading lots and lots about the RPi GPIO board and from what I can tell I should be able to make a specific pin HIGH which should then output appx. 3.3v. Pin 1 seems to be hot always with 3.3v. So using alligator clips I connect Pin 1 -> motor -> Pin 6 (GND) ... when I connect things up like this the motor spins. So I know that my connections are good and nothing blows. I can connect/disconnect the motor between pin1 and 6 and it runs.

OK...now I think I should be able to do the same thing with another pin ... say Pin 11. (GPIO17 I think) ... I have downloaded the various RPi.GPIO libraries and tried using wiringPi and command line python to send a HIGH signal to that Pin11. My theory is that Pin11 should start outputting 3.3v and power that motor.

Am I missing something very basic here? If I am using the software correctly ... should I be getting 3.3v from that Pin11 ??? or is that not how it works? I realize it's not probably safe...but should I be able to do a proof of concept with just a couple wires and a motor? or do I have to use a breadboard and wire everything up on a breadboard with resisters and such??

Thank you for your time,

ER

PS: My ultimate goal is to teach a week long summer camp class at my sons' school on the RPi. Basically introduction to the Pi, Scratch, basic Python, XBMC, etc ... and as a stretch goal I was hoping to get the kids to finish off the week by doing some GPIO stuff. I'm trying to keep cost and time down as much as possible so I was hoping to do a very basic proof of concept without going the whole breadboard kit route. I was hoping I could connect a couple wires to a motor, write some Python code and watch the motor spin. Just enough to let the kids see their software making something physical happen.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple GPIO Example

Tue Jan 29, 2013 4:17 pm

You could flash gpio16, the green LED on the board.

The gpios are all 3.3V and only supply a few milliamps (circa 20 mA). You will only be able to drive a tiny motor. It would NOT be safe though. The motor back voltage when it stops may fry your Pi.

Look for a cheap ULN2003A chip and use that to drive motors in a single direction, or buy a motor driver board. Both use the gpios as control signals and switch the power internally.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple GPIO Example

Tue Jan 29, 2013 4:22 pm


robertsirwin
Posts: 5
Joined: Tue Jan 29, 2013 2:51 pm

Re: Simple GPIO Example

Tue Jan 29, 2013 11:19 pm

Thank you for the info and link...great info. As it turns out it was working all along...you were right about the motor...I switched to an LED and it worked great. Again I know it's probably not terribly safe...but I really wanted to see it work. So I put two alligator clips on pins 12 and 6...ran my python program...then touched my LED ends to the alligator clips...and viola...LED turned on and off as expected based on the code.

I'm really looking forward to getting my breadboard kit tomorrow and learning more about the electronics side.

Thanks,

ER

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple GPIO Example

Tue Jan 29, 2013 11:49 pm

I admire and applaud your experimentation. Please warn me if your name is Monty Burns and you buy my local power station though. :D

1HzCoder
Posts: 31
Joined: Thu Jul 12, 2012 1:15 am
Location: Lower Alabama

Re: Simple GPIO Example

Wed Jan 30, 2013 1:22 am

One word: RESISTOR
Some things to learn before hooking anything up to electronics.

The ratio of V(olts) = I (amps) * R(esistance) , V=IR, commonly , though incorrectly, known as Ohms Law. Then learn how to use it to figure the resistors needed to keep your current on the output pins below 75% of the max current (16mA) that the Pi can source or sink. You don't run your car engine red-lined all the time, do you?

How to find , read, and understand datasheets.

Basic symbols and their use in drawing circuits on paper first.

How to use search engines to find tutorials on the thousands of different things that can be done with the micro-controller of your choice.

How, why and when to use resistors, transistors, relays, diodes, and capacitors to protect your Pi from over current, over voltage, back-emf, voltage spikes and sags, ect.

I guess it is probably best to just say, get some of the excellent books on wiring things up to the Pi.
Easily found by a basic search of your favorite online bookstore. I like Simon Monks books, but that is just me.

Most of all, have fun, you will eventually learn all this stuff, I just prefer doing it before the magic blue smoke comes rolling out of everything. :o
TomJ
Einstein once said you don't really understand anything until you can explain it to your Grandmother

sim_tcr
Posts: 331
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: Simple GPIO Example

Wed Jan 30, 2013 7:06 am

I have posted two very simple GPIO examples in my website.

http://raspisimon.no-ip.org/singleled.php
http://raspisimon.no-ip.org/threeled.php

hope this helps.
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

RussoNC
Posts: 48
Joined: Fri Sep 07, 2012 6:53 am
Location: New Caledonia
Contact: Website

Re: Simple GPIO Example

Wed Feb 06, 2013 11:16 am

sim_tcr Thanks you !!!! I was searching for something easy to understand and I saw your web page, very nice and simple to understand, thank you again !! xD
Whant to see MySQL, nginx in action on the Raspberry pi ? Check my site: www.pirepository.com

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple GPIO Example

Wed Feb 06, 2013 11:29 am

RussoNC wrote:sim_tcr Thanks you !!!! I was searching for something easy to understand and I saw your web page, very nice and simple to understand, thank you again !! xD
Ditto. Clear examples.

sim_tcr
Posts: 331
Joined: Tue Nov 06, 2012 1:01 pm
Location: Bangalore
Contact: Website

Re: Simple GPIO Example

Wed Feb 06, 2013 11:37 am

joan wrote:
RussoNC wrote:sim_tcr Thanks you !!!! I was searching for something easy to understand and I saw your web page, very nice and simple to understand, thank you again !! xD
Ditto. Clear examples.
Courtsey to Gordon at https://projects.drogon.net/ I have given the original url at the end of my page.
http://raspisimon.no-ip.org
Raspberry Pi Model B x 2, Raspberry Pi 2 x 2, Transcend 32GB Class 10, Transcend 16GB Class 10, Transcend 8GB Class 4, Custom 12V 1.5A (stepped down to 5.5V)

Return to “General discussion”