When i run the program the the readings are 0.000 and nothing is writen to the SD
here is th code:
#include “SPI.h”
#include “RTClib.h”
#include <SD.h>
#include <LiquidCrystal_I2C.h>
//Constant for Chip select pin used
const uint8_t CS = 10;
//SDcard ChipSelect and initialazation
int CSsd=4;
File myFile;
int mod1=6;
int mod2=7;
int mod3=8;
RTC_DS1307 RTC;
LiquidCrystal_I2C lcd(0x27,16,2);
//Constants for commands to be sent to the LDE/LME device.
const uint8_t READ_LDE = 0x2D;
const uint8_t SEND2DHR = 0x14;
const uint8_t READ_DHR = 0x98;
const float SCALE_FACTOR = 1200.0;
void setup() {
//Initialise Serial UART communication
Serial.begin(9600);
lcd.init();
lcd.backlight();
RTC.begin();
//Initialise SPI communication
SPI.begin();
//Initialise Chip Select pin
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
pinMode(CSsd, OUTPUT);
pinMode (mod1, INPUT_PULLUP);
pinMode (mod2, INPUT_PULLUP);
pinMode (mod3, INPUT_PULLUP);
SD.begin();
lcd.setCursor (0,0);
lcd.print (" Pitot Sensor");
lcd.setCursor (0,1);
lcd.print (" Lab Edition");
delay (3000);
RTC.adjust(DateTime(DATE, TIME)); // to Adjust clock If Battery gone
}
// The main program loop continuously gets a pressure measurement.
void loop() {
// ---------------------------------Pressure read--------------------------
// Create a buffer to read the result into.
uint16_t val;
// Send the command to poll the current pressure reading.
writeByte(READ_LDE);
// Send the command to send the pressure reading to the data register.
writeByte(SEND2DHR);
// Send the command to read the data register.
writeByte(READ_DHR);
// Read the first byte back from the LDE/LME sensor.
val = readByte();
// Shift this byte up.
val <<= 8;
// Read the second byte back from the LDE/LME sensor.
val |= readByte();
// Get the value of the pressure measurement in Pascals.
float result = val / SCALE_FACTOR;
if (result > 27.306) {
result=result-54.612;
}
delay (50);
// -----------------------End of Pressure Read----------------
DateTime now = RTC.now();
String dt; //Date
String tim; //Time
String dnt; //Date And Time To SD
String SDline; //Data to SD
String DispLn0; //First Display line
String DispLn1; //Secound Display line
String Filenm=“temp”; //Filename
String Serline; //Serial display line
// ----------------Calculating Time and date Data-----------------
dt="";
tim="";
if ((now.day()< 10))
dt=dt+“0”;
dt=dt+String(now.day());
Filenm=Filenm+dt;
dt=dt+"/";
if ((now.month()< 10))
dt=dt+“0”;
dt=dt+String(now.month())+"/";
if ((now.month()< 10))
Filenm=Filenm+“0”;
Filenm=Filenm+String(now.month())+".txt";
dt=dt+String(now.year());
if ((now.hour()< 10))
tim=tim+“0”;
tim=tim+String(now.hour())+":";
if ((now.minute()< 10))
tim=tim+“0”;
tim=tim+String(now.minute())+":";
if ((now.second()< 10))
tim=tim+“0”;
tim=tim+String(now.second());
dnt=dt+" "+tim;
// -----------------Finish Calculating time and date--------------
if (digitalRead(mod1)==LOW) {
DispLn0= “Dyn P[Pa]: “;
DispLn1=String (result,3);
}
else if (digitalRead(mod2)==LOW) {
DispLn0= “Air Flow[m/s]: “;
float airs=sqrt((2abs(result))/1.225);
if (airs>=0) {
DispLn1=String (airs,3);
}
else {
DispLn1="-"+ String (airs,3);
}
}
else if (digitalRead(mod3)==LOW) {
DispLn0= “Water Flow[m/s]:”;
float waters=sqrt((2abs(result))/1013);
if (waters>=0) {
DispLn1=String (waters,3);
}
else {
DispLn1=”-”+ String (waters,3);
}
}
else {
DispLn0=” Huston We Have”;
DispLn1=" A PROBLEM";
}
lcd.clear();
lcd.setCursor (0,0);
lcd.print (DispLn0);
lcd.setCursor (0,1);
lcd.print (DispLn1);
//print result to serial Monitor
Serline=dnt+" Dynamic Pressure="+String(result, 3)+" [Pa]";
Serial.println(Serline);
//Save Data To SD Card
SDline=dnt+" "+String(result,3);
File myFile;
myFile = SD.open(Filenm, FILE_WRITE);
myFile.println (SDline);
myFile.close();
//loop around for a new read every half second
delay(500);
}
// ----------------------------Subrutines-------------------
// Send one byte to the sensor.
void writeByte(uint8_t toSend) {
// Drive the CS pin low to enable communication with the slave.
digitalWrite(CS, LOW);
//Send the byte to sensor
SPI.transfer(toSend);
delay (50);
// Drive the CS pin high to disable communication with the slave.
digitalWrite(CS, HIGH);
}
// Read one byte from the sensor.
uint8_t readByte() {
// Create a variable to store the received byte.
uint8_t data;
// Drive the CS pin low to enable communication with the slave.
digitalWrite(CS, LOW);
//Read value from sensor
data = SPI.transfer(0x00);
delay (50);
// Drive the CS pin high to disable communication with the slave.
digitalWrite(CS, HIGH);
return data;
}
Thank You