So @des107
What happens if you load this code
#include <Adafruit_ADS1X15.h>
#include "RTClib.h"
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
// The following define your basic variables: ---------------------------------------------------------------------------------------
#define LOG_INTERVAL 10000 // mills between entries (set to 10,000 for 10 seconds)
#define SYNC_INTERVAL 10000 // mills between calls to "flush()" (write data to the card)
uint32_t syncTime = 0; // time of last "sync()"
#define LED1 2 // Make LED1 Controlled by Pin 2 on the Arduino
#define LED2 3 // Make LED2 Controlled by Pin 3 on the Arduino
const int chipSelect = 10; // The Data Logging Shield uses Pin 10 to communicate with the SD Card
const int ADS1115_ADDRESS = 0x48; // Set the I2C address of the ADS1115 ADC (Wire.h allows for multiple devices to be connected to the same SDA/SCL pins)
const int RTC_ADDRESS = 0x68; // Set the I2C address of the DS3231 RTC
Adafruit_ADS1115 adc; // Create an Object for the ADC
RTC_DS3231 rtc; // Create an Object for the RTC
File logfile; // Create the Variable for the File data type
// Enum to represent the four different error types----------------------------------------------------------------------------------
enum ErrorType {
ERROR_RTC,
ERROR_ADC,
ERROR_SD_CARD,
ERROR_OPEN_FILE
};
// These are the three functions that will be called upon continuously in the loop---------------------------------------------------
// They check to ensure that the RTC, ADC, and SD Card are still connected/working properly
bool isRTCConnected() {
return rtc.begin(); // Try to initialize the RTC and return the success status
}
bool isADCConnected() {
return adc.begin(ADS1115_ADDRESS); // Try to initialize the ADC and return the success status
}
bool isSDCardConnected() {
return SD.begin(chipSelect); // Try to initialize the SD card and return the success status
}
// Used for flashing LEDS for a way of user debugging--------------------------------------------------------------------------------
void flashLED(int pin, int flashes, int onTime, int offTime) { // This sets up a function to flash the debugging LEDs using the: pin, number of flashes, on time (ms), and off time (ms)
for (int i = 0; i < flashes; i++) { // This creates the loop. For "i" amount (the number of flashes):
digitalWrite(pin, HIGH); // Turn on the LED at the pin
delay(onTime); // For however many milliseconds
digitalWrite(pin, LOW); // Turn off the LED at the pin
delay(offTime); // For however many milliseconds
}
}
// The following section is created for debugging purposes---------------------------------------------------------------------------
void error(char *str, ErrorType errorType) {
digitalWrite(LED1, LOW);
while (!isRTCConnected() || !isADCConnected() || !isSDCardConnected() || errorType == ERROR_OPEN_FILE) {
switch (errorType) {
case ERROR_RTC:
flashLED(LED2, 3, 200, 200);
delay(5000);
break;
case ERROR_ADC:
flashLED(LED2, 6, 200, 200);
delay(5000);
break;
case ERROR_SD_CARD:
flashLED(LED2, 3, 500, 500);
delay(5000);
break;
case ERROR_OPEN_FILE:
flashLED(LED2, 6, 500, 500);
delay(5000);
break;
default:
break;
}
}
}
// Create the file's date&time signature---------------------------------------------------------------------------------------------
void dateTime(uint16_t* date, uint16_t* time) { // This function is used to set the date of the file in your file explorer
DateTime now = rtc.now(); // This initializes the RTC
*date = FAT_DATE(now.year(), now.month(), now.day()); // This returns the date using FAT_DATE macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second()); // This returns the time using FAT_TIME macro to format fields
}
// These are your initial setup parameters-------------------------------------------------------------------------------------------
void setup(void)
{
Serial.begin(9600); // Begins Serial Communication b/t Arduino and Computer
// Set-up the Debugging LEDs
pinMode(LED1, OUTPUT); // Makes the pin that LED1 is connected to an output
pinMode(LED2, OUTPUT); // Makes the pin that LED2 is connected to an output
digitalWrite(LED1, HIGH); // Turns on LED1 to indicate the code is being executed with no problems
Wire.begin(); // Calls upon the Wire.h library to initialize
rtc.begin(); // Initialize the DS3231 RTC
if (!rtc.begin()) { // If initializing the RTC fails:
error(ERROR_RTC); // This defines what will be typed on screen, along with what error type will be called
}
// Un-Comment the following Lines to Adjust the Time on the RTC (then comment them out again once it has been adjusted!)
//DateTime adjustedTime(2023, 7, 6, 8, 22, 00); // Set the desired date and time
//rtc.adjust(adjustedTime); // Adjust the RTC time
adc.begin(ADS1115_ADDRESS); // Initialize the ADS1115 ADC with the desired I2C address
if (!adc.begin(ADS1115_ADDRESS)) { // If initializing the ADC fails:
error(ERROR_ADC); // This defines what will be typed on screen, along with what error type will be called
}
// Initialize the SD Card
pinMode(10, OUTPUT); // Pin 10 is used to communicate with the SD Card
if (!SD.begin(chipSelect)) {
error(ERROR_SD_CARD); // If the SD Card cannot be connected to:
}
// Create a New File
char filename[13]; // Buffer to hold the filename (8 characters for "YY-MM-DD", 1 for '.', 3 for "CSV", and 1 for null terminator)
DateTime now = rtc.now(); // Sets the DateTime variable to the current time
SdFile::dateTimeCallback(dateTime); // This is used to set the date of the file in your file explorer
// Open the logfile with UTF-8 encoding. This is necessary so that there is not problem with the "°" Symbol
logfile = SD.open(filename, FILE_WRITE | O_WRITE | O_CREAT | O_APPEND);
if (!logfile) { // If there is a problem with opening the file:
error( ERROR_OPEN_FILE); // This defines what will be typed on screen, along with what error type will be called
}
logfile.print("\xEF\xBB\xBF"); // Write UTF-8 BOM to indicate the encoding
}
// The following is what loops over and over again; in this case, collecting and writing data----------------------------------------
void loop()
{
if (!isRTCConnected()) {
error(ERROR_RTC);
}
if (!isADCConnected()) {
error(ERROR_ADC);
}
if (!isSDCardConnected()) {
error(ERROR_SD_CARD);
}
digitalWrite(LED1, HIGH); // Turns on LED1 to indicate the code is executing with no problems
// Read the Current Time from the RTC
DateTime now = rtc.now();
// Convert Date and Time Values to Strings with Leading Zeros
String yearString = now.year() < 10 ? "0" + String(now.year()) : String(now.year());
String monthString = now.month() < 10 ? "0" + String(now.month()) : String(now.month());
String dayString = now.day() < 10 ? "0" + String(now.day()) : String(now.day());
String hourString = now.hour() < 10 ? "0" + String(now.hour()) : String(now.hour());
String minuteString = now.minute() < 10 ? "0" + String(now.minute()) : String(now.minute());
String secondString = now.second() < 10 ? "0" + String(now.second()) : String(now.second());
String ymdhms = yearString + "-" + monthString + "-" + dayString + " " + hourString + ":" + minuteString + ":" + secondString;
// Use an Array to Store Voltage and Temperature Values for All 4 Channels
float voltages[4];
float temperatures[4];
// Loop Through all 4 Channels, Read the Voltages, Convert it to Temperature
for (uint8_t channel = 0; channel < 4; channel++)
{
int16_t adcValue = adc.readADC_SingleEnded(channel); // Read from the current channel
float voltage = adcValue * 0.0001875; // Convert raw value to voltage (6.144V / (2^15bits))
voltages[channel] = voltage; // Sets the voltage to the voltage for each respective channel
float temperature = voltage * (1800 / 5); // Convert the voltage to a temperature (0-5v = 0-1800°C type of scale)
temperatures[channel] = temperature; // Sets the temperature to the temperature for each respective channel
}
// Serial Print data
for (uint8_t i=0; i<4; i++)
{
}
for (uint8_t i=0; i<4; i++)
{
}
// Log data to SD Card
logfile.print(ymdhms);
logfile.print(",");
for (uint8_t i=0; i<4; i++)
{
logfile.print(voltages[i], 3);
logfile.print(",");
}
for (uint8_t i=0; i<4; i++)
{
logfile.print(temperatures[i], 0);
logfile.print(",");
}
logfile.println();
// Delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
// Check Passage of Time
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
// Turn On Red LED, Write Data to SD Card, Turn Off Red LED
digitalWrite(LED2, HIGH);
delay(500);
logfile.flush();
delay(500);
digitalWrite(LED2, LOW);
}
What happens now
also.... Why do you have this
void setup(void)
???
Shouldn't it be
void setup()
{
}