Esempio n. 1
0
// initializer for I2C - we only indicate the reset pin and OLED type !
boolean ArduiPi_OLED::init(int8_t RST, uint8_t OLED_TYPE) 
{
  dc = cs = -1; // DC and chip Select do not exist in I2C
  rst = RST==OLED_PIN_DEFAULT ? DEF_I2C_RESET : RST;  // Reset Pin

  // Select OLED parameters
  if (!select_oled(OLED_TYPE))
    return false;

  // Init & Configure Raspberry PI I2C
  if (bcm2835_i2c_begin()==0)
    return false;
    
  bcm2835_i2c_setSlaveAddress(_i2c_addr) ;
    
  // Set clock to 400 KHz
  // does not seem to work, will check this later
  // bcm2835_i2c_set_baudrate(400000);
  bcm2835_i2c_set_baudrate(400000);

  // Setup reset pin direction as output
  if (rst >= 0)
    bcm2835_gpio_fsel(rst, BCM2835_GPIO_FSEL_OUTP);
  
  return ( true);
}
Esempio n. 2
0
/*!
 \param freq desired frequency. 40Hz to 1000Hz using internal 25MHz oscillator.
 */
void PCA9685::setPWMFreq(int freq) {

    uint8_t prescale_val = (CLOCK_FREQ / 4096 / freq)  - 1;
    bcm2835_i2c_set_baudrate(400000);
    bcm2835_i2c_setSlaveAddress(addr);

    pca_sendBuf[0] = MODE1;
    pca_sendBuf[1] = 0x10;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = PRE_SCALE;
    pca_sendBuf[1] = prescale_val;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = MODE1;
    pca_sendBuf[1] = 0x80;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = MODE2;
    pca_sendBuf[1] = 0x04;
    bcm2835_i2c_write (pca_sendBuf, 2);
    //i2c->write_byte(MODE1, 0x10); //sleep
    //i2c->write_byte(PRE_SCALE, prescale_val); // multiplyer for PWM frequency
    //i2c->write_byte(MODE1, 0x80); //restart
    //i2c->write_byte(MODE2, 0x04); //totem pole (default)
}
Esempio n. 3
0
/*!
 \param led channel to set PWM value for
 \param on_value 0-4095 value to turn on the pulse
 \param off_value 0-4095 value to turn off the pulse
 */
void PCA9685::setPWM(uint8_t led, int on_value, int off_value) {
    bcm2835_i2c_set_baudrate(400000);
    bcm2835_i2c_setSlaveAddress(addr);

    pca_sendBuf[0] = LED0_ON_L + LED_MULTIPLYER * (led - 1);
    pca_sendBuf[1] = on_value & 0xFF;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = LED0_ON_H + LED_MULTIPLYER * (led - 1);
    pca_sendBuf[1] = on_value >> 8;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = LED0_OFF_L + LED_MULTIPLYER * (led - 1);
    pca_sendBuf[1] = off_value & 0xFF;
    //std::cout << (int)pca_sendBuf[1] << std::endl;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = LED0_OFF_H + LED_MULTIPLYER * (led - 1);
    pca_sendBuf[1] = off_value >> 8;
    //std::cout << (int)pca_sendBuf[1] << std::endl;
    bcm2835_i2c_write (pca_sendBuf, 2);

    //i2c->write_byte(LED0_ON_L + LED_MULTIPLYER * (led - 1), on_value & 0xFF);
    //i2c->write_byte(LED0_ON_H + LED_MULTIPLYER * (led - 1), on_value >> 8);
    //i2c->write_byte(LED0_OFF_L + LED_MULTIPLYER * (led - 1), off_value & 0xFF);
    //i2c->write_byte(LED0_OFF_H + LED_MULTIPLYER * (led - 1), off_value >> 8);
}
Esempio n. 4
0
static PyObject *
PyBCM2835_i2c_set_baudrate(PyObject *self, PyObject *args)
{
	uint32_t baudrate;
	if (!PyArg_ParseTuple(args,"i",&baudrate)) {
		return NULL;
	}

	bcm2835_i2c_set_baudrate(baudrate);
	Py_RETURN_NONE;
}
Esempio n. 5
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
}
Esempio n. 6
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");
}
Esempio n. 7
0
//! Sets PCA9685 mode to 00
void PCA9685::reset() {
    bcm2835_init();
    bcm2835_i2c_set_baudrate(400000);
    bcm2835_i2c_setSlaveAddress(addr);

    pca_sendBuf[0] = MODE1;
    pca_sendBuf[1] = 0x00;
    bcm2835_i2c_write (pca_sendBuf, 2);

    pca_sendBuf[0] = MODE2;
    pca_sendBuf[1] = 0x04;
    bcm2835_i2c_write (pca_sendBuf, 2);

    //i2c->write_byte(MODE1, 0x00); //Normal mode
    //i2c->write_byte(MODE2, 0x04); //totem pole
}
Esempio n. 8
0
int PCA9685::getPWM(uint8_t led) {
    int ledval = 0;

    bcm2835_i2c_set_baudrate(400000);
    bcm2835_i2c_setSlaveAddress(addr);

    char regH = LED0_OFF_H + LED_MULTIPLYER * (led-1);
    char regL = LED0_OFF_L + LED_MULTIPLYER * (led-1);

    bcm2835_i2c_read_register_rs(&regH,&pca_recvBuf[0],1);
    //std::cout << (int)pca_recvBuf[0] << std::endl;
    //ledval = i2c->read_byte(LED0_OFF_H + LED_MULTIPLYER * (led-1));
    ledval = pca_recvBuf[0] & 0xf;
    ledval <<= 8;
    bcm2835_i2c_read_register_rs(&regL,&pca_recvBuf[0],1);
    //std::cout << (int)pca_recvBuf[0] << std::endl;
    //ledval += i2c->read_byte(LED0_OFF_L + LED_MULTIPLYER * (led-1));
    ledval += pca_recvBuf[0];
    return ledval;
}
Esempio n. 9
0
/*
*	Function: i2c_test
* Description: be used to test I2C related functions by using the PCF8574 module
*/
void i2c_test(void)
{
	uint8_t i2cWBuf[10] = {0x00};
	uint8_t i2cRBuf[10] = {0X00};
	printf("--------------->Test I2C With Pcf8574<--------------\n");
       i2cWBuf[0] = 0x40;
	bcm2835_i2c_begin();
	bcm2835_i2c_setSlaveAddress(PCF8574_ADDR); //set the slave address
       bcm2835_i2c_set_baudrate(400000);  //set the speed of the SDA 400kb/s
	bcm2835_i2c_write(i2cWBuf,1); 
	
	bcm2835_i2c_read(i2cRBuf, 1);
	if(i2cWBuf[0] == i2cRBuf[0])
		printf("I2C interface work well !...\n");
	else
		printf("I2C interface work bad!...\n");
	
	bcm2835_i2c_end();
	printf("==============Test Over Of I2C=================\n");		
}
Esempio n. 10
0
int main(int argc, char **argv)
{


      if (!bcm2835_init())
	return 1;
	char temp[1];				//temporary values
	int ret;
	int ad[2];

	bcm2835_i2c_begin();
	bcm2835_i2c_setSlaveAddress(0x29);      // addr pin attached to ground
	bcm2835_i2c_set_baudrate(1000);         // Default

	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_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_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); 

	ad[0] = (int)temp[0];
	printf("ad value:%d\n",ad[0]*256+ad[1]);

	bcm2835_i2c_end();
	bcm2835_close();
	
	return 0;
}
Esempio n. 11
0
int main(int argc, char **argv)
{
  printf("MMA8452Q Basic Example\n");

  // Set up the interrupt pins, they're set as active high, push-pull
  //pinMode(int1Pin, INPUT);
  //digitalWrite(int1Pin, LOW);
  //pinMode(int2Pin, INPUT);
  //digitalWrite(int2Pin, LOW);

  bcm2835_init();
  bcm2835_i2c_begin();
  bcm2835_i2c_set_baudrate(100000);
  bcm2835_i2c_setSlaveAddress(MMA8452_ADDRESS);

  initMMA8452(); //Test and intialize the MMA8452

while(1){
    loop();
  }
  return 0;
}
//void bcm2835_i2c_set_baudrate(uint32_t baudrate);
/// Call bcm2835_i2c_set_baudrate with 1 parameter
/// \par            Refer
/// \par            Modify
void ope_i2c_set_baudrate(void)
{
    get_int_code();
    bcm2835_i2c_set_baudrate( *((uint32_t *)(buff+1)) );
}
Esempio n. 13
0
/*
* initialize the i2c driver library
*/
int i2c_init(void) {
    bcm2835_init();
    bcm2835_i2c_set_baudrate(I2C_BAUDRATE);
    return 0;
}
Esempio n. 14
0
void I2Cdev::initialize() {
  bcm2835_init();
  bcm2835_i2c_set_baudrate( i2c_baudrate  );
}