First Code


i trying streamline code bit... let me explain purpose first.

so have 3 fish tanks 1,2,3 wanted system log data visually , digitally takes temp each tank , displays on lcd , logs information sd card information plotted gnuplot chart. let me know think

ignore pin numbers.. understand conflict wrote code before assembly waiting parts come in.

code: [select]
//welcome michael meyer's temp logging system, here theory of operation:
//first code sets lcd display, probes, , sd sheild there then
//displays information lcd during start-up
//clears lcd prints basic information such title of program , each tank
//the program finds temp of each tank
//after finding temp prints information lcd
//then shortly after logs information pre-formated excel document stored on sd card (please note file generated during first run, information needs formated excel doc you-
//can use gnuplot information
//to @ file take out sd card , plug computer , veiw file.


//the temp measuring device must hooked gnd, pin 10 or pwm, , 5v power supply 5v resistor must placed before device

#include <liquidcrystal.h>
#include <sd.h>
#include <spi.h>
#include <wire.h>
#include "rtclib.h"
#include <onewire.h>
#include <dallastemperature.h>

#define redlite 3 //pin red
#define greenlite 5 // pin green
#define bluelite 6  //pin blue
#define temp_precision 12 //how many bits of data used measuring temp
#define log_interval 1000 //mills between entries
#define echo_to_serial 0 // echo data serial port
#define sync_interval 1000
uint32_t synctime = 0;
#define wait_to_start 0 // wait serial input in setup()

float tempf;
float tempf1;
float tempf2;

liquidcrystal lcd(7,8,9,10,11,12); //set pins ever lcd plugged board. command intializes library number of interface pins

int brightness = 255; // brightness range of 0 - 255

const int buspin = 10; //set pwm pin

onewire bus(buspin); //sets bus variable of 10
dallastemperature sensors(&bus); //sets sensor bus
deviceaddress tank1, tank2, tank3; //an array holds device address

rtc_ds1307 rtc; //defines real time clock objet

const int chipselect = 10; // sets pin sd cs line

file logfile;


void setup ()
{
  serial.begin(9600);
  serial.println();
  lcd.begin(20,4); //size of lcd display 16 being length , 2 being height
  lcd.print("welcome michael's");
  lcd.setcursor(0,1); //sets posision of going type next 1 equal second line , 0 means closest left side
  lcd.print("fish watch program"); 
  pinmode(redlite, output);
  pinmode(greenlite, output);
  pinmode(bluelite, output);
 
  brightness = 100;
 
  (int = 0; < 255; i++)
  { //this sets backlight backlite lcd display
    setbacklight(i, 0, 255-i);
  }
 
  sensors.begin(); //this command starts library senors

//tank1 = {};
//tank2 = {};
//tank3 = {};

  sensors.setresolution(tank1, temp_precision);
  sensors.setresolution(tank2, temp_precision);
  sensors.setresolution(tank3, temp_precision);
  if (!sensors.getaddress(tank1, 0)) serial.println("unable find address tank1");
  if (!sensors.getaddress(tank2, 1)) serial.println("unable find address tank2");
  if (!sensors.getaddress(tank3, 2)) serial.println("unable find address tank3");

pinmode(10, output); //this default chip select must 10

lcd.setcursor (0,3);
lcd.print("initializing sd card");
delay (100);

//see if card present , can initialized
if (!sd.begin(chipselect))
{
  lcd.setcursor (4,4);
  lcd.print("card failed");
  return;
}
//creates log file
char filename[] = "logger00.csv";
for (uint8_t = 0; < 100; i++)
{
  filename[6] = i/10 + '0';
  filename[7] = i%10 + '0';
  if (! sd.exists(filename)) {
    //only open new file if doesn't exist
    logfile = sd.open(filename, file_write);
    break;
  }
}
 
  wire.begin();
  if (!rtc.begin()) {
    logfile.println("rtc failed");
  }
 
  logfile.println("time, tank1temp, tank2temp, tank3temp"); //this sets headers

 
  delay (1000);
  lcd.clear();
  lcd.setcursor(1,0);
  lcd.print("meyer tank montior");
  lcd.setcursor(0,1);
  lcd.print("tank1:");
  lcd.setcursor(0,2);
  lcd.print("tank2:");
  lcd.setcursor(0,3);
  lcd.print("tank3:");
  lcd.noblink();
}

void loop()
{
datetime now;
//this sets dleay amount of time want between readings
delay((log_interval -1) - (millis()% log_interval));

sensors.requesttemperatures();

printtemperaturetank1;
printtemperaturetank2;
printtemperaturetank3;

uint32_t m = millis();
logfile.print(m);
logfile.print(",");

now=rtc.now();

logfile.print(now.unixtime());
logfile.print(", ");
logfile.print('"');
logfile.print(now.year(), dec);
logfile.print("/");
logfile.print(now.month(), dec);
logfile.print("/");
logfile.print(now.day(), dec);
logfile.print(" ");
logfile.print(now.hour(), dec);
logfile.print(":");
logfile.print(now.minute(), dec);
logfile.print(":");
logfile.print(now.second(), dec);

logfile.print(", ");
logfile.print(tempf);
logfile.print(", ");
logfile.print(tempf1);
logfile.print(", ");
logfile.print(tempf2);

logfile.println();

if((millis() - synctime) < sync_interval) return;
synctime = millis();

logfile.flush();

}

void printtemperaturetank1(deviceaddress tank1)//gets temp , displays on tank 1 line
{
  tempf = sensors.gettempf(tank1); //used float tempf = sensors.gettempf(tank1)
  lcd.setcursor(1,7);
  lcd.print(tempf);
}

void printtemperaturetank2(deviceaddress tank2) //gets temp , displys on tank 2 line
{
tempf1 = sensors.gettempf(tank2); //used float tempf1 = sensors.gettempf(tank2)
lcd.setcursor(2,7);
lcd.print(tempf1);
}

void printtemperaturetank3(deviceaddress tank3) //gets temp , displays on tank 3 line
{
  tempf2 = sensors.gettempf(tank3); //used float tempf2 = sensors.gettempf(tank3)
  lcd.setcursor(3,7);
  lcd.print(tempf2);
}

void setbacklight(uint8_t r, uint8_t g, uint8_t b) {
  // normalize red led - brighter rest!
  //this code program sets backlight
  r = map(r, 0, 255, 0, 100);
  g = map(g, 0, 255, 0, 150);

  r = map(r, 0, 255, 0, brightness);
  g = map(g, 0, 255, 0, brightness);
  b = map(b, 0, 255, 0, brightness);

  // common anode invert!
  r = map(r, 0, 255, 255, 0);
  g = map(g, 0, 255, 255, 0);
  b = map(b, 0, 255, 255, 0);
  serial.print("r = "); serial.print(r, dec);
  serial.print(" g = "); serial.print(g, dec);
  serial.print(" b = "); serial.println(b, dec);
  analogwrite(redlite, r);
  analogwrite(greenlite, g);
  analogwrite(bluelite, b);
}

quote
so have 3 fish tanks 1,2,3 wanted system log data visually , digitally takes temp each tank , displays on lcd , logs information sd card information plotted gnuplot chart. let me know think

i think need of these .........................

quote
i trying streamline code bit.

quote
ignore pin numbers.. understand conflict wrote code before assembly waiting parts come in.

trying optimize code before have tested on hardware premature.

code: [select]
printtemperaturetank1;
printtemperaturetank2;
printtemperaturetank3;

these statements might read:
47;
389;
123945;
they not call functions.


Arduino Forum > Using Arduino > Programming Questions > First Code


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support