asus0909 0 Posted November 15, 2014 Share Posted November 15, 2014 #include <Wire.h> //BH1750 IIC Mode #include <math.h> int BH1750address = 0x23; //setting i2c address uint16_t val=0; byte buff[2]; void setup() { Wire.begin(); Serial.begin(9600);//init Serail band rate } void loop() { int i; val=0; BH1750_Init(BH1750address); delay(200); if(2==BH1750_Read(BH1750address)) { val=((buff[0]<<8)|buff[1])/1.2; Serial.print(val,DEC); Serial.println("[lx]"); } } int BH1750_Read(int address) { int i=0; Wire.beginTransmission(address); Wire.requestFrom(address, 2 ); while(Wire.available()) { buff[i] = Wire.read(); // receive one byte i++; } Wire.endTransmission(); return i; } void BH1750_Init(int address) { Wire.beginTransmission(address); Wire.write(0x10);//1lx reolution 120ms Wire.endTransmission(); } SCL >> PA6 SDA >> PA7 but no result ,pz help me? Quote Link to post Share on other sites
zeke 693 Posted November 15, 2014 Share Posted November 15, 2014 @@asus0909 Here is a data sheet for the bh1750: http://www.dfrobot.com/image/data/SEN0097/BH1750FVI.pdf The iic address = 0x23 when ADDR = LOW. The iic address = 0x3C when ADDR = HIGH. I do not see where you configure the light sensor for a specific sample resolution. It may be in reset mode until you configure it. Check out page 7 of the datasheet to see an example transaction to get a reading out of the device. Also, do you have pull-up resistors on SCL and SCK? Quote Link to post Share on other sites
asus0909 0 Posted November 15, 2014 Author Share Posted November 15, 2014 @@zeke The iic address = 0x23 when ADDR = LOW. this mean ADD >> GND ? I do not see where you configure the light sensor for a specific sample resolution. void BH1750_Init(int address) { Wire.beginTransmission(address); Wire.write(0x10);//1lx reolution 120ms Wire.endTransmission(); } Wire.write(0x10);//Continuous_H_resolution_Mode 0x10 Can you help me code sample? p/s:my english is not good Quote Link to post Share on other sites
zeke 693 Posted November 17, 2014 Share Posted November 17, 2014 Hi @@asus0909, Don't worry about your english skills. We can speak code and we will understand each other this mean ADD >> GND ? Yes, that is correct. Connect the ADDR pin to ground and then the I2C address will be 0x23. Do you have a logic analyzer? If so, connect it up to the SDA and SCL lines and capture some waveforms. Those waveforms will let us know what is and is not working properly. Quote Link to post Share on other sites
asus0909 0 Posted November 20, 2014 Author Share Posted November 20, 2014 Do you have a logic analyzer? i don't have... i use I2C_SoftwareLibrary.h http://forum.43oh.com/topic/3617-energia-library-software-i2c-master-for-msp430g2553/ but error error: '__delay_cycles' was not declared in this scope pz,help me? Quote Link to post Share on other sites
Marvi 1 Posted March 21, 2015 Share Posted March 21, 2015 I tested BH1750FVI board for arduino and it works. But there is few things I have to do before It worked. On the board is 3.3V voltage stabilizer, so you must remove it or use 5V from USB and common ground with microprocessor! I make few changes in code. Energia 0014 and Launchpad 1.4 (cross RX TX) with MSP430G2553. Here is my working code: // SDA to PIN 1.7 //SCL to PIN 1.6 //The iic address = 0x23 when ADDR = LOW; address = 0x3C when ADDR = HIGH #include <Wire.h> //BH1750 I2C Mode slave uint16_t Lux=0; void setup() { Wire.begin(); Serial.begin(9600); } void loop() { Lux=0; Read_BH1750(); Serial.print(Lux,DEC); Serial.println(" LUX"); delay(400); } void Read_BH1750() { byte buff[2]; int i=0; Wire.beginTransmission(0x23); Wire.write(0x10);//1 Lux resolution time 120ms Wire.requestFrom(0x23, 2 ); while(Wire.available()){buff[i] = Wire.read(); i++;} // receive one byte Wire.endTransmission(); if(i==2){Lux=((buff[0]<<8)|buff[1])/(12/10);} } phaseform 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.