ChadP
Posts: 57
Joined: Sat Jul 07, 2012 2:30 pm
Location: West Virginia. United States
Contact: Yahoo Messenger

gpio

Thu Aug 02, 2012 12:58 am

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.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13379
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: gpio

Thu Aug 02, 2012 1:15 am

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.

ChadP
Posts: 57
Joined: Sat Jul 07, 2012 2:30 pm
Location: West Virginia. United States
Contact: Yahoo Messenger

Re: gpio

Thu Aug 02, 2012 2:06 am

Ok thanks, so on wheezy id use python to controll the pins, is that correct

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13379
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: gpio

Thu Aug 02, 2012 2:12 am

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).

User avatar
DexOS
Posts: 876
Joined: Wed May 16, 2012 6:32 pm
Contact: Website

Re: gpio

Thu Aug 02, 2012 3:56 pm

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.
Batteries not included, Some assembly required.

dimonic
Posts: 41
Joined: Fri Jun 08, 2012 9:08 pm

Re: gpio

Tue Aug 14, 2012 11:03 pm

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.

User avatar
exartemarte
Posts: 376
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: gpio

Tue Aug 14, 2012 11:41 pm

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.

Return to “Raspberry Pi OS”