Page 1 of 1

gpio

Posted: Thu Aug 02, 2012 12:58 am
by ChadP
Dumb question but how do i use the gpio pins, where do i put the code in, im running wheezy. Can i use arduino code that i have already.

Re: gpio

Posted: Thu Aug 02, 2012 1:15 am
by mahjongg
Can i use arduino code that i have already.
No you can't, at least not if its assembly language, as the Arduino uses a different RISC architecture.
You might be able to re-use some C code though.
The GPIO's are controllable through sets of library's, different ones for different languages.
perhaps reading some of the magpie magazines might help.

Re: gpio

Posted: Thu Aug 02, 2012 2:06 am
by ChadP
Ok thanks, so on wheezy id use python to controll the pins, is that correct

Re: gpio

Posted: Thu Aug 02, 2012 2:12 am
by mahjongg
You can use any language you like, as long as there are libraries to control the GPIO, or if you know how to do the "bare metal programming".
There is documentation describing how to do that, in the form of the Broadcom BCM2835 "datasheet", that can be found on the net (and probably the Wiki).

Re: gpio

Posted: Thu Aug 02, 2012 3:56 pm
by DexOS
If you want to go the bare metal route, i am work on a project that uses a basic like language, but for things like GPIO its very similar to how you would code the arduino.

Example to flash LED:

Code: Select all

include 'DexBasic\DexBasic.inc'                  
                                                   ;
pinMode  GPIO16, OUTPUT                            ; set as output
                                                   ;
LetsLoop:                                          ; a label
                                                   ;
digitalWrite  GPIO16, HIGH                         ; set LED on
delayMicroseconds  1000000                         ; waits 1 second
digitalWrite  GPIO16, LOW                          ; set  LED off
delayMicroseconds  1000000                         ; waits 1 second
                                                   ;
goto  LetsLoop                                    
                                                   ;
align 4                                           
ProgramSize:                                      
ScreenBuffer:                                    
So arduino code would be easy to convert.
If you need more info just ask.

Re: gpio

Posted: Tue Aug 14, 2012 11:03 pm
by dimonic
The answer you are looking for is the https://projects.drogon.net/raspberry-pi/wiringpi/ library. It comes with a command line utility (gpio) as well.

Re: gpio

Posted: Tue Aug 14, 2012 11:41 pm
by exartemarte
ChadP wrote:Dumb question but how do i use the gpio pins, where do i put the code in, im running wheezy. Can i use arduino code that i have already.
The Arduino language is a version of C. There is an article showing you how to write, compile and execute a C program on the Pi in issue 3 of The MagPi, page 22.

You can port Arduino programs to the Pi, although you may need to tinker with them a bit and of course anything that directly accesses the atmega hardware won't work because the Pi hardware isn't the same.

See my answer in a another thread to some one who asked a similar question.