I am trying to build a weather station with these components:
- BMP280 barometric sensor (Temperature... Pressure... Humidity)
- Arduino Uno
- 50K potentiometer
I wrote/modified the code below and I could only achieve these:
A
- I get the barometric reading of my room alright.
- I display a hard coded string on the LCD display
However I will like to achieve:
B
- I get the barometric reading of my room alright.
- I display a hard coded string (name) on the LCD display
- Write the reading to the SD card object
- Read the the SD card object and display it on the LCD screen
- Alternate display of the name (250 ms) and barometric info (temperature, Pressure, Humidity) on SD card (500 ms)
//LCD1602
//You should now see your LCD1602 display the flowing characters "SUNFOUNDER" and "hello, world"
//Email:support@sunfounder.com
//Website:www.sunfounder.com
//2015.5.7
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include<Wire.h>
#include "SparkFunBME280.h"
#include <LiquidCrystal.h>// include the library code
//File mySensorData; //File object to write data to
/**********************************************************/
BME280 mySensorA; //Uses default I2C address 0x77
BME280 mySensorB; //Uses I2C address 0x76 (jumper closed)
/**********************************************************/
char array1[]=" Simpx, Inc "; //the string to print on the LCD
char array2[]="Lync Platform! "; //the string to print on the LCD
int tim = 500; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
/*********************************************************/
void setup()
{
//Write Headers to micro SD object in file <name.*>
/************************************************************/
/*{
const int chipSelect = 8; //Maybe not yours!!.You have to put your cs pin here
pinMode(8, OUTPUT);
SD.begin(chipSelect);
mySensorData = SD.open("PTHData.txt", FILE_WRITE); //it is asking to open PTHData.txt
mySensorData.println(" Temperature, Pressure, Humidity" );
mySensorData.close();
}*/
/************************************************************/
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
Serial.begin(9600);
Serial.println("Example showing alternate I2C addresses");
Wire.begin();
mySensorA.setI2CAddress(0x76); //The default for the SparkFun Environmental Combo board is 0x77 (jumper open).
//If you close the jumper it is 0x76
//The I2C address must be set before .begin() otherwise the cal values will fail to load.
if(mySensorA.beginI2C() == false) Serial.println("Sensor A connect failed");
mySensorB.setI2CAddress(0x76); //Connect to a second sensor
if(mySensorB.beginI2C() == false) Serial.println("Sensor B connect failed");
}
/*********************************************************/
void loop()
{
lcd.setCursor(15,0); // set the cursor to column 15, line 0
for ( int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++)
{
lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
lcd.print(array1[positionCounter1]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
lcd.setCursor(15,1); // set the cursor to column 15, line 1
for (int positionCounter2 = 0; positionCounter2 < 26; positionCounter2++)
{
lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
lcd.print(array2[positionCounter2]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
Serial.print("HumidityA: ");
Serial.print(mySensorA.readFloatHumidity(), 0);
Serial.print(" PressureA: ");
Serial.print(mySensorA.readFloatPressure(), 0);
Serial.print(" TempA: ");
//Serial.print(mySensorA.readTempC(), 2);
Serial.print(mySensorA.readTempF(), 2);
Serial.print(" Humidity Room: ");
Serial.print(mySensorB.readFloatHumidity(), 0);
Serial.print("%");
Serial.print(" Pressure Room: ");
Serial.print(mySensorB.readFloatPressure(), 0);
Serial.print(" Pa ");
Serial.print(" Temperatur Room: ");
//Serial.print(mySensorB.readTempC(), 2);
Serial.print(mySensorB.readTempF(), 2);
Serial.print( " degrees F ");
Serial.println();
delay(100);
/* {
mySensorData = SD.open("PTHData.txt", FILE_WRITE);
float tempR = mySensorB.readTempF();
float presR = mySensorB.readFloatPressure();
float humdR = mySensorB.readFloatHumidity();
*********Make sure the righ object writes the right values*******
if(mySensorData) {
mySensorData.print(tempR); //write temperature data to card
mySensorData.print(","); //write a commma
mySensorData.print(presR); //write pressure and end the line (println)
mySensorData.print(","); //write a commma
mySensorData.println(humdR); //write temperature data to card
mySensorData.print(","); //write a comma
mySensorData.close();
delay(500);
}*/
}
Right now this code will give you a solution for:
A1
A2
FYI
When I un-comment these lines of code I get A1 as solution and nothing was written to micro SD object. I failed woefully to achieve my goal. Any help will be appreciated thanks.