Added new telstick windows drivers
Former-commit-id: 797b455c0a2b358e691a198017acea4eb5c02f73
This commit is contained in:
parent
36d0826a33
commit
af01fb9ae9
22 changed files with 2886 additions and 13 deletions
80
arduino/lib/BH1750/BH1750FVI.cpp
Executable file
80
arduino/lib/BH1750/BH1750FVI.cpp
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
#include "BH1750FVI.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
BH1750FVI::BH1750FVI(){
|
||||
|
||||
}
|
||||
|
||||
void BH1750FVI::begin(void){
|
||||
Wire.begin();
|
||||
I2CWriteTo(Power_On ); //Turn it On
|
||||
pinMode(AddrPin,OUTPUT);
|
||||
digitalWrite(AddrPin,HIGH);
|
||||
|
||||
}
|
||||
void BH1750FVI::Sleep(void){
|
||||
I2CWriteTo(Power_Down ); //Turn it off , Reset operator won't work in this mode
|
||||
}
|
||||
void BH1750FVI::Reset(void){
|
||||
I2CWriteTo(Power_On ); //Turn it on again
|
||||
I2CWriteTo(reset ); //Reset
|
||||
|
||||
}
|
||||
void BH1750FVI::SetAddress(uint8_t add){
|
||||
switch (add){
|
||||
case Device_Address_L:
|
||||
address_value=Device_Address_L;
|
||||
digitalWrite(AddrPin,LOW);
|
||||
state=false;
|
||||
break;
|
||||
case Device_Address_H:
|
||||
address_value=Device_Address_H;
|
||||
digitalWrite(AddrPin,HIGH);
|
||||
state=true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
void BH1750FVI::SetMode(uint8_t MODE){
|
||||
switch(MODE){
|
||||
case Continuous_H_resolution_Mode:
|
||||
break;
|
||||
case Continuous_H_resolution_Mode2:
|
||||
break;
|
||||
case Continuous_L_resolution_Mode:
|
||||
break;
|
||||
case OneTime_H_resolution_Mode:
|
||||
break;
|
||||
case OneTime_H_resolution_Mode2:
|
||||
break;
|
||||
case OneTime_L_resolution_Mode:
|
||||
break;
|
||||
}
|
||||
delay(10);
|
||||
I2CWriteTo(MODE);
|
||||
}
|
||||
|
||||
uint16_t BH1750FVI::GetLightIntensity(void){
|
||||
uint16_t Intensity_value;
|
||||
if(state ==true){
|
||||
Wire.beginTransmission(Device_Address_H);
|
||||
Wire.requestFrom(Device_Address_H, 2);
|
||||
}
|
||||
if(state ==false){
|
||||
Wire.beginTransmission(Device_Address_L);
|
||||
Wire.requestFrom(Device_Address_L, 2);
|
||||
}
|
||||
Intensity_value = Wire.read();
|
||||
Intensity_value <<= 8;
|
||||
Intensity_value |= Wire.read();
|
||||
Wire.endTransmission();
|
||||
Intensity_value=Intensity_value/1.2;
|
||||
return Intensity_value;
|
||||
|
||||
}
|
||||
|
||||
void BH1750FVI::I2CWriteTo(uint8_t DataToSend){
|
||||
Wire.beginTransmission(address_value);
|
||||
Wire.write(DataToSend);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
68
arduino/lib/BH1750/BH1750FVI.h
Executable file
68
arduino/lib/BH1750/BH1750FVI.h
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
|
||||
/* This library for Digital Light sensor BH1750FVI
|
||||
|
||||
use I2C Communication protocal , SDA,SCL Are required
|
||||
|
||||
to interface with this sensor
|
||||
|
||||
pin configuration :
|
||||
|
||||
VCC >>> 3.3V
|
||||
SDA >>> A4
|
||||
SCL >>> A5
|
||||
ADDR >> A3 "Optional"
|
||||
GND >>> gnd
|
||||
|
||||
written By : Mohannad Rawashdeh
|
||||
www.genotronex.com
|
||||
*/
|
||||
|
||||
#ifndef BH1750FVI_h
|
||||
#define BH1750FVI_h
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
#define Device_Address_L 0x23 // Device address when address pin LOW
|
||||
#define Device_Address_H 0x5C // Device address when address pin LOW
|
||||
//all command here taken from Data sheet OPECODE Table page 5
|
||||
#define Power_Down 0x00
|
||||
|
||||
#define Power_On 0x01
|
||||
|
||||
#define reset 0x07
|
||||
|
||||
#define Continuous_H_resolution_Mode 0x10
|
||||
|
||||
#define Continuous_H_resolution_Mode2 0x11
|
||||
|
||||
#define Continuous_L_resolution_Mode 0x13
|
||||
|
||||
#define OneTime_H_resolution_Mode 0x20
|
||||
|
||||
#define OneTime_H_resolution_Mode2 0x21
|
||||
|
||||
#define OneTime_L_resolution_Mode 0x23//As well as address value
|
||||
|
||||
#define AddrPin 17 // Address pin enable
|
||||
class BH1750FVI {
|
||||
public:
|
||||
BH1750FVI();
|
||||
void begin(void);
|
||||
void Sleep(void);
|
||||
void SetMode(uint8_t MODE);
|
||||
void Reset(void);
|
||||
void SetAddress(uint8_t add);
|
||||
uint16_t GetLightIntensity(void);
|
||||
|
||||
private:
|
||||
void I2CWriteTo(uint8_t DataToSend);
|
||||
byte address_value;
|
||||
boolean state;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
60
arduino/lib/BH1750/Examples/BH1750_LCD/BH1750_LCD.ino
Executable file
60
arduino/lib/BH1750/Examples/BH1750_LCD/BH1750_LCD.ino
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
This is a simple code to test BH1750FVI Light senosr
|
||||
communicate using I2C Protocol
|
||||
this library enable 2 slave device address
|
||||
Main address 0x23
|
||||
secondary address 0x5C
|
||||
connect this sensor as following :
|
||||
VCC >>> 3.3V
|
||||
SDA >>> A4
|
||||
SCL >>> A5
|
||||
addr >> A3
|
||||
Gnd >>>Gnd
|
||||
|
||||
Written By : Mohannad Rawashdeh
|
||||
|
||||
*/
|
||||
|
||||
// First define the library :
|
||||
#include <BH1750FVI.h> // Sensor Library
|
||||
#include <Wire.h> // I2C Library
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||
uint16_t Light_Intensity=0;
|
||||
// Call the function
|
||||
|
||||
BH1750FVI LightSensor;
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(9600);
|
||||
lcd.begin(16, 2);
|
||||
|
||||
// call begin Function so turn the sensor On .
|
||||
LightSensor.begin();
|
||||
LightSensor.SetAddress(Device_Address_H); //Address 0x5C
|
||||
LightSensor.SetMode(Continuous_H_resolution_Mode);
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("BH1750 Sensor");
|
||||
lcd.setCursor(1, 1);
|
||||
lcd.print("Please wait...");
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(" Intensity = ");
|
||||
lcd.setCursor(5, 1);
|
||||
Light_Intensity = LightSensor.GetLightIntensity();
|
||||
lcd.print(Light_Intensity);
|
||||
lcd.print(" Lux");
|
||||
delay(2000);
|
||||
|
||||
|
||||
}
|
||||
74
arduino/lib/BH1750/Examples/BH1750_Led/BH1750_Led.ino
Executable file
74
arduino/lib/BH1750/Examples/BH1750_Led/BH1750_Led.ino
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
This is a simple code to test BH1750FVI Light senosr
|
||||
communicate using I2C Protocol
|
||||
this library enable 2 slave device address
|
||||
Main address 0x23
|
||||
secondary address 0x5C
|
||||
connect this sensor as following :
|
||||
VCC >>> 3.3V
|
||||
SDA >>> A4
|
||||
SCL >>> A5
|
||||
addr >> A3
|
||||
Gnd >>>Gnd
|
||||
|
||||
Written By : Mohannad Rawashdeh
|
||||
|
||||
*/
|
||||
|
||||
// First define the library :
|
||||
#include <BH1750FVI.h> // Sensor Library
|
||||
#include <Wire.h> // I2C Library
|
||||
|
||||
uint16_t Light_Intensity=0;
|
||||
// Call the function
|
||||
#define LedPin 9 // led connecting to pin D9
|
||||
BH1750FVI LightSensor;
|
||||
|
||||
int SensorValue =0;
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(9600);
|
||||
// call begin Function so turn the sensor On .
|
||||
LightSensor.begin();
|
||||
/*
|
||||
Set the address for this sensor
|
||||
you can use 2 different address
|
||||
Device_Address_H "0x5C"
|
||||
Device_Address_L "0x23"
|
||||
you must connect Addr pin to A3 .
|
||||
*/
|
||||
LightSensor.SetAddress(Device_Address_H); //Address 0x5C
|
||||
// To adjust the slave on other address , uncomment this line
|
||||
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
|
||||
//-----------------------------------------------
|
||||
/*
|
||||
set the Working Mode for this sensor
|
||||
Select the following Mode:
|
||||
Continuous_H_resolution_Mode
|
||||
Continuous_H_resolution_Mode2
|
||||
Continuous_L_resolution_Mode
|
||||
OneTime_H_resolution_Mode
|
||||
OneTime_H_resolution_Mode2
|
||||
OneTime_L_resolution_Mode
|
||||
|
||||
The data sheet recommanded To use Continuous_H_resolution_Mode
|
||||
*/
|
||||
LightSensor.SetMode(Continuous_H_resolution_Mode);
|
||||
pinMode(9,OUTPUT) // Connect LED With 100ohm resistor
|
||||
// to pin D9
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
// call GetLightIntensity() Function , so the sensor read
|
||||
//the Intensity Value and send it
|
||||
Light_Intensity=LightSensor.GetLightIntensity();
|
||||
delay(50);
|
||||
|
||||
SensorValue=map(Light_Intensity,0,2000,255,0);
|
||||
SensorValue=constrain(SensorValue,255,0);
|
||||
digitalWrite(LedPin,SensorValue);
|
||||
// ready to another reading .
|
||||
}
|
||||
68
arduino/lib/BH1750/Examples/BH1750_serial/BH1750_serial.ino
Executable file
68
arduino/lib/BH1750/Examples/BH1750_serial/BH1750_serial.ino
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
/*
|
||||
This is a simple code to test BH1750FVI Light senosr
|
||||
communicate using I2C Protocol
|
||||
this library enable 2 slave device address
|
||||
Main address 0x23
|
||||
secondary address 0x5C
|
||||
connect this sensor as following :
|
||||
VCC >>> 3.3V
|
||||
SDA >>> A4
|
||||
SCL >>> A5
|
||||
addr >> A3
|
||||
Gnd >>>Gnd
|
||||
|
||||
Written By : Mohannad Rawashdeh
|
||||
|
||||
*/
|
||||
|
||||
// First define the library :
|
||||
|
||||
#include <Wire.h>
|
||||
#include <BH1750FVI.h>
|
||||
|
||||
|
||||
BH1750FVI LightSensor;
|
||||
|
||||
|
||||
void setup() { // put your setup code here, to run once:
|
||||
Serial.begin(9600);
|
||||
LightSensor.begin();
|
||||
/*
|
||||
Set the address for this sensor
|
||||
you can use 2 different address
|
||||
Device_Address_H "0x5C"
|
||||
Device_Address_L "0x23"
|
||||
you must connect Addr pin to A3 .
|
||||
*/
|
||||
LightSensor.SetAddress(Device_Address_H);//Address 0x5C
|
||||
// To adjust the slave on other address , uncomment this line
|
||||
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
|
||||
//-----------------------------------------------
|
||||
/*
|
||||
set the Working Mode for this sensor
|
||||
Select the following Mode:
|
||||
Continuous_H_resolution_Mode
|
||||
Continuous_H_resolution_Mode2
|
||||
Continuous_L_resolution_Mode
|
||||
OneTime_H_resolution_Mode
|
||||
OneTime_H_resolution_Mode2
|
||||
OneTime_L_resolution_Mode
|
||||
|
||||
The data sheet recommanded To use Continuous_H_resolution_Mode
|
||||
*/
|
||||
|
||||
LightSensor.SetMode(Continuous_H_resolution_Mode);
|
||||
|
||||
Serial.println("Running...");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value
|
||||
Serial.print("Light: ");
|
||||
Serial.print(lux);
|
||||
Serial.println(" lux");
|
||||
delay(1000);
|
||||
}
|
||||
24
arduino/lib/BH1750/keywords.txt
Executable file
24
arduino/lib/BH1750/keywords.txt
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For BH1750FVI
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
KEYWORD1
|
||||
BH1750FVI KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
KEYWORD2
|
||||
begin KEYWORD2
|
||||
Sleep KEYWORD2SetMode KEYWORD2Reset KEYWORD2GetLightIntensity KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue