Permalink
Browse files

Add BMP085

  • Loading branch information...
1 parent aeaa005 commit 98b3dcc0d1f83b48a0a2df1f8cafd0d263bca79d @nathanchantrell committed Apr 7, 2013
Showing with 41 additions and 32 deletions.
  1. +41 −32 BMP085_TX/BMP085_TX.ino → TinyTX_BMP085/TinyTX_BMP085.ino
@@ -1,46 +1,43 @@
-
//----------------------------------------------------------------------------------------------------------------------
-// BMP085 Barometric Pressure & Temperature Sensor Node
-// By Nathan Chantrell.
+// TinyTX - An ATtiny84 and BMP085 Wireless Air Pressure/Temperature Sensor Node
+// By Nathan Chantrell. For hardware design see http://nathan.chantrell.net/tinytx
//
-// Using the BMP085 sensor and ATmega328
+// Using the BMP085 sensor connected via I2C
+// I2C can be connected withf SDA to D8 and SCL to D7 or SDA to D10 and SCL to D9
//
// Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence:
// http://creativecommons.org/licenses/by-sa/3.0/
+//
+// Requires Arduino IDE with arduino-tiny core: http://code.google.com/p/arduino-tiny/
//----------------------------------------------------------------------------------------------------------------------
-// Power pin of the BMP085 sensor is connected to A3 or 3.3V (Not 5V!)
-// Connect GND to Ground
-// Connect SCL to Analogue 5
-// Connect SDA to Analogue 4
-// EOC & XCLR are not used
-
-#include <Wire.h>
-#include <Adafruit_BMP085.h> // https://github.com/adafruit/Adafruit-BMP085-Library
#include <JeeLib.h> // https://github.com/jcw/jeelib
+#include <PortsBMP085.h> // Part of JeeLib
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // interrupt handler for JeeLabs Sleepy power saving
#define myNodeID 1 // RF12 node ID in the range 1-30
#define network 210 // RF12 Network group
#define freq RF12_433MHZ // Frequency of RFM12B module
-#define USE_ACK // Enable ACKs, comment out to disable
+//#define USE_ACK // Enable ACKs, comment out to disable
#define RETRY_PERIOD 5 // How soon to retry (in seconds) if ACK didn't come in
#define RETRY_LIMIT 5 // Maximum number of times to retry
#define ACK_TIME 10 // Number of milliseconds to wait for an ack
-#define BMP085_POWER A3 // BMP085 power pin is connected on A3
-Adafruit_BMP085 bmp;
+PortI2C i2c (2); // BMP085 SDA to D8 and SCL to D7
+// PortI2C i2c (1); // BMP085 SDA to D10 and SCL to D9
+BMP085 psensor (i2c, 3); // ultra high resolution
+#define BMP085_POWER 9 // BMP085 Power pin is connected on D9
//########################################################################################################################
//Data Structure to be sent
//########################################################################################################################
typedef struct {
- int temp; // Temperature reading
+ int16_t temp; // Temperature reading
int supplyV; // Supply voltage
- int press; // Pressure reading
+ int32_t pres; // Pressure reading
} Payload;
Payload tinytx;
@@ -86,11 +83,10 @@ Adafruit_BMP085 bmp;
#endif
}
-
//--------------------------------------------------------------------------------------------------
// Read current supply voltage
//--------------------------------------------------------------------------------------------------
- long readVcc() {
+long readVcc() {
bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
long result;
// Read 1.1V reference against Vcc
@@ -110,26 +106,39 @@ Adafruit_BMP085 bmp;
}
//########################################################################################################################
-
void setup() {
+
+ pinMode(BMP085_POWER, OUTPUT); // set power pin for BMP085 to output
+ digitalWrite(BMP085_POWER, HIGH); // turn BMP085 sensor on
+ Sleepy::loseSomeTime(50);
+ psensor.getCalibData();
rf12_initialize(myNodeID,freq,network); // Initialize RFM12 with settings defined above
rf12_sleep(0); // Put the RFM12 to sleep
-
- // Turn on power pin for the BMP085
- pinMode(BMP085_POWER, OUTPUT);
- digitalWrite(BMP085_POWER, HIGH);
-
- bmp.begin(); // Initialise the BMP085
-}
+ PRR = bit(PRTIM1); // only keep timer 0 going
-void loop() {
-
- tinytx.temp = (bmp.readTemperature()*100); // Get temperature
+ ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
- tinytx.press = (bmp.readPressure()/100); // Get pressure & convert to mb
-
+}
+
+void loop() {
+
+ // Get raw temperature reading
+ psensor.startMeas(BMP085::TEMP);
+ Sleepy::loseSomeTime(16);
+ int32_t traw = psensor.getResult(BMP085::TEMP);
+
+ // Get raw pressure reading
+ psensor.startMeas(BMP085::PRES);
+ Sleepy::loseSomeTime(32);
+ int32_t praw = psensor.getResult(BMP085::PRES);
+
+ // Calculate actual temperature and pressure
+ int32_t press;
+ psensor.calculate(tinytx.temp, press);
+ tinytx.pres = (press * 0.01);
+
tinytx.supplyV = readVcc(); // Get supply voltage
rfwrite(); // Send data via RF

0 comments on commit 98b3dcc

Please sign in to comment.