Skip to content

Commit 1bd3f9c

Browse files
committed
Merge branch 'develop'
2 parents 7033677 + 9dd3aad commit 1bd3f9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4956
-2
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# open-weather-station
2-
Open source weather station based on Arduino and Ionic by Francisco Clariá https://openWeatherStation.com
1+
# Open Weather Station
2+
Open source weather station suite based on Arduino sensing module that transmits data via bluetooth to an Ionic powered Android app (coming soon)
3+
4+
## COMING NEXT ##
5+
* project details
6+
* hardware assembly instructions
7+
* app to connect, visualize and publish data
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
language: cpp
2+
env:
3+
global:
4+
- ARDUINO_PACKAGE_VERSION=1.8.4
5+
- DISPLAY=:1.0
6+
7+
before_install:
8+
# arduino requires an X server even with command line
9+
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/xvfb_$TRAVIS_JOB_NUMBER.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
10+
11+
install:
12+
- wget -q -O- http://downloads.arduino.cc/arduino-$ARDUINO_PACKAGE_VERSION-linux64.tar.xz | tar -Jxf -
13+
- sudo mv arduino-$ARDUINO_PACKAGE_VERSION /usr/local/share/arduino
14+
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
15+
# Add esp8266 board support
16+
# - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
17+
# - arduino --install-boards esp8266:esp8266
18+
# link project directory into Arduino libraries area.
19+
- ln -s $PWD /usr/local/share/arduino/libraries/BH1750
20+
21+
script:
22+
# uno
23+
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750test/BH1750test.ino
24+
- arduino --verify --board arduino:avr:uno $PWD/examples/BH1750advanced/BH1750advanced.ino
25+
# esp8266
26+
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570test/BH1750test.ino
27+
# - arduino --verify --board esp8266:esp8266:generic $PWD/examples/BH1570advanced/BH1750advanced.ino
+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
3+
This is a library for the BH1750FVI Digital Light Sensor breakout board.
4+
5+
The BH1750 board uses I2C for communication. Two pins are required to
6+
interface to the device. Configuring the I2C bus is expected to be done
7+
in user code. The BH1750 library doesn't do this automatically.
8+
9+
Written by Christopher Laws, March, 2013.
10+
11+
*/
12+
13+
#include "BH1750.h"
14+
15+
// Define milliseconds delay for ESP8266 platform
16+
#if defined(ESP8266)
17+
18+
#include <pgmspace.h>
19+
#define _delay_ms(ms) delayMicroseconds((ms) * 1000)
20+
21+
// Use _delay_ms from utils for AVR-based platforms
22+
#elif defined(__avr__)
23+
#include <util/delay.h>
24+
25+
// Use Wiring's delay for compability with another platforms
26+
#else
27+
#define _delay_ms(ms) delay(ms)
28+
#endif
29+
30+
31+
// Legacy Wire.write() function fix
32+
#if (ARDUINO >= 100)
33+
#define __wire_write(d) Wire.write(d)
34+
#else
35+
#define __wire_write(d) Wire.send(d)
36+
#endif
37+
38+
39+
// Legacy Wire.read() function fix
40+
#if (ARDUINO >= 100)
41+
#define __wire_read() Wire.read()
42+
#else
43+
#define __wire_read() Wire.receive()
44+
#endif
45+
46+
47+
/**
48+
* Constructor
49+
* @params addr Sensor address (0x76 or 0x72, see datasheet)
50+
*
51+
* On most sensor boards, it was 0x76
52+
*/
53+
BH1750::BH1750(byte addr) {
54+
55+
BH1750_I2CADDR = addr;
56+
57+
}
58+
59+
60+
/**
61+
* Configure sensor
62+
* @param mode Measurment mode
63+
*/
64+
void BH1750::begin(uint8_t mode) {
65+
66+
// I2C is expected to be initialized outside this library
67+
68+
// Configure sensor in specified mode
69+
configure(mode);
70+
71+
}
72+
73+
74+
/**
75+
* Configure BH1750 with specified working mode
76+
* @param mode Measurment mode
77+
*/
78+
void BH1750::configure(uint8_t mode) {
79+
80+
// Check measurment mode is valid
81+
switch (mode) {
82+
83+
case BH1750_CONTINUOUS_HIGH_RES_MODE:
84+
case BH1750_CONTINUOUS_HIGH_RES_MODE_2:
85+
case BH1750_CONTINUOUS_LOW_RES_MODE:
86+
case BH1750_ONE_TIME_HIGH_RES_MODE:
87+
case BH1750_ONE_TIME_HIGH_RES_MODE_2:
88+
case BH1750_ONE_TIME_LOW_RES_MODE:
89+
90+
// Save mode so it can be restored when One-Time modes are used.
91+
BH1750_MODE = mode;
92+
93+
// Send mode to sensor
94+
Wire.beginTransmission(BH1750_I2CADDR);
95+
__wire_write((uint8_t)BH1750_MODE);
96+
Wire.endTransmission();
97+
98+
// Wait a few moments to wake up
99+
_delay_ms(10);
100+
break;
101+
102+
default:
103+
104+
// Invalid measurement mode
105+
#ifdef BH1750_DEBUG
106+
Serial.println(F("BH1750: Invalid measurment mode"));
107+
#endif
108+
109+
break;
110+
111+
}
112+
113+
}
114+
115+
116+
/**
117+
* Read light level from sensor
118+
* @return Light level in lux (0 ~ 65535)
119+
*/
120+
uint16_t BH1750::readLightLevel(bool maxWait) {
121+
122+
// Measurment result will be stored here
123+
uint16_t level;
124+
125+
// One-Time modes need to be re-applied after power-up. They have a maximum
126+
// measurement time and a typical measurement time. The maxWait argument
127+
// determines which measurement wait time is used when a one-time mode is
128+
// being used. The typical (shorter) measurement time is used by default and
129+
// if maxWait is set to True then the maximum measurement time will be used.
130+
// See data sheet pages 2, 5 and 7 for more details.
131+
switch (BH1750_MODE) {
132+
133+
case BH1750_ONE_TIME_HIGH_RES_MODE:
134+
case BH1750_ONE_TIME_HIGH_RES_MODE_2:
135+
case BH1750_ONE_TIME_LOW_RES_MODE:
136+
137+
// Send mode to sensor
138+
Wire.beginTransmission(BH1750_I2CADDR);
139+
__wire_write((uint8_t)BH1750_MODE);
140+
Wire.endTransmission();
141+
142+
// wait for measurement time
143+
if (BH1750_MODE == BH1750_ONE_TIME_LOW_RES_MODE) {
144+
maxWait ? _delay_ms(24) : _delay_ms(16);
145+
}
146+
else {
147+
maxWait ? _delay_ms(180) :_delay_ms(120);
148+
}
149+
break;
150+
151+
}
152+
153+
// Read two bytes from sensor
154+
Wire.requestFrom(BH1750_I2CADDR, 2);
155+
156+
// Read two bytes, which are low and high parts of sensor value
157+
level = __wire_read();
158+
level <<= 8;
159+
level |= __wire_read();
160+
161+
// Print raw value if debug enabled
162+
#ifdef BH1750_DEBUG
163+
Serial.print(F("[BH1750] Raw value: "));
164+
Serial.println(level);
165+
#endif
166+
167+
// Convert raw value to lux
168+
level /= 1.2;
169+
170+
// Print converted value if debug enabled
171+
#ifdef BH1750_DEBUG
172+
Serial.print(F("[BH1750] Converted value: "));
173+
Serial.println(level);
174+
#endif
175+
176+
return level;
177+
178+
}
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
3+
This is a library for the BH1750FVI Digital Light Sensor
4+
breakout board.
5+
6+
The BH1750 board uses I2C for communication. Two pins are required to
7+
interface to the device. Configuring the I2C bus is expected to be done
8+
in user code. The BH1750 library doesn't do this automatically.
9+
10+
Datasheet: http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-e.pdf
11+
12+
Written by Christopher Laws, March, 2013.
13+
14+
*/
15+
16+
#ifndef BH1750_h
17+
#define BH1750_h
18+
19+
#if (ARDUINO >= 100)
20+
#include <Arduino.h>
21+
#else
22+
#include <WProgram.h>
23+
#endif
24+
25+
#include "Wire.h"
26+
27+
// Uncomment, to enable debug messages
28+
// #define BH1750_DEBUG
29+
30+
// No active state
31+
#define BH1750_POWER_DOWN 0x00
32+
33+
// Wating for measurment command
34+
#define BH1750_POWER_ON 0x01
35+
36+
// Reset data register value - not accepted in POWER_DOWN mode
37+
#define BH1750_RESET 0x07
38+
39+
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
40+
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10
41+
42+
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
43+
#define BH1750_CONTINUOUS_HIGH_RES_MODE_2 0x11
44+
45+
// Start measurement at 4lx resolution. Measurement time is approx 16ms.
46+
#define BH1750_CONTINUOUS_LOW_RES_MODE 0x13
47+
48+
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
49+
// Device is automatically set to Power Down after measurement.
50+
#define BH1750_ONE_TIME_HIGH_RES_MODE 0x20
51+
52+
// Start measurement at 0.5lx resolution. Measurement time is approx 120ms.
53+
// Device is automatically set to Power Down after measurement.
54+
#define BH1750_ONE_TIME_HIGH_RES_MODE_2 0x21
55+
56+
// Start measurement at 1lx resolution. Measurement time is approx 120ms.
57+
// Device is automatically set to Power Down after measurement.
58+
#define BH1750_ONE_TIME_LOW_RES_MODE 0x23
59+
60+
class BH1750 {
61+
62+
public:
63+
BH1750 (byte addr = 0x23);
64+
void begin (uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE);
65+
void configure (uint8_t mode);
66+
uint16_t readLightLevel(bool maxWait = false);
67+
68+
private:
69+
int BH1750_I2CADDR;
70+
uint8_t BH1750_MODE;
71+
72+
};
73+
74+
#endif

0 commit comments

Comments
 (0)