Help writing for ADAFRUIT Data logger + digital flow sensor,

Hello, all arduino experts!
i am very new to arduino and its a bit hard for me to find the right stuff.

i managed to program the RTC for the current time, BUT

can anyone help me to write a small program for arduino UNO + ADAFRUIT data logger shield?

the idea is to log the water flow rate during a long period for future use in a graph (like excel)
so it needs to be written with a time stamp from the onboard RTC to the SD card.

i will use a digital flow sensor (VCC/GND/DATA)
but i will be happy if the code will contain another connection also to an analog sensor (like temperature)

i want this as my utility company is probably wrongly calculation my water usage and billing me for a whole lot more.

can anyone please help? :slight_smile:
i am sure than an expert can write this code within 5 minutes.

much appreciated!

ms2000:
i am sure than an expert can write this code within 5 minutes.

I am sure that an "expert" would want to be paid to do your work/homework problem.

by expert i meant not a person who does this for living and want to get rich off my silly project, a person who is an expert due to experience

i participate and help in electronics forums and do drawings and many calculations for lots of people that needs help, never occurred to me to ask for money, :o if that is the situation here its actually very sad. :confused:
so if no one helps others i guess when i will learn i wont be sharing my knowledge either...

ms2000:
by expert i meant not a person who does this for living and want to get rich off my silly project, a person who is an expert due to experience

i participate and help in electronics forums and do drawings and many calculations for lots of people that needs help, never occurred to me to ask for money, :o if that is the situation here its actually very sad. :confused:
so if no one helps others i guess when i will learn i wont be sharing my knowledge either...

Sharing knowledge is one thing. Many many people do that here.

Expecting someone to do write your WHOLE program is ridiculous.

ms2000:
can anyone help me to write a small program for arduino UNO + ADAFRUIT data logger shield?

i am sure than an expert can write this code within 5 minutes.

Which? Do you want help or do you want to hire someone?

I have a sketch that reads three thermistors over and over and logs them to an SD card with a date-time group.

If you still need some sample code, let me know.

w2rg at w2rg dot net

A start....

#include <Wire.h>
#include <SPI.h>
#include <SdFat.h>
//#include <Ethernet.h>
#include <HX711.h>
HX711 scale(A0, A1);//forwards for orange board
HX711 scale2(A2, A3);//forwards for orange board
//HX711 scale2(A2,A3);//forwards for orange board
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
//Adafruit_ADS1015 ads;     /* Use thi for the 12-bit version */
float sConst[2] = {
  //  912.2,//5Kg Nominal
  833.5,//5Kg
  408.8//10Kg Nominal
};
boolean advance;
int gopin = 7;
int internalRAW;
double internalTEMP;
float grossraw;
float gross;
float grossraw2;
float gross2;
float ti01;
int speedy;
char tbuf[10]={
  ' ','\0'};
// SD chip select pin.  Be sure to disable any other SPI devices such as Enet.
const uint8_t chipSelect = SS;

// Interval between data records in milliseconds.
// The interval must be greater than the maximum SD write latency plus the
// time to acquire and write data to the SD to avoid overrun errors.
// Run the bench example to check the quality of your SD card.
const uint32_t SAMPLE_INTERVAL_MS = 200;
//==============================================================================
// Error messages stored in flash.
#define error(msg) sd.errorHalt(F(msg))
// Log file base name.  Must be six characters or less.
#define FILE_BASE_NAME "Data"
//------------------------------------------------------------------------------
// File system object.
SdFat sd;

// Log file.
SdFile file;

// Time in micros for next data record.
uint32_t logTime;

//==============================================================================
// User functions.  Edit writeHeader() and logData() for your requirements.

const uint8_t ANALOG_COUNT = 4;
//------------------------------------------------------------------------------
// Write data header.
void writeHeader() {
  file.print(F("micros"));
  for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    file.print(F(",adc"));
    file.print(i, DEC);
  }
  file.println();
}
//------------------------------------------------------------------------------
// Log a data record.
void logData() {
  uint16_t data[ANALOG_COUNT];

  // Read all channels to avoid SD write latency between readings.
  for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    data[i] = analogRead(i);
  }
  // Write data to file.  Start with log time in micros.
  file.print(logTime);

  // Write ADC data to CSV record.
  for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    file.write(',');
    file.print(data[i]);
  }
  file.println();
}
//thermistor linearize
double Thermistor(int RawADC) {
  double Temp;
  Temp = log(10000.0*((1024.0/RawADC-1))); 
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius
  //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  return Temp;
}
float scalar(float x, float in_min,  float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void setup(void) 
{
  /*
    uint8_t mac[]     = { 
   0x90, 0xA2, 0xDA, 0x00, 0x51, 0x06               };
   uint8_t ip[]      = { 
   192, 168, 0, 6               };
   uint8_t gateway[] = { 
   192, 168, 0, 1               };
   uint8_t subnet[]  = { 
   255, 255, 255, 0               };
   Ethernet.begin(mac, ip, gateway, subnet);
   delay(5000);
   */
  const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
  char fileName[13] = FILE_BASE_NAME "00.csv";

  delay(1000);



  // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }
  // Find an unused file name.
  if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
  }
  while (sd.exists(fileName)) {
    if (fileName[BASE_NAME_SIZE + 1] != '9') {
      fileName[BASE_NAME_SIZE + 1]++;
    } 
    else if (fileName[BASE_NAME_SIZE] != '9') {
      fileName[BASE_NAME_SIZE + 1] = '0';
      fileName[BASE_NAME_SIZE]++;
    } 
    else {
      error("Can't create file name");
    }
  }
  if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
    error("file.open");
  }
  do {
    delay(10);
  } 
  while (Serial.read() >= 0);

  Serial.print(F("Logging to: "));
  Serial.println(fileName);
  Serial.println(F("Type any character to stop"));

  // Write data header.
  writeHeader();

  // Start on a multiple of the sample interval.
  logTime = micros()/(1000UL*SAMPLE_INTERVAL_MS) + 1;
  logTime *= 1000UL*SAMPLE_INTERVAL_MS;
  ////////////////////////////////////////////////////////////////////////////
  //zero the scale

  scale.set_scale();
  //Average 2 values;
  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.set_scale(sConst[0]);
  delay (100);
  scale.tare();
  //ITare[0]= float(scale.get_units(2))/1000.0;
  delay (100);
  grossraw= float(scale.get_units(10))/1000.0;
  delay (100);
  scale.tare();

  //zero the scale2

  scale2.set_scale();
  //Average 2 values;
  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale2.set_scale(sConst[1]);
  delay (100);
  scale2.tare();
  //ITare[0]= float(scale.get_units(2))/1000.0;
  delay (100);
  grossraw2= float(scale2.get_units(10))/1000.0;
  delay (100);
  scale2.tare();

  Serial.begin(9600);
  pinMode(9,OUTPUT);
  pinMode(7, INPUT);
  Serial.println("Hello!");
  digitalWrite(7, LOW); 
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)

  ads.begin();
}

void loop(void) 
{

  int16_t adc0, adc1, adc2, adc3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  Serial.print("AIN0: "); 
  Serial.println(adc0);
  Serial.print("AIN1: "); 
  Serial.println(adc1);
  Serial.print("AIN2: "); 
  Serial.println(adc2);
  Serial.print("AIN3: "); 
  Serial.println(adc3);
  Serial.println(" ");
  int pin4 = digitalRead(4);
  int pin5 = digitalRead(5);
  int pin6 = digitalRead(6);
  int pin7 = digitalRead(7);
  int pin8 = digitalRead(8);
  //print out the value of the pushbutton
  Serial.print("pin4 :"); 
  Serial.println(pin4);
  Serial.print("pin5 :"); 
  Serial.println(pin5);
  Serial.print("pin6 :"); 
  Serial.println(pin6);
  Serial.print("pin7 :"); 
  Serial.println(pin7);
  Serial.print("pin8 :"); 
  Serial.println(pin8);  

  grossraw = float (scale.get_units())/1000.0;
  grossraw2 = float (scale2.get_units())/1000.0;
  advance = digitalRead(gopin);
  internalRAW=analogRead(A1);
  internalTEMP =  Thermistor(internalRAW);
  if abs(grossraw < 20.0) gross=grossraw;


  ti01 = (adc3-3200)/146.7 +10.0;
  speedy = int (-grossraw*1024)+200;
  if (speedy>255) speedy = 255;
  Serial.print("Grossraw: ");
  Serial.println(grossraw,6);
  Serial.print("Grossraw2: ");
  Serial.println(grossraw2,6);
  Serial.print("Internal Temp: ");
  Serial.print("TI01:)");
  Serial.print(ti01);
  Serial.println(internalTEMP,6);   
  analogWrite(9,speedy);
  logData();
  // Force data to SD and update the directory entry to avoid data loss.
  if (!file.sync() || file.getWriteError()) {
    error("write error");
  }    
  delay(100);
}

.....

// ABSIO16 I/O tester to SD card and serial console Mega2560
#include <Wire.h>
#include <SPI.h>
#include <SdFat.h>
#include <HX711.h>
HX711 scale(A0, A1);//forwards for orange board
HX711 scale2(A2, A3);//forwards for orange board
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads; /* Use this for the 16-bit version /
//Adafruit_ADS1015 ads; /
Use thi for the 12-bit version */
int16_t adc0, adc1, adc2, adc3;
float sConst[2] = {
// 912.2,//5Kg Nominal
833.5,//5Kg
408.8//10Kg Nominal
};
boolean advance;
int gopin = 7;
int internalRAW;
double internalTEMP;
float grossraw;
float gross;
float grossraw2;
float gross2;
float ti01;
int speedy;
char tbuf[10]={
' ','\0'};
// SD chip select pin. Be sure to disable any other SPI devices such as Enet.
const uint8_t chipSelect = SS;
// Interval between data records in milliseconds.
// The interval must be greater than the maximum SD write latency plus the
// time to acquire and write data to the SD to avoid overrun errors.
// Run the bench example to check the quality of your SD card.
const uint32_t SAMPLE_INTERVAL_MS = 200;
// Error messages stored in flash.
#define error(msg) sd.errorHalt(F(msg))
// Log file base name. Must be six characters or less.
#define FILE_BASE_NAME "Data"
// File system object.
SdFat sd;

// Log file.
SdFile file;

// Time in micros for next data record.
uint32_t logTime;
// User functions. Edit writeHeader() and logData() for your requirements.

const uint8_t ANALOG_COUNT = 6;
// Write data header.
void writeHeader() {
file.print(F("micros"));
for (uint8_t i = 0; i < 4; i++) {
file.print(F(",adc"));
file.print(i, DEC);
}
file.print(F(",AI4"));
file.print(F(",AI5"));
file.print(F(",AI6"));

file.print(F(",iTmp"));
file.print(F(",gross"));
file.print(F(",gross2"));
file.println();
}

// Log a data record.
void logData() {
uint16_t data[ANALOG_COUNT];
for (uint8_t i = 4; i < ANALOG_COUNT; i++) {
data = analogRead(i);

  • }*
  • // Write data to file. Start with log time in micros.*
  • file.print(logTime);*
  • file.write(',');*
  • file.print(adc0);*
  • file.write(',');*
  • file.print(adc1);*
  • file.write(',');*
  • file.print(adc2);*
  • file.write(',');*
  • file.print(adc3);*
  • // Write ADC data to CSV record.*
  • for (uint8_t i = 4; i < ANALOG_COUNT; i++) {*
  • file.write(',');*
    _ file.print(data*);_
    _
    }_
    _
    file.write(',');_
    _
    file.print(internalTEMP);_
    _
    file.write(',');_
    _
    file.print(grossraw);_
    _
    file.write(',');_
    _
    file.print(grossraw2);_
    _
    file.println();_
    _
    }_
    _
    //thermistor linearize*_
    double Thermistor(int RawADC) {
    * double Temp;*
    _ Temp = log(10000.0*((1024.0/RawADC-1)));
    Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
    * Temp = Temp - 273.15; // Convert Kelvin to Celcius*
    //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit_

    * return Temp;*
    }
    float scalar(float x, float in_min, float in_max, float out_min, float out_max)
    {
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    }
    void setup(void)
    {
    * const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
    char fileName[13] = FILE_BASE_NAME "00.csv";
    Serial.begin(9600);
    _
    pinMode(9,OUTPUT);_
    pinMode(8, INPUT_PULLUP);
    pinMode(7, INPUT_PULLUP);
    pinMode(6, INPUT_PULLUP);
    pinMode(5, INPUT_PULLUP);
    pinMode(4, INPUT_PULLUP);
    _
    delay(1000);_
    // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with*

    * // breadboards. use SPI_FULL_SPEED for better performance.
    if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    _
    sd.initErrorHalt();_
    _
    }_
    _
    // Find an unused file name._
    if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
    _
    }_
    _
    while (sd.exists(fileName)) {_
    if (fileName[BASE_NAME_SIZE + 1] != '9') {
    fileName[BASE_NAME_SIZE + 1]++;
    _
    }_
    else if (fileName[BASE_NAME_SIZE] != '9') {
    fileName[BASE_NAME_SIZE + 1] = '0';
    fileName[BASE_NAME_SIZE]++;
    _
    }_
    _
    else {_
    _
    error("Can't create file name");_
    _
    }_
    _
    }_
    if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
    _
    error("file.open");_
    _
    }_
    _
    do {_
    _
    delay(10);_
    _
    }_
    _
    while (!Serial.available());_
    _
    Serial.print(F("Logging to: "));_
    _
    Serial.println(fileName);_
    _
    Serial.println(F("Type any character to stop"));_
    _
    // Write data header._
    _
    writeHeader();_
    _
    //sample interval._
    logTime = micros()/(1000ULSAMPLE_INTERVAL_MS) + 1;

    logTime = 1000ULSAMPLE_INTERVAL_MS;
    * //zero the scale*
    * scale.set_scale();
    _
    //Average 2 values;_
    _
    // this value is obtained by calibrating the scale with known weights; see the README for details*_
    * scale.set_scale(sConst[0]);
    _
    delay (100);_
    _
    scale.tare();_
    //ITare[0]= float(scale.get_units(2))/1000.0;
    _
    delay (100);_
    grossraw= float(scale.get_units(10))/1000.0;
    _
    delay (100);_
    _
    scale.tare();_
    _
    //zero the scale2*_
    * scale2.set_scale();
    _
    //Average 2 values;_
    _
    // this value is obtained by calibrating the scale with known weights; see the README for details*_
    * scale2.set_scale(sConst[1]);
    _
    delay (100);_
    _
    scale2.tare();_
    //ITare[0]= float(scale.get_units(2))/1000.0;
    _
    delay (100);_
    grossraw2= float(scale2.get_units(10))/1000.0;
    _
    delay (100);_
    _
    scale2.tare();_
    _
    Serial.println("Hello!");_
    _
    digitalWrite(7, LOW);_
    _
    Serial.println("Getting single-ended readings from AIN0..3");_
    _
    Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");_
    ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
    _
    ads.begin();_
    _
    }_
    _
    //main*_
    void loop(void)
    {
    * adc0 = ads.readADC_SingleEnded(0);
    adc1 = ads.readADC_SingleEnded(1);
    adc2 = ads.readADC_SingleEnded(2);
    adc3 = ads.readADC_SingleEnded(3);
    _
    Serial.print("AIN0: ");_
    _
    Serial.println(adc0);_
    _
    Serial.print("AIN1: ");_
    _
    Serial.println(adc1);_
    _
    Serial.print("AIN2: ");_
    _
    Serial.println(adc2);_
    _
    Serial.print("AIN3: ");_
    _
    Serial.println(adc3);_
    _
    Serial.println(" ");_
    _
    int pin4 = digitalRead(4);_
    _
    int pin5 = digitalRead(5);_
    _
    int pin6 = digitalRead(6);_
    _
    int pin7 = digitalRead(7);_
    _
    int pin8 = digitalRead( 8 );_
    _
    //print out the value of the pushbutton*_
    * Serial.print("pin4 :");*
    * Serial.println(pin4);*
    * Serial.print("pin5 :");*
    * Serial.println(pin5);*
    * Serial.print("pin6 :");*
    * Serial.println(pin6);*
    * Serial.print("pin7 :");*
    * Serial.println(pin7);*
    * Serial.print("pin8 :");*
    * Serial.println(pin8); *
    //get the scale data
    * grossraw = float (scale.get_units())/1000.0;
    grossraw2 = float (scale2.get_units())/1000.0;
    _
    advance = digitalRead(gopin);_
    _
    internalRAW=analogRead(A7);_
    _
    internalTEMP = Thermistor(internalRAW);_
    _
    if abs(grossraw < 20.0) gross=grossraw;_
    _
    //hack a temperature reading from a transmitter*_
    * ti01 = (adc3-3200)/146.7 +10.0;*
    _ speedy = int (-grossraw1024)+200;_
    _
    if (speedy>255) speedy = 255;_
    _
    Serial.print("Grossraw: ");_
    _
    Serial.println(grossraw,6);_
    _
    Serial.print("Grossraw2: ");_
    _
    Serial.println(grossraw2,6);_
    _
    Serial.print("Internal Temp: ");_
    _
    Serial.print("TI01:)");_
    _
    Serial.print(ti01);_
    _
    Serial.println(internalTEMP,6); _
    _
    analogWrite(9,speedy);_
    _
    logData();_
    _
    // Force data to SD and update the directory entry to avoid data loss._
    _
    if (!file.sync() || file.getWriteError()) {_
    _
    error("write error");_
    _
    }_
    _
    if (Serial.available()) file.close(); _
    _
    delay(100);_
    _
    }*_

1bit
it' much much that you enclose your code in code tags as you did in the previous post.

I thank everyone for the help provided,
i still couldn't figure it out. W2RG offered to help with his own code,

meanwhile i found 2 codes that "combined" will do the best job,
ONE code is a water flow sensor (so its digital and working well) BUT missing the crutial part that writes to the SD Card :frowning:
it also supports the 16X2 LCD screen real time display (which is nice)

the SECOND code is the demo code for the adafruit that uses the SD card, but is written for ANALOG sensors,
(and does not support the LCD screen)

the best would be the modify one of the codes (add the missing parts,)

to have the digital sensor support + LCD + SD LOGGING

here are the links for the codes in case you can help :slight_smile:
also any other code will help...

Jaycar-water-flow-gauge

Adafruit CODE + Explanation

everyone suggested to hire a programmer, but since i want to use it just for personal use,
to control the water company meter (as you probably know they are asses)
so i am not sure if anyone will be willing to do that for a couple of bucks, and wont charge me hundreds of $... in which case i will give up...

Be aware that using millis() may cause a problem in a program that runs for a long time.

Millis() is an unsigned long integer type, which means that you can count up to 50 days (2^32 - 1 milliseconds) from the time the Arduino was last reset. Then millis() reverts back to zero (0) and starts all over again. This can have undesired effects if, for example, you're calculating time lapses like ( last_time - millis() ) in a loop.

This is not necessarily a problem, but you need to be aware of it in a program that may run for a long time.

ms2000:
the best would be the modify one of the codes (add the missing parts,)

to have the digital sensor support + LCD + SD LOGGING

In programming you don't use the word "code" in plural. Independent blocks of code are referred to as programs. Or "apps" if .... no, no no. :slight_smile:

That's no small bit of functionality you require your program to implement.

Do you at all understand any of the code examples you are trying to merge? Am I overly suspicious if assuming you didn't write them yourself?

W2RG thank you for that advice,
i wanted to use the RTC on the adafruit datalogger,
which is more accurate, can run for longer times and will keep time in the event of a power loss.

Rupert, i did NOT write the code myself.
i do understand some and the basics, but since i am not familiar to programming
(i am a HARDWARE and not a software guy)

so, thats why i asked forum members for help,
for me to debug hardware at this level would be 5-10 minutes work, so i assumed who ever is familiar with programming can understand the code easily and make the changes,
(specially as i attached all the materials including a detailed description of the code, as its a demo example from the shield maker.)

sadly no one was willing to help up to this point.

ms2000:
so, thats why i asked forum members for help,
for me to debug hardware at this level would be 5-10 minutes work, so i assumed who ever is familiar with programming can understand the code easily and make the changes,
(specially as i attached all the materials including a detailed description of the code, as its a demo example from the shield maker.)

You apparently don't value the software side of things very much, because your statement of 5-10 minutes of hardware work would indicate that you believe that the software work would take just as long.

Here's an approach to sampling and logging that uses only the RTC and not millis():

/*  LogDataSD.ino    26 April 2016    by RAGS

  revised 28 April 2016 to use 3.3 V instead of 5 V
  revised  1 May 2016 to incllude log on/off
  revised  3 May 2016 to clean and simplify code
  
 Reads an array of thermistors on the analog input pins.
 Calculates the temperature using the Steinhart-Hart relationship.
 Prints the results to the serial monitor.
 
 The circuit:
 * thermistor from GND to analog pin n.
 * 4700 Ohm resistor from +5V to analog pin n.
 * jumper from 3.3V to AREF
 * ON/OFF swith from Dpin 2 to GND
 */

#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

#define NSENSORS    3
#define LOGTIMESTEP  10  // seconds

const int analogInPin = A0;
const int SDSelect = 10;
const char logfile[] = "datalog.csv";

const int logswitchPin = 2;

RTC_DS1307 rtc;
DateTime  now, lastlog;

void setup() {
  Serial.begin(57600);

  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  
  if ( !SD.begin( SDSelect ) ) {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");
  
  if ( !rtc.begin() ) {
    Serial.println("Couldn't find Real Time Clock.");
    Serial.println("Can't log without it.");
    while ( 1 );
  }
  
  analogReference( EXTERNAL ); 
  lastlog = rtc.now();
  pinMode( logswitchPin, INPUT_PULLUP );     

}

void loop() {

float R = 5000.0;
float temperature[ NSENSORS ];

const float A = 0.077746e-3;    // Steinhart-Hart coefficients for Thermistor D
const float B = 4.7634e-4;
const float C = -1.0320e-6;

  now = rtc.now();
  while ( now.unixtime() - lastlog.unixtime() < LOGTIMESTEP ) {
    now = rtc.now();
  }
  lastlog = now;
  
  for ( int i = 0; i < NSENSORS; i++ ) {
    R = 4700.0 / ( (1023.0 / analogRead( i ) ) -1 );
    temperature[ i ] = 1.0 / (A + B * log( R ) + C * log( R ) * log( R ) *  log( R ) ) - 273.15;
  }

  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.print( "\t" );
  Serial.print( now.unixtime() );
  for ( int i = 0; i < NSENSORS; i++ ) {
    Serial.print( "\t" );  
    Serial.print( temperature[ i ] );
  }
  Serial.println();

  if ( !digitalRead( logswitchPin ) )  {
    Serial.println("Logging is switched OFF.");
    delay( LOGTIMESTEP / 2 );     
  }
  else {
    File dataFile = SD.open( logfile, FILE_WRITE );
    if ( dataFile ) {
      dataFile.print( now.year(), DEC );
      dataFile.print( "-" );
      dataFile.print( now.month(), DEC );
      dataFile.print( "-" );
      dataFile.print( now.day(), DEC );
      dataFile.print( "," );
      dataFile.print( now.hour(), DEC );
      dataFile.print( ":" );
      dataFile.print( now.minute(), DEC );
      dataFile.print( ":" );
      dataFile.print( now.second(), DEC );
      dataFile.print( "," );
      dataFile.print( now.unixtime() );
      for ( int i = 0; i < NSENSORS; i++ ) {
        dataFile.print( "," );
        dataFile.print( temperature[ i ] );
      }
      dataFile.println();
      dataFile.close();
      }  
    else {
      Serial.print("Error opening ");
      Serial.println( logfile );
    } 
  }
}

It's set up to read three thermistors, calculate the corresponding temperatures, and log the values to the SD card every 10 seconds along with the date and time. To count off 10 seconds, it uses the RTC's unixtime output instead of millis(). It will run as long as the batttery on the shield lasts.

The code isn't bulletproof or polished, but it works.

Since you are just using this to check the utility's meter, I don't see why you need to use clock at all. You really just need a pulse counter, which is essentially all the utility would do.

You might look at Jaycar Water Flow Gauge | Freetronics
which really has more than you need for the flow. If you want to graph the flow against time, which doesn't account for much with the utility, it is just a matter of sending the count to SD on a regular basis, and then resetting it.

dear ieee488, you are wrong by saying i dont value the software part,
its just that think the modification i need is not much work, the parallel of me debugging a hardware glitch,

but unfortionalty most members prefer to spend 5 minutes to analyze my texts and be offended instead of just offering the right help...

W2RG thank you, unfortunately my lack of knowledge in programming holds me back for adjusting this code to my needs, :frowning:

i will probably try to ask some friends for help... as someone who knows the code will have to compile it...

ms2000:
dear ieee488, you are wrong by saying i dont value the software part,
its just that think the modification i need is not much work, the parallel of me debugging a hardware glitch,

but unfortionalty most members prefer to spend 5 minutes to analyze my texts and be offended instead of just offering the right help...

You don't value the software part.

You can't do it yourself, but you think it should take only 5-10 minutes which is the time you think it should take you to debug a hardware glitch. This is laughable.

With that type of attitude, you'll be hardpressed to find someone who wants to help.

Why would anyone want to help someone who doesn't value their work? ? ?

ms2000:
dear ieee488, you are wrong by saying i dont value the software part,
its just that think the modification i need is not much work, the parallel of me debugging a hardware glitch,

but unfortionalty most members prefer to spend 5 minutes to analyze my texts and be offended instead of just offering the right help...

W2RG thank you, unfortunately my lack of knowledge in programming holds me back for adjusting this code to my needs, :frowning:

i will probably try to ask some friends for help... as someone who knows the code will have to compile it...

It's not that I don't want to help, but it seems to me you're either not at a level of knowledge about programming that you're even able to try for yourself, starting small, and asking advice along the way, or alternatively, you just want it all served to you, ready to run.

I am a software person, but when it comes to hardware, its in it's nature that I have to do it myself. If I didn't know how to read a simple electronics diagram, and in general did not know how any parts work or what they are named, not being able to even ask questions or understand any response, then however much I may want to build something, it is just not going to happen.

Your way of asking for help is like if I were to ask someone knowledgable in electronics not just to suggest a solution in text or diagram form, but to solder it together, test it, and physically send it to me.

That's what poeple are reacting to. There is no shame in not knowing, but not being capable of, or not bothering to think, experiment and learn, you're not going to get anywhere. If the current project is too complex for your skills, then start with something easier, that's the way it is for all of us.

This is a resource group, not a manufacturing team.

I have delivered (close to) working code to people on this group, but that's for stuff that I readily know how to do, or for things I wanted to research on my own. Whipping up some C++ classes and doing some I2C, as well as switches and LED's, is within my level of comprehension. I'm not a big fan of all those asking to "simply" merge two pieces of code into one. You may look at several examples and incorporate pieces into your solution, but you have to write it yourself. How else are you going to debug and modify it? Which you will!

Also, asking for code to interface "a digital flowmeter", or some "shield", is far too loosely defined.

Please don't think that I'm angry or upset. What I want you to take home from this reply, is the need to start learning what you need to learn, which means getting more familiar with the software side of microcontrollers. Microcontrollers are about hardware AND software.

You have many aha's ahead of you, with regards to software, just as I have with hardware. Heck, last August I didn't know what a pullup resistor was.

:slight_smile:

I've been mulling over a response to several of the unhelpful earlier posts, which I thought were a bit brusque. Rupert909's latest expands nicely on the ideas behind them, however.

The original poster does need to recognize the nature of Arduinos, the Arduino "community", and forums such as this one. I feel that learning is an essential part of it all. When I come here looking for a "solution", it's in the nature of "why doesn't printf() work for float-types?" Not a broad conceptual matter like, "can someone help me design a measurement system ...?"

I think it's necessary to learn at least some aspects of both hardware and software. We're talking about experimenting with microcontroller systems, after all, and it just won't do to know only the hardware or only the software part of the system.

I advise ms2000 to bite the bullet and do the necessary homework to learn some Arduino programming. It will take time, but you already have lots of support online in the many guides and examples that are out there. I think you'll find that folks will offer help on these forums, but no one will volunteer to produce customized software that suits your unique needs. You'll need to adapt.