Ejemplo n.º 1
0
int main ()
{
	//Initialise the Raspberry Pi GPIO
	if(!bcm2835_init())
		return 1;
	
	printTempAndHumidity();

	return 1;
}
Ejemplo n.º 2
0
int main(void) {
	if (!bcm2835_init())
		return 1;

	flipdot_init();
	flipdot_clear_to_0();
	flipdot_shutdown();

	return(0);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
  // If you call this, it will not actually access the GPIO
  // Use for testing
  // bcm2835_set_debug(1);

  int a[MAX_SAMPLES];
  int k;
  for (k=0;k<MAX_SAMPLES;++k)
    a[k] = 100000 + k;
 
  struct timeval tv ;
  gettimeofday (&tv, NULL) ;
  epoch = (tv.tv_sec * 1000000 + tv.tv_usec) / 1000 ;

  if (!bcm2835_init()) return 1;

 // Set the pin to be an input
  bcm2835_gpio_fsel(PIN_15, BCM2835_GPIO_FSEL_INPT);  // Ausgang IR Empfänger


  // Funktioniert als IR Repeater. IR Empfangsmodul ist an IN PIN_15
  // OUT PIN_22 steuert 38kHz Oszillator
  while (1) {
    int i=0;
    int msBegin = millis();
    int msEnd = 0;
    a[i] = bcm2835_gpio_lev(PIN_15);
    if (a[i] == 0) {
      ++i;
      while (i < MAX_SAMPLES) {
        a[i] = bcm2835_gpio_lev(PIN_15);
        ++i;
        int p,q;
        for (p=0; p < 1000; ++p)
          q=p;
      }
      msEnd = millis();
      
      printf("%d - %d, %d samples, %d ms per 100 samples\n", msBegin, msEnd, MAX_SAMPLES, (msEnd-msBegin)*100/MAX_SAMPLES);
      int j;
      int nLastPrint = 0;
      for (j=0;j<MAX_SAMPLES;++j) {
        if (j>0 && a[j] != a[j-1] && a[j] == 0) {
          printf(" (%d)\n", j-nLastPrint);
          nLastPrint=j;
        }
        printf("%d", (a[j]) ? 0 : 1);
      }
      printf("\n");
    }
  }
  return 0;
}
Ejemplo n.º 4
0
void PCA9685::init(int bus, int address) {
	_i2cbus = bus;
	_i2caddr = address;
	snprintf(busfile, sizeof(busfile), "/dev/i2c-%d", bus);

	bcm2835_init(); 	//init bcm chip for power switch
	bcm2835_gpio_fsel(POWERPIN, BCM2835_GPIO_FSEL_OUTP); //set GPIO17 (pin11) as the power switch pin
	SetMainPower(true); //set power on
	reset();
	//usleep(10*1000);
}
Ejemplo n.º 5
0
int connect_to_serial() {
	if (!bcm2835_init()) {
		return 1;
	}
	
	bcm2835_gpio_fsel(PIN_LED_SUCCESS, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_fsel(PIN_DOOR_SUCCESS, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_fsel(PIN_FAIL,BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_fsel(PIN_DOOR_OPEN,BCM2835_GPIO_FSEL_INPT);
	return 0;
}
Ejemplo n.º 6
0
GPIO::GPIO()
{
    if(!isBCM2835Initialized)
    {
        if(!bcm2835_init())
        {
            std::cout << "Error initializing GPIO." << std::endl;
        }
        isBCM2835Initialized = true;
    }
}
Ejemplo n.º 7
0
void hc_sr04_prepare(void)
{
    if (!bcm2835_init()) {
        exit(1);
    }

    bcm2835_gpio_fsel(PIN_ECHO_BACK, BCM2835_GPIO_FSEL_INPT);
    bcm2835_gpio_fsel(PIN_TRIGGER, BCM2835_GPIO_FSEL_OUTP);

    bcm2835_gpio_write(PIN_TRIGGER, LOW);
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) 
{
	bcm2835_init();
	 
	if(comparse(argc, argv) == EXIT_FAILURE) return 0;
	 
	// setting PWM_PIN as pwm from channel 0 in markspace mode with range = RANGE
	bcm2835_gpio_fsel(PWM_PIN, BCM2835_GPIO_FSEL_ALT5);  //ALT5 is pwm mode
	bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16); // pwm freq = 19.2 / 16 MHz
	bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1);		     // markspace mode
	bcm2835_pwm_set_range(PWM_CHANNEL, RANGE);
	
	
	bcm2835_gpio_fsel(OE_SHIFTER, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(OE_SHIFTER, BCM2835_GPIO_PUD_DOWN); //pull-down for output enable of logic shifters

	bcm2835_gpio_fsel(MOTOR_D3, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(MOTOR_D3, BCM2835_GPIO_PUD_DOWN); //pull-down for motor enable
	
	bcm2835_gpio_fsel(PA0, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(PA0, BCM2835_GPIO_PUD_UP);
	bcm2835_gpio_write(PA0, HIGH);
	
	bcm2835_gpio_write(OE_SHIFTER, HIGH);
	bcm2835_gpio_write(MOTOR_D3, LOW);
	
	// creating and running threads
	pthread_t th1, th2, th3, th4, th5, th6, th7;
	pthread_create(&th1, NULL, (void*)encoder_time_thread, NULL);
	pthread_create(&th2, NULL, (void*)magnet_time_thread, NULL);
	pthread_create(&th3, NULL, (void*)encoder_thread, NULL);
	pthread_create(&th4, NULL, (void*)magnet_thread, NULL);
	pthread_create(&th5, NULL, (void*)energy_time_thread, NULL);
	pthread_create(&th6, NULL, (void*)calculate_energy, NULL);
	pthread_create(&th7, NULL, (void*)calculate_I_ref, NULL);
	
	bcm2835_delay(100); // delay to make sure that all threads are initialised and iC-MU is conofigured
	printf("\nPress enter to start the motor.");
	getchar(); 
	bcm2835_gpio_write(MOTOR_D3, HIGH);
	
	start = 1;
	printf("Started.\n");

	printf("\nPress enter to stop the motor.\n");
	getchar();
	bcm2835_gpio_write(MOTOR_D3, LOW);
	
	bcm2835_spi_end();
	bcm2835_close();
	
	
	return 0;
}
Ejemplo n.º 9
0
/**
 * @ingroup SPI-DIO
 *
 * @param device_info
 * @return
 */
uint8_t bw_spi_dio_start(device_info_t *device_info) {
#if !defined(BARE_METAL) && !defined(__AVR_ARCH__)
	if (bcm2835_init() != 1)
		return 1;
#endif
	FUNC_PREFIX(spi_begin());

	if (device_info->slave_address <= 0)
		device_info->slave_address = BW_DIO_DEFAULT_SLAVE_ADDRESS;

	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{ 
 
  if (!bcm2835_init())
  {
        printf("Failed to init bcm2835\n");
  	return 1;
  }
  // Set the pin to be an output
  bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);

  int rep;
  char *on_or_off = NULL;
 
  on_or_off = argv[1];  

  if (!(on_or_off))
     {
    	printf("Usage %s on|off \n",argv[0]);
        exit(2);	
     }

        usleep(500);
	bcm2835_gpio_write(PIN, LOW);
        usleep(8000);
  for (rep=0; rep<10; rep++);
  //recall INVERSION out a 1 to ge a zero!
  {
     {
	bcm2835_gpio_write(PIN, LOW);
        usleep(8000);
  //above is gap between burst

        bgas_main(); 

//########################################################
	if (strcmp(on_or_off,"on")==0){	
          bgas_on();
/*        # It is on */

	} else if (strcmp(on_or_off,"off") == 0) {
          bgas_off();
/*        # It is off */
        }
// ##################################################################
} 
//   printf ("loop done\n");
}
	bcm2835_gpio_write(PIN, LOW);
        bcm2835_close();
        return 0;

} // main
Ejemplo n.º 11
0
int main (void)
{
	//Initialise the Raspberry Pi GPIO
	if(!bcm2835_init()) {
		printf("Couldn't init bcm2835!");
		return 1;
	}
	
	printTempAndHumidity();

	return 0;
}
Ejemplo n.º 12
0
/**
 *@brief Initializes the SPI peripheral
 *@return none
 */
void SPI_Initialize(void)
{	if (!bcm2835_init())
	{
		printf("BCM libray error.\n");			//Should be run with the sudo cmd
	}
	bcm2835_spi_begin();						//Configure SPI pins
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      	//Configure bit order
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);  			//Set clock polarity and phase CPOL=0, CPHA=0
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_4);	//SPI baud rate at 244 Khz
	bcm2835_spi_chipSelect(BCM2835_SPI_CS_NONE);			//Control CE0 in software
	printf("SPI initialized...\n");
}
Ejemplo n.º 13
0
//
// Set up a memory regions to access GPIO
//
void setup_io()
{
	void *clock_map;	
   /* open /dev/mem */
   if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
      printf("can't open /dev/mem \n");
      exit(-1);
   }
 
   /* mmap GPIO */
   gpio_map = mmap(
      NULL,             //Any adddress in our space will do
      BLOCK_SIZE,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      GPIO_BASE         //Offset to GPIO peripheral
   );
   
    clock_map = mmap(
      NULL,             //Any address in our space will do
      BLOCK_SIZE,       //Map length
      PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
      MAP_SHARED,       //Shared with other processes
      mem_fd,           //File to map
      CLOCK_BASE         //Offset to hardware clock peripheral
    );   
 
   close(mem_fd); //No need to keep mem_fd open after mmap
 
   if (gpio_map == MAP_FAILED) {
      printf("mmap error %d\n", (int)gpio_map);//errno also set!
      exit(-1);
   }
 
   // Always use volatile pointer!
   gpio = (volatile unsigned *)gpio_map;
   clock_base = (volatile unsigned *)clock_map;

   if (!bcm2835_init())
   {
		printf("bcm2835_init error\n");
		exit(-1);   
   }
    // bcm2835_spi_begin();
    // bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
    // bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
    // bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32); 
    // bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    // bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default   
    // bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, LOW);      // the default   
} // setup_io
Ejemplo n.º 14
0
int main(int argc, char **argv) {
	int first = 0x03, last = 0x77;
    int flags = 0;
    int version = 0;

	while (1 + flags < argc && argv[1 + flags][0] == '-') {
		switch (argv[1 + flags][1]) {
		case 'V': version = 1; break;
		case 'a':
			first = 0x00;
			last = 0x7F;
			break;
		default:
			fprintf(stderr, "Warning: Unsupported flag \"-%c\"!\n", argv[1 + flags][1]);
			//help(); // TODO
			exit(1);
		}
		flags++;
	}

    if (version) {
		fprintf(stderr, "i2cdetect version %s\n", VERSION);
		exit(0);
	}

	if (bcm2835_init() != 1) {
		fprintf(stderr, "bcm2835_init() failed\n");
		exit(1);
	}

	bcm2835_i2c_begin();

	bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_2500); // 100kHz

	int address;

	for (address = 0x00; address <= 0x7F; address++) {
		if (address < first || address > last) {
			continue;
		}
		bcm2835_i2c_setSlaveAddress(address);
		if (bcm2835_i2c_write(NULL, 0) == 0) {
			printf("0x%.2X : 0x%.2X : %s\n", address, address << 1, lookup_device(address));
		}
	}

	bcm2835_i2c_end();

	bcm2835_close();

	return 0;
}
Ejemplo n.º 15
0
/**
 *@brief Initializes the I2C peripheral
 *@param address Address the I2C peripheral is communicating with.
 *@return none
 */
void I2C_Initialize(unsigned char address)
{
    if (!bcm2835_init())						//Configure I2C pins
    {
        printf("BCM libray error.\n");
    }
    bcm2835_i2c_end();		//Close I2C peripheral to reconfigure it

    bcm2835_i2c_begin();						//Set pins as I2C
    bcm2835_i2c_set_baudrate(baudrate);			//Set I2C baudrate
    bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_2500);		//100 Khz
    bcm2835_i2c_setSlaveAddress(address);	//Set device address
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
  if (!bcm2835_init())
        return 1;

  int type = DHT22;
  int dhtpin = atoi(argv[1]);

  printf("Using pin #%d\n", dhtpin);
  readDHT(type, dhtpin);
  return 0;

} // main
Ejemplo n.º 17
0
void SPI_Init() {
	bcm2835_init();

	bcm2835_spi_begin();

	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, 0);
	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, 0);

	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64);

	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
	bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
}
Ejemplo n.º 18
0
int main(int argc, char **argv)
{
	if (bcm2835_init() == 0) {
		return 1;
	}
	
	bcm2835_gpio_fsel(PIN37, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_write(PIN37, HIGH);
	
	bcm2835_close();
	
	return 0;
}
Ejemplo n.º 19
0
int main( int argc, char **argv ) { 
  if (!bcm2835_init())
    return 1;
  
/*  TFT_init_board();
  TFT_hard_reset();
  RAIO_init(); */
  
  RAIO_screen_off();

  bcm2835_close();
  
  return 0;
}
Ejemplo n.º 20
0
int main(int argc, const char* argv[])
{	

	if(!bcm2835_init())
	{
		printf("%s\n", "BCM2835 failed to initialize");
		return 0;
	}

	bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);

	count = 0;
	
	if(argc != 2)
	{
		printf("usage: startbrewing file\n");
		return 0; 
	} else {
		const char *url = "https://userstream.twitter.com/1.1/user.json";
		oauth_keys *keys = malloc(sizeof(oauth_keys)+1);	

		keys->ckey = malloc(50);
		keys->csecret = malloc(50);
		keys->atok = malloc(50);
		keys->atoksecret = malloc(50);
		
		char *filename = malloc(strlen(argv[1])+1);
	
		strcpy(filename, argv[1]);
		
		read_in_keys(filename, keys);
		
		curl_global_init(CURL_GLOBAL_ALL);
		
		CURL *curl = curl_easy_init();
		char *signedurl = oauth_sign_url2(url, NULL, OA_HMAC, "GET", keys->ckey, keys->csecret, keys->atok, keys->atoksecret);
		
		curl_easy_setopt(curl, CURLOPT_URL, signedurl);
		curl_easy_setopt(curl, CURLOPT_USERAGENT, "Start Brewing/0.1");
		curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, parse);

		int curl_status = curl_easy_perform(curl);
		
		curl_easy_cleanup(curl);
		curl_global_cleanup();
	}
	
	return 0;
}
Ejemplo n.º 21
0
int init_all(I2CVariables *i2c_var) {
    if (!bcm2835_init()) return ERROR_BCM2835_INIT;
    bcm2835_i2c_begin();
    bcm2835_i2c_setClockDivider(BCM2835_I2C_CLOCK_DIVIDER_626);         // 400 kHz

    ADXL345_init();
    L3G4200D_init();
    HMC5883L_init();
    BMP085_init();
    PCA9685PW_init(1);

    I2CVariables_init(i2c_var);
    return 0;
}
Ejemplo n.º 22
0
int main(){
    bcm2835_init();
    // Setup PWM
    bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16);
    bcm2835_pwm_set_mode(PWM_CHANNEL_0,1,1);
    bcm2835_pwm_set_mode(PWM_CHANNEL_1,1,1);
    bcm2835_pwm_set_range(PWM_CHANNEL_0, PWM_RANGE);
    bcm2835_pwm_set_range(PWM_CHANNEL_1, PWM_RANGE);
    setup();
    while(1) {
      loop();
    }
    return (0);
}
Ejemplo n.º 23
0
int mcp7941x_start (char slave_address) {

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

	bcm2835_i2c_begin();

	if (slave_address <= 0)
		i2c_mcp7941x_slave_address = MCP7941X_DEFAULT_SLAVE_ADDRESS;
	else
		i2c_mcp7941x_slave_address = slave_address;

	return MCP7941X_OK;
}
Ejemplo n.º 24
0
int bw_spi_dio_start(device_info_t *device_info) {

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

	bcm2835_spi_begin();
	// Just once. Assuming all devices do have the same
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);

	if (device_info->slave_address <= 0)
		device_info->slave_address = BW_DIO_DEFAULT_SLAVE_ADDRESS;

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

    bcm2835_gpio_fsel( PIN, BCM2835_GPIO_FSEL_OUTP );

    while( 1 ) {
        bcm2835_gpio_write( PIN, HIGH );
        usleep( TIME );
        bcm2835_gpio_write( PIN, LOW );
        usleep( TIME );
    }
}
Ejemplo n.º 26
0
int main(int argc, char **argv)
{
  unsigned char buf[6];
  unsigned char i,reg;
  double temp=0,calc=0, skytemp,atemp;
  FILE *flog;
  flog=fopen("mlxlog.csv", "a");
    bcm2835_init();
    bcm2835_i2c_begin();
    bcm2835_i2c_set_baudrate(25000);
    // set address...........................................................................................
    bcm2835_i2c_setSlaveAddress(0x5a);
    printf("\nOk, your device is working!!\n");
    while(1) {
      time_t t = time(NULL);
      struct tm tm = *localtime(&t);
      calc=0;
      reg=7;
      for(i=0;i<AVG;i++){
	bcm2835_i2c_begin();
	bcm2835_i2c_write (&reg, 1);
	bcm2835_i2c_read_register_rs(&reg,&buf[0],3);
	temp = (double) (((buf[1]) << 8) + buf[0]);
	temp = (temp * 0.02)-0.01;
	temp = temp - 273.15;
	calc+=temp;
	sleep(1);
      }
      skytemp=calc/AVG;
      calc=0;
      reg=6;
      for(i=0;i<AVG;i++){
	bcm2835_i2c_begin();
	bcm2835_i2c_write (&reg, 1);
	bcm2835_i2c_read_register_rs(&reg,&buf[0],3);
	temp = (double) (((buf[1]) << 8) + buf[0]);
	temp = (temp * 0.02)-0.01;
	temp = temp - 273.15;
	calc+=temp;
	sleep(1);
      }
      atemp=calc/AVG;
      printf("%02d-%02d %02d:%02d:%02d\n    Tambi=%04.2f C, Tobj=%04.2f C\n", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,atemp,skytemp);
      fprintf(flog,"%04d-%02d-%02d %02d:%02d:%02d,%04.2f,%04.02f\n",tm.tm_year+1900, tm.tm_mon +1, tm.tm_mday,tm.tm_hour, tm.tm_min, tm.tm_sec,atemp,skytemp);
      fflush(flog);
      sleep(LOGTIME-(2*AVG));
    }
    printf("[done]\n");
}
Ejemplo n.º 27
0
int main(int argc, char **argv)
{
    if (!bcm2835_init())
        return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
    bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP);
printf("irm test start: \n");
char turn;    
char n,p,result;
unsigned long i;
unsigned long buff[33];
while (1)
{	
	i++;delayMicroseconds(60);	
	if(bcm2835_gpio_lev(PIN)==1)
	{
	turn=1;
	}	
	else
	{
	if(turn==1)
		{
		if((n>0)&&(n<=33)) 
			{
			buff[n-1]=i;
			
			}
		n++;i=0;

		if(n==34)
			{
			n=0;
			//for(p=0;p<33;p++){printf("%d-%d;",p,buff[p]);}

			if(buff[0]>180 && buff[0]<250 && buff[1]<25 && buff[2]<25 && buff[3]<25 && buff[4]<25 && buff[5]<25 && buff[6]<25 && buff[7]<25 && buff[8]<25 && buff[9]>25 && buff[10]>25 && buff[11]>25 && buff[12]>25 && buff[13]>25) 
				{
				for(p=0;p<8;p++)
					{
					result>>=1;
					if(buff[25+p]>25) {result|=0x80;}
					}	
				printf("get the irm key code-hex ox%x \n",result);
				}
			bcm2835_delay(200);
			}
		}
	turn=0;
	}
}
Ejemplo n.º 28
0
LEDMatrix::LEDMatrix(int width, int height) {
	this->width = width;
	this->height = height;

	//Initialize the color array
	for(int i = 0; i < (width*height); i++) {
		colors.push_back(Color());
	}

	//Initialize the BCM2835 library
	bcm2835_init();
	bcm2835_spi_begin();

	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128);
}
Ejemplo n.º 29
0
int main(int argc, char **argv)
{
    if (geteuid() == 0)
    {
	if (!bcm2835_init())
	    return 1;
	if (!bcm2835_close())
	    return 1;
    }
    else
    {
	fprintf(stderr, "****You need to be root to properly run this test program\n");
    }
    return 0;
}
Ejemplo n.º 30
-1
int rpi_gpio_init() {
    if(!bcm2835_init()) return 1;

    // Set up pins as outputs
    bcm2835_gpio_fsel(RPI_SPI_MOSI, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(RPI_SPI_CLK,  BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(RPI_SPI_CE0,  BCM2835_GPIO_FSEL_OUTP);

    return 0;
}