Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 59 additions & 61 deletions 2-gpio/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,63 @@

int main(int argc, char **argv)
{

int i;

if (!bcm2835_init())
return 1;

// Set the pins to be an output
bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);

while(1)
{
bcm2835_gpio_set(PIN0);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN0);
bcm2835_delay(500);

bcm2835_gpio_set(PIN1);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN1);
bcm2835_delay(500);
bcm2835_gpio_set(PIN2);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN2);
bcm2835_delay(500);

bcm2835_gpio_set(PIN3);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN3);
bcm2835_delay(500);

bcm2835_gpio_set(PIN4);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN4);
bcm2835_delay(500);

bcm2835_gpio_set(PIN5);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN5);
bcm2835_delay(500);

bcm2835_gpio_set(PIN6);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN6);
bcm2835_delay(500);

bcm2835_gpio_set(PIN7);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN7);
bcm2835_delay(500);
}

bcm2835_close();
return 0;
int i;

if (!bcm2835_init())
return 1;

// Set the pins to be an output
bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);

while(1)
{
bcm2835_gpio_set(PIN0);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN0);
bcm2835_delay(500);

bcm2835_gpio_set(PIN1);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN1);
bcm2835_delay(500);
bcm2835_gpio_set(PIN2);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN2);
bcm2835_delay(500);

bcm2835_gpio_set(PIN3);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN3);
bcm2835_delay(500);

bcm2835_gpio_set(PIN4);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN4);
bcm2835_delay(500);

bcm2835_gpio_set(PIN5);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN5);
bcm2835_delay(500);

bcm2835_gpio_set(PIN6);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN6);
bcm2835_delay(500);

bcm2835_gpio_set(PIN7);
bcm2835_delay(500);
bcm2835_gpio_clr(PIN7);
bcm2835_delay(500);
}

bcm2835_close();
return 0;
}

25 changes: 12 additions & 13 deletions 2-gpio/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@

int main(int argc, char **argv)
{

int i;

if (!bcm2835_init())
return 1;

// Set the pins to be an output
bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);

while(1)
{
{
//turn the even leds on
//turn the odd leds off
bcm2835_gpio_write(PIN0, HIGH);
Expand Down Expand Up @@ -79,8 +78,8 @@ int main(int argc, char **argv)

// wait a little bit
bcm2835_delay(500);
}
bcm2835_close();
return 0;
}

bcm2835_close();
return 0;
}

18 changes: 8 additions & 10 deletions 3-lightsensor/light.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

int main(int argc, char **argv)
{


if (!bcm2835_init())
return 1;
if (!bcm2835_init())
return 1;

char temp[1]; //temporary values
int ret;
int ad[2];
Expand All @@ -36,21 +35,21 @@ int main(int argc, char **argv)
temp[0] = 0xa0; //select the control register
bcm2835_i2c_write(temp,1);
temp[0] = 0x03; //Power up the device
bcm2835_i2c_write(temp,1);
bcm2835_i2c_write(temp,1);
bcm2835_delay(500);

bcm2835_i2c_read(temp,1);
printf("%x - if 33 the device is turned on\n",temp[0]);

temp[0] = 0xac; //Channel 0 lower byte
bcm2835_i2c_write(temp,1);
bcm2835_i2c_write(temp,1);
bcm2835_i2c_read(temp,1);

ad[1]= (int)temp[0];

temp[0] = 0xad; //channel 0 upper byte
bcm2835_i2c_write(temp,1);
bcm2835_i2c_read(temp,1);
temp[0] = 0xad; //channel 0 upper byte
bcm2835_i2c_write(temp,1);
bcm2835_i2c_read(temp,1);

ad[0] = (int)temp[0];
printf("ad value:%d\n",ad[0]*256+ad[1]);
Expand All @@ -60,4 +59,3 @@ int main(int argc, char **argv)

return 0;
}

10 changes: 5 additions & 5 deletions 4-temperature/temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $

/*******************
length command extra 0-rw-register-cr-00
length command extra 0-rw-register-cr-00
Read the status(0) 2 0x40 ro 0100 0000
read the configur(1) 2 0x48 r 0100 1000
write the confi 2 0x08 w 0000 1000
Expand All @@ -38,7 +38,8 @@ write the Tlow 3 0x38 w 0011 1000
int main(int argc, char **argv)
{
if (!bcm2835_init())
return 1;
return 1;

char buffer[4];
buffer[0] = 50;
int i,temp;
Expand All @@ -62,10 +63,10 @@ int main(int argc, char **argv)
{
buffer[0] = 0x50; //read the temp
bcm2835_spi_transfern(buffer,3);
printf("status %02X %02X\n",buffer[1],buffer[2]);
printf("status %02X %02X\n", buffer[1], buffer[2]);
temp = buffer[1];
temp = temp<<8;
temp = temp + ( buffer[2] & 0xF8);
temp = temp + ( buffer[2] & 0xF8);
printf("status %08x\n",temp);
temp = temp>>3;
temp = temp/16;
Expand All @@ -77,4 +78,3 @@ int main(int argc, char **argv)
bcm2835_close();
return 0;
}