title: TCS34725 color sensor readings fluctuate when interfacing with PIC16
body: <p>I am trying to read the values of the TCS34725 color sensor with a PIC16 through I2C. Currently, I am continuously polling the clear register on the TCS. However, every 10 or so times I read the value in the clear register, I get a random drop in the readings. For example, a set of consecutive readings may be [17, 17, 17, 17, 17, 17, 17, 17, 14, 15, 16, 17 ...], repeating. </p>
  
  <p>I have tried interfacing with an Arduino Uno in this same situation and get a consistent reading of 17.</p>
  
  <p>I would like to eliminate the drop in the readings.</p>
  
  <p>The code I have in XC8 for reading the TCS is as follows</p>
  
  <pre><code>void read_colorsensor(void){
  unsigned char color_low[4];
  unsigned char color_high[4];
  int i;
  I2C_Master_Start();
  I2C_Master_Write(0b01010010);   //7bit address 0x29 + Write
  I2C_Master_Write(0b10110100);   //Write to cmdreg + access&amp;increment clear low reg
  I2C_Master_Stop();
  
  I2C_Master_Start();     //Repeated start command for combined I2C
  I2C_Master_Write(0b01010011);   //7bit address 0x29 + Read
  color_low[0] = I2C_Master_Read(1);
  color_high[0] = I2C_Master_Read(0);
  I2C_Master_Stop();
  color[0] = (color_high[0] &lt;&lt; 8)|(color_low[0]);
  return;
  }
  </code></pre>