Skip to content

Commit 172e1a4

Browse files
Cleaned up directories and documentation
1 parent ed9ed81 commit 172e1a4

File tree

13 files changed

+1193
-62
lines changed

13 files changed

+1193
-62
lines changed

examples/CSV_Output/CSV_Output.ino

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/******************************************************************************
2+
CSV_Output.ino
3+
BME280 Arduino and Teensy example
4+
Marshall Taylor @ SparkFun Electronics
5+
May 20, 2015
6+
https://github.com/sparkfun/SparkFun_BME280_Arduino_Library
7+
8+
This sketch configures two BME280 to produce comma separated values for use
9+
in generating spreadsheet graphs.
10+
in 10 being used for chip select.
11+
12+
Resources:
13+
Uses Wire.h for I2C operation
14+
Uses SPI.h for SPI operation
15+
16+
Development environment specifics:
17+
Arduino IDE 1.6.4
18+
Teensy loader 1.23
19+
20+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
21+
Please review the LICENSE.md file included with this example. If you have any questions
22+
or concerns with licensing, please contact [email protected].
23+
Distributed as-is; no warranty is given.
24+
******************************************************************************/
25+
26+
#include <stdint.h>
27+
#include "SparkFunBME280.h"
28+
29+
#include "Wire.h"
30+
#include "SPI.h"
31+
32+
//Global sensor object
33+
BME280 mySensor;
34+
35+
unsigned int sampleNumber = 0; //For counting number of CSV rows
36+
37+
void setup()
38+
{
39+
//***Driver settings********************************//
40+
//commInterface can be I2C_MODE or SPI_MODE
41+
//specify chipSelectPin using arduino pin names
42+
//specify I2C address. Can be 0x77(default) or 0x76
43+
44+
//For I2C, enable the following and disable the SPI section
45+
mySensor.settings.commInterface = I2C_MODE;
46+
mySensor.settings.I2CAddress = 0x77;
47+
48+
//For SPI enable the following and dissable the I2C section
49+
//mySensor.settings.commInterface = SPI_MODE;
50+
//mySensor.settings.chipSelectPin = 10;
51+
52+
53+
//***Operation settings*****************************//
54+
mySensor.settings.runMode = 3; // 3, Normal mode
55+
mySensor.settings.tStandby = 0; // 0, 0.5ms
56+
mySensor.settings.filter = 0; // 0, filter off
57+
//tempOverSample can be:
58+
// 0, skipped
59+
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
60+
mySensor.settings.tempOverSample = 1;
61+
//pressOverSample can be:
62+
// 0, skipped
63+
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
64+
mySensor.settings.pressOverSample = 1;
65+
//humidOverSample can be:
66+
// 0, skipped
67+
// 1 through 5, oversampling *1, *2, *4, *8, *16 respectively
68+
mySensor.settings.humidOverSample = 1;
69+
70+
Serial.begin(57600);
71+
Serial.print("Program Started\n");
72+
Serial.print("Starting BME280... result of .begin(): 0x");
73+
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
74+
//Calling .begin() causes the settings to be loaded
75+
Serial.println(mySensor.begin(), HEX);
76+
77+
//Build a first-row of column headers
78+
Serial.print("\n\n");
79+
Serial.print("Sample,");
80+
Serial.print("T(deg C),");
81+
Serial.print("T(deg F),");
82+
Serial.print("P(kPa),");
83+
Serial.print("Alt(m),");
84+
Serial.print("Alt(ft),");
85+
Serial.print("%RH");
86+
Serial.println("");
87+
88+
}
89+
90+
void loop()
91+
{
92+
93+
//Print each row in the loop
94+
Serial.print(sampleNumber);
95+
Serial.print(",");
96+
Serial.print(mySensor.readTempC(), 2);
97+
Serial.print(",");
98+
Serial.print(mySensor.readTempF(), 3);
99+
Serial.print(",");
100+
Serial.print(mySensor.readFloatPressure(), 0);
101+
Serial.print(",");
102+
Serial.print(mySensor.readFloatAltitudeMeters(), 3);
103+
Serial.print(",");
104+
Serial.print(mySensor.readFloatAltitudeFeet(), 3);
105+
Serial.print(",");
106+
Serial.print(mySensor.readFloatHumidity(), 0);
107+
Serial.println();
108+
109+
sampleNumber++;
110+
111+
delay(50);
112+
113+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include "CircularBuffer.h"
2+
#include <stdint.h>
3+
4+
//****************************************************************************//
5+
//
6+
// Circular buffer
7+
//
8+
//****************************************************************************//
9+
10+
//Construct a CircularBuffer type with arguments
11+
// uint16_t inputSize: number of elements
12+
CircularBuffer::CircularBuffer(uint16_t inputSize)
13+
{
14+
cBufferData = new float[inputSize];
15+
cBufferLastPtr = 0;
16+
cBufferElementsUsed = 0;
17+
cBufferSize = inputSize;
18+
19+
}
20+
21+
CircularBuffer::~CircularBuffer()
22+
{
23+
delete[] cBufferData;
24+
25+
}
26+
27+
//Get an element at some depth into the circular buffer
28+
//zero is the push location. Max is cBufferSize - 1
29+
//
30+
//Arguments:
31+
// uint16_t elementNum: number of element in
32+
//
33+
float CircularBuffer::getElement( uint16_t elementNum )
34+
{
35+
//Translate elementNum into terms of cBufferLastPtr.
36+
int16_t virtualElementNum;
37+
virtualElementNum = cBufferLastPtr - elementNum;
38+
if( virtualElementNum < 0 )
39+
{
40+
virtualElementNum += cBufferSize;
41+
}
42+
43+
//Output the value
44+
return cBufferData[virtualElementNum];
45+
}
46+
47+
//Put a new element into the buffer.
48+
//This also expands the size up to the max size
49+
//Arguments:
50+
//
51+
// int16_t elementVal: value of new element
52+
//
53+
void CircularBuffer::pushElement( float elementVal )
54+
{
55+
//inc. the pointer
56+
cBufferLastPtr++;
57+
58+
//deal with roll
59+
if( cBufferLastPtr >= cBufferSize )
60+
{
61+
cBufferLastPtr = 0;
62+
}
63+
64+
//write data
65+
cBufferData[cBufferLastPtr] = elementVal;
66+
67+
//increase length up to cBufferSize
68+
if( cBufferElementsUsed < cBufferSize )
69+
{
70+
cBufferElementsUsed++;
71+
}
72+
}
73+
74+
//Averages the last n numbers and provides that. Discards fractions
75+
float CircularBuffer::averageLast( uint16_t numElements )
76+
{
77+
if( numElements < recordLength() )
78+
{
79+
numElements = recordLength();
80+
}
81+
//Add up all the elements
82+
float accumulator = 0;
83+
int8_t i;
84+
for( i = 0; i < numElements; i++ )
85+
{
86+
accumulator += getElement( i );
87+
}
88+
//Divide by number of elements
89+
if( numElements != 0 )
90+
{
91+
accumulator /= numElements;
92+
}
93+
else
94+
{
95+
accumulator = 0;
96+
}
97+
return accumulator;
98+
}
99+
100+
//Returns the current size of the buffer
101+
uint16_t CircularBuffer::recordLength( void )
102+
{
103+
return cBufferElementsUsed;
104+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef CIRCULARBUFFER_H
2+
#define CIRCULARBUFFER_H
3+
#include <stdint.h>
4+
5+
//****************************************************************************//
6+
//
7+
// Circular Buffer
8+
//
9+
//****************************************************************************//
10+
11+
//Class CircularBuffer is int16_t
12+
//Does not care about over-running real data ( if request is outside length's bounds ).
13+
//For example, the underlying machine writes [48], [49], [0], [1] ...
14+
15+
class CircularBuffer
16+
{
17+
public:
18+
CircularBuffer( uint16_t inputSize );
19+
~CircularBuffer();
20+
float getElement( uint16_t ); //zero is the push location
21+
void pushElement( float );
22+
float averageLast( uint16_t );
23+
uint16_t recordLength( void );
24+
private:
25+
uint16_t cBufferSize;
26+
float *cBufferData;
27+
int16_t cBufferLastPtr;
28+
uint8_t cBufferElementsUsed;
29+
};
30+
31+
32+
33+
#endif // CIRCULARBUFFER_H

0 commit comments

Comments
 (0)