I am trying to display the values indicated right at the bottom of the code. For some reason they do not show up. I want it to loop like the data logging information. Any suggestions will be hugely appreciated. Thank you:
#include <SD.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
#include "RTClib.h"
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
#include <LiquidCrystal.h>
File myFile;
Adafruit_INA219 ina219;
RTC_DS1307 RTC;
int temperaturePin = 0;
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
Serial.begin(115200);
ina219.begin();
Wire.begin();
RTC.begin();
lcd.begin(16, 2);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("Starting Adafruit TSL2591 Test!");
if (tsl.begin())
{
Serial.println("Found a TSL2591 sensor");
}
else
{
Serial.println("No sensor found ... check your wiring?");
while (1);
}
/* Configure the sensor */
configureSensor();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(DATE, TIME));
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
}
void configureSensor(void)
{
tsl.setGain(TSL2591_GAIN_MED);
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);
}
void unifiedSensorAPIRead(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light <-4294966000.0))
{
/* If event.light = 0 lux the sensor is probably saturated /
/ and no reliable data could be generated! /
/ if event.light is +/- 4294967040 there was a float over/underflow */
Serial.println("Invalid data (adjust gain or timing)");
}
else
{
Serial.print(event.light); Serial.println(" lux");
}
}
void unifiedSensorAPIWrite(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light <-4294966000.0))
{
/* If event.light = 0 lux the sensor is probably saturated /
/ and no reliable data could be generated! /
/ if event.light is +/- 4294967040 there was a float over/underflow */
myFile.println("Invalid data (adjust gain or timing)");
}
else
{
myFile.print(event.light); myFile.println(" lux");
}
}
void unifiedSensorAPILCD(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light <-4294966000.0))
{
/* If event.light = 0 lux the sensor is probably saturated /
/ and no reliable data could be generated! /
/ if event.light is +/- 4294967040 there was a float over/underflow */
lcd.println("0 lux");
}
else
{
lcd.print(event.light); lcd.println(" lx");
}
}
void loop()
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
float temperature = getVoltage(temperaturePin);
temperature = (temperature - .5) * 100;
DateTime now = RTC.now();
myFile = SD.open("datalog.txt", FILE_WRITE);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
myFile.print("Bus Voltage: "); myFile.print(busvoltage); myFile.println(" V");
myFile.print("Shunt Voltage: "); myFile.print(shuntvoltage); myFile.println(" mV");
myFile.print("Load Voltage: "); myFile.print(loadvoltage); myFile.println(" V");
myFile.print("Current: "); myFile.print(current_mA); myFile.println(" mA");
unifiedSensorAPIRead();
unifiedSensorAPIWrite();
Serial.print("Temp: "); Serial.print(temperature); Serial.println(" degree Celsius");
myFile.print("Temp: "); myFile.print(temperature); myFile.println(" degree Celsius");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
myFile.print(now.year(), DEC);
myFile.print('/');
myFile.print(now.month(), DEC);
myFile.print('/');
myFile.print(now.day(), DEC);
myFile.print(' ');
myFile.print(now.hour(), DEC);
myFile.print(':');
myFile.print(now.minute(), DEC);
myFile.print(':');
myFile.print(now.second(), DEC);
myFile.println();
Serial.println("");
myFile.println("");
// close the file:
myFile.close();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(busvoltage); lcd.print(" V");
lcd.print(current_mA); lcd.print(" mA");
lcd.setCursor(0, 1);
unifiedSensorAPILCD();
lcd.print(temperature); lcd.print(" C");
delay(5000);
}
float getVoltage(int pin)
{
return (analogRead(pin) * .004882814);
}