Zoran Roncevicmakers-ns
Published © GPL3+

Ambient 2 Click Board on Arduino101

A short article about testing MikroElektronika Ambient 2 click board on the Arduino 101 microcontroller.

BeginnerProtip30 minutes2,094
Ambient 2 Click Board on Arduino101

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
MikroE Arduino UNO shield - click board
×1
MikroE Ambient 2 click board
×1

Story

Read more

Schematics

Stack Arduino/Shield/Sensor

Code

Ambient2.ino

Arduino
#include <Wire.h>

#define OPT3001_ADDRESS 0x44


typedef union {
  uint16_t rawData;
  struct {
    uint16_t Result : 12;
    uint8_t Exponent : 4;
  };
} OPT3001_ER;

OPT3001_ER er;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("ClosedCube OPT3001 Arduino Test");
  Wire.begin();
  Wire.beginTransmission(OPT3001_ADDRESS);
  Wire.write(0x01); // Registar 01 je konfiguracioni
  Wire.endTransmission();
  Wire.beginTransmission(OPT3001_ADDRESS);
  Wire.write(0xC6);
  Wire.endTransmission();

}

void loop() {
  // put your main code here, to run repeatedly:
  Wire.beginTransmission(OPT3001_ADDRESS);
  Wire.write(0x00);
  Wire.endTransmission(); 
  readData(&er.rawData);
  int lux = 0.01*pow(2, er.Exponent)*er.Result;
  Serial.println(lux);
  delay(500);
}

void readData(uint16_t* data) {
    uint8_t buf[2];

  Wire.requestFrom(OPT3001_ADDRESS, 2);

  int counter = 0;
  while (Wire.available() < 2)
  {
    counter++;
    delay(10);
    if (counter > 250)
      return;
  }

  Wire.readBytes(buf, 2);
  *data = (buf[0] << 8) | buf[1];

  return;
}

Credits

Zoran Roncevic

Zoran Roncevic

19 projects • 128 followers
Hackster Live ambassador in Serbia. Organizer of Maker NS community.
makers-ns

makers-ns

0 projects • 6 followers

Comments