User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

my simple program in GEANY

Tue Sep 08, 2015 5:54 am

Hi
I write a simple code that only turns on an LED for me
by C in geany

this is my code:

Code: Select all

#include <bcm2835.h>
int main(int argc,char **argv){
if (!bcm2835_init()) return 1;
bcm2835_gpio_fsel(18,BCM2835_GPIO_FSEL_OUTP);

while(1){
bcm2835_gpio_set(18);
}
}

there is no error in compile and build
but when I run this code , my led is off !! and dont change
my circiut is right :!:
whats your idea ?? :?: :?:
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: my simple program in GEANY

Tue Sep 08, 2015 7:34 am

Perhaps try this:

Code: Select all

#include <bcm2835.h>

int main(int argc,char **argv){
	if (!bcm2835_init()) return 1;

	bcm2835_gpio_fsel(18,BCM2835_GPIO_FSEL_OUTP);

	while(1) {
//		bcm2835_gpio_set(18);
		bcm2835_gpio_write(18, 1);
	}
	
}
Not sure why you code the while forever loop, you could do without in this sample.

Succes!

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: my simple program in GEANY

Tue Sep 08, 2015 9:09 am

GerardWassink wrote:Perhaps try this:

Code: Select all

#include <bcm2835.h>

int main(int argc,char **argv){
	if (!bcm2835_init()) return 1;

	bcm2835_gpio_fsel(18,BCM2835_GPIO_FSEL_OUTP);

	while(1) {
//		bcm2835_gpio_set(18);
		bcm2835_gpio_write(18, 1);
	}
	
}
Not sure why you code the while forever loop, you could do without in this sample.

Succes!

Gerard
I tested it but my LED wass off too !!
while loop : because first I write a flasher code and when I see it doesnt work I change it
I tested the LED too
thanks for your help
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
Mahan_Micro
Posts: 44
Joined: Tue Aug 04, 2015 8:52 pm

Re: my simple program in GEANY

Thu Sep 10, 2015 8:45 pm

ise there any idea for my problem??
my gpio is right , with python I test it but in C don't work !!
If your Dreams Don't Scare You , They Aren't Big Enough

User avatar
buja
Posts: 532
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: my simple program in GEANY

Thu Sep 10, 2015 9:05 pm

Maybe it's a rights issue, can you run it with sudo from the command line?

Code: Select all

sudo yourprogram

Return to “Beginners”