Skip to content

Commit 99c11c3

Browse files
committed
Added Ardusat's libraries
1 parent 06822e5 commit 99c11c3

File tree

13 files changed

+694
-0
lines changed

13 files changed

+694
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
bmp085.cpp
3+
libary for using the I2C bmp085 pressure sensor
4+
5+
(c) Written by Jeroen Cappaert for NanoSatisfi, August 2012
6+
*/
7+
8+
#include <Arduino.h>
9+
#include "bmp085.h"
10+
#include <Wire.h>
11+
12+
13+
//Constructor
14+
bmp085::bmp085()
15+
{
16+
barOSS = 2;
17+
}
18+
19+
//configure barometer
20+
void bmp085::configBaro()
21+
{
22+
ac1 = bmp085ReadInt(BAR_ADDR, 0xAA);
23+
ac2 = bmp085ReadInt(BAR_ADDR, 0xAC);
24+
ac3 = bmp085ReadInt(BAR_ADDR, 0xAE);
25+
ac4 = bmp085ReadInt(BAR_ADDR, 0xB0);
26+
ac5 = bmp085ReadInt(BAR_ADDR, 0xB2);
27+
ac6 = bmp085ReadInt(BAR_ADDR, 0xB4);
28+
b1 = bmp085ReadInt(BAR_ADDR, 0xB6);
29+
b2 = bmp085ReadInt(BAR_ADDR, 0xB8);
30+
mb = bmp085ReadInt(BAR_ADDR, 0xBA);
31+
mc = bmp085ReadInt(BAR_ADDR, 0xBC);
32+
md = bmp085ReadInt(BAR_ADDR, 0xBE);
33+
}
34+
35+
// user function: get pressure and temperature from sensor with one command
36+
void bmp085::getBmpData(float bmp[])
37+
{
38+
bmp[0] = getTempFromBaro(baroReadUT());
39+
bmp[1] = getPressFromBaro(baroReadUP());
40+
}
41+
42+
43+
// calculate temperature given ut
44+
float bmp085::getTempFromBaro(unsigned int ut)
45+
{
46+
long x1, x2;
47+
48+
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
49+
x2 = ((long)mc << 11)/(x1 + md);
50+
b5 = x1 + x2;
51+
52+
return (float) ((b5 + 8)>>4)/10.;
53+
}
54+
55+
56+
// Calculate pressure given up
57+
// calibration values must be known
58+
// b5 is also required so bmp085GetTemperature(...) must be called first.
59+
// Value returned will be pressure in units of Pa.
60+
long bmp085::getPressFromBaro(unsigned long up)
61+
{
62+
long x1, x2, x3, b3, b6, p;
63+
unsigned long b4, b7;
64+
65+
b6 = b5 - 4000;
66+
// Calculate B3
67+
x1 = (b2 * (b6 * b6)>>12)>>11;
68+
x2 = (ac2 * b6)>>11;
69+
x3 = x1 + x2;
70+
b3 = (((((long)ac1)*4 + x3)<<barOSS) + 2)>>2;
71+
72+
// Calculate B4
73+
x1 = (ac3 * b6)>>13;
74+
x2 = (b1 * ((b6 * b6)>>12))>>16;
75+
x3 = ((x1 + x2) + 2)>>2;
76+
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
77+
78+
b7 = ((unsigned long)(up - b3) * (50000>>barOSS));
79+
if (b7 < 0x80000000)
80+
p = (b7<<1)/b4;
81+
else
82+
p = (b7/b4)<<1;
83+
84+
x1 = (p>>8) * (p>>8);
85+
x1 = (x1 * 3038)>>16;
86+
x2 = (-7357 * p)>>16;
87+
p += (x1 + x2 + 3791)>>4;
88+
89+
return p;
90+
}
91+
92+
93+
// read uncorrected temperature value from bmp085
94+
unsigned int bmp085::baroReadUT()
95+
{
96+
unsigned int ut;
97+
98+
// Write 0x2E into Register 0xF4
99+
// This requests a temperature reading
100+
Wire.beginTransmission(BAR_ADDR);
101+
Wire.write(0xF4);
102+
Wire.write(0x2E);
103+
Wire.endTransmission();
104+
105+
// Wait at least 4.5ms
106+
delay(5);
107+
108+
// Read two bytes from registers 0xF6 and 0xF7
109+
ut = bmp085ReadInt(BAR_ADDR,0xF6);
110+
return ut;
111+
}
112+
113+
114+
// read uncorrected pressure value from bmp085
115+
unsigned long bmp085::baroReadUP()
116+
{
117+
unsigned char msb, lsb, xlsb;
118+
unsigned long up = 0;
119+
120+
// Write 0x34+(OSS<<6) into register 0xF4
121+
// Request a pressure reading w/ oversampling setting
122+
Wire.beginTransmission(BAR_ADDR);
123+
Wire.write(0xF4);
124+
Wire.write(0x34 + (barOSS<<6));
125+
Wire.endTransmission();
126+
127+
// Wait for conversion, delay time dependent on OSS
128+
delay(2 + (3<<barOSS));
129+
130+
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
131+
Wire.beginTransmission(BAR_ADDR);
132+
Wire.write(0xF6);
133+
Wire.endTransmission();
134+
Wire.requestFrom(BAR_ADDR,3);
135+
136+
// Wait for data to become available
137+
while(Wire.available() < 3)
138+
;
139+
msb = Wire.read();
140+
lsb = Wire.read();
141+
xlsb = Wire.read();
142+
143+
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-barOSS);
144+
145+
return up;
146+
}
147+
148+
149+
150+
// read integer on bmp085
151+
int bmp085::bmp085ReadInt(int device, byte address)
152+
{
153+
unsigned char msb, lsb;
154+
155+
Wire.beginTransmission(device);
156+
Wire.write(address);
157+
Wire.endTransmission();
158+
159+
Wire.requestFrom(device, 2);
160+
while(Wire.available()<2)
161+
;
162+
msb = Wire.read();
163+
lsb = Wire.read();
164+
165+
return (int) msb<<8 | lsb;
166+
}
167+
168+
169+
170+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
bmp085.h
3+
libary for using the I2C bmp085 pressure sensor
4+
5+
(c) Written by Jeroen Cappaert for NanoSatisfi, August 2012
6+
*/
7+
8+
9+
#ifndef bmp085_h
10+
#define bmp085_h
11+
12+
#include <Arduino.h>
13+
14+
#define BAR_ADDR 0x77 // Barometric pressure sensor I2C address
15+
16+
17+
class bmp085
18+
{
19+
public:
20+
//constructor
21+
bmp085();
22+
//functions
23+
void configBaro();
24+
int bmp085ReadInt(int device, byte address);
25+
unsigned int baroReadUT();
26+
unsigned long baroReadUP();
27+
float getTempFromBaro(unsigned int ut);
28+
long getPressFromBaro(unsigned long up);
29+
void getBmpData(float bmp[]);
30+
//variables
31+
int ac1;
32+
int ac2;
33+
int ac3;
34+
unsigned int ac4;
35+
unsigned int ac5;
36+
unsigned int ac6;
37+
int b1;
38+
int b2;
39+
int mb;
40+
int mc;
41+
int md;
42+
int barOSS;
43+
long b5;
44+
private:
45+
};
46+
47+
48+
#endif
5.55 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
///=========================================================
2+
// Many-Sensor-on I2C Test
3+
//---------------------------------------------------------
4+
//
5+
// Connect a number of I2C sensors to one Arduino and poll
6+
//
7+
// Author: pplatzer & jcappaert 2012
8+
// (c) nanosatisfi.com
9+
//=========================================================
10+
11+
//Includes
12+
#include <Wire.h> //I2C communication
13+
#include <FreeSixIMU.h> //6DOF
14+
#include <FIMU_ADXL345.h> //Accelerometer
15+
#include <FIMU_ITG3200.h> //Gyro
16+
#include "mag3110.h"
17+
#include "vcnl4000.h"
18+
#include "tmp102.h"
19+
#include "bmp085.h"
20+
21+
//Constants
22+
//General
23+
#define CycleTime 1000 //wait time for next measurements
24+
const int MyI2C = 11; //set own I2C address ID=11
25+
26+
//create instances for sensors
27+
FreeSixIMU sixDOF = FreeSixIMU(); //FreeSixIMU object
28+
mag3110 mag;
29+
vcnl4000 light;
30+
tmp102 temp;
31+
bmp085 pres;
32+
33+
//Define Variables
34+
float fltTemp; //temperature
35+
int intMag[3]; //Magnetic field - x-axis
36+
int intAmbLight; //Ambient Light value
37+
float fltAngles[3]; //Euler Angles
38+
float bmp[2];
39+
40+
41+
//--------------------------------------------------------
42+
// S E T U P
43+
//--------------------------------------------------------
44+
void setup() {
45+
//Serial
46+
Serial.begin(115200);
47+
Serial.println("Set up....");
48+
49+
//I2C Protocoll
50+
Wire.begin(MyI2C); //Join I2C bus as slave # MyI2C
51+
Serial.println("Joining I2C...");
52+
53+
//Configure Sensors
54+
mag.configMag();Serial.println("Magnetometer configured....");//configure Magnetometer
55+
light.configAmb(); Serial.println("Ambient Light configured...");//configure Ambient Light Sensor
56+
sixDOF.init(); Serial.println("Euler Angles configured...");//configure 6DOF Unit
57+
//configBaro();Serial.println("Barometer configured.......");//configure Barometric sensor
58+
pres.configBaro();
59+
60+
//Done Setup
61+
Serial.println("...done setup");
62+
}
63+
64+
//--------------------------------------------------------
65+
// M A I N L O O P
66+
//--------------------------------------------------------
67+
void loop(){
68+
//Measure Temperature
69+
Serial.print("requesting temperature....");
70+
fltTemp = temp.getTemperature();
71+
Serial.print(" Celsius: ");
72+
Serial.println(fltTemp);
73+
74+
//Measure Magnetic Field
75+
Serial.print("requesting mag values.....");
76+
//intMagX = getMagX();
77+
intMag[0] = mag.readx();intMag[1] = mag.ready();intMag[2] = mag.readz();
78+
Serial.print(" myTsla: ");
79+
Serial.print(intMag[0]);Serial.print(" | ");
80+
Serial.print(intMag[1]);Serial.print(" | ");
81+
Serial.println(intMag[2]);
82+
83+
//Measure Ambient Light
84+
Serial.print("requesting Ambient Light..");
85+
intAmbLight = light.readAmbient();
86+
Serial.print(" lux: ");
87+
Serial.println(intAmbLight, DEC);
88+
89+
//Measure Euler Angles
90+
Serial.print("requesting Euler Angles...");
91+
sixDOF.getEuler(fltAngles);
92+
Serial.print(" Angles: ");
93+
Serial.print(fltAngles[0]); Serial.print(" | ");
94+
Serial.print(fltAngles[1]); Serial.print(" | ");
95+
Serial.println(fltAngles[2]);
96+
97+
//Barometric Pressure
98+
Serial.print("requesting Pressure.......");
99+
pres.getBmpData(bmp);
100+
Serial.print(" Pressure: "); Serial.print(bmp[1]);
101+
Serial.print(" BaroTemp: "); Serial.println(bmp[0]);
102+
103+
104+
105+
//Wait 1 second for next measurements
106+
Serial.println("---------------------------------------------------------");
107+
delay(CycleTime);
108+
}
109+

0 commit comments

Comments
 (0)