Hi All
Firstly thank you for clicking on this thread and I hope some one can point me in the right direction.
I am building an Aquarium monitor with the following:
UNO
one wire sensor
waterflow sensor
RTC clock module.
I can get the read outs on my 24x4 lcd however getting the reading on the nextion is getting tricky. I have a custom background with the text boxes labelled temperature, flow rate and time.
I have looked through many videos and resources and cant get the information over to the uno.
If you need any further information please ask.
Thanks
code below:
//LIBRARIES
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <DS3231.h> // CLOCK MODULE
// PINS USED - Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 7
//Raspberry Pi is connected to Serial 0
#define serialPi Serial
DS3231 rtc(SDA, SCL);
float humidity = 0.0f;
// USED VARIABLES
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup(void)
{
// start serial port
Serial.begin(9600);
// Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
lcd.begin(20, 4);
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised,
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
rtc.begin();
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop(void)
{
Serial.print ("Aquarium monitor created by Robert Ball:"); //Prints "Aquarium monitor created by Robert Ball "
Serial.print('\n'); //returns a new line*/
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature for the device 1 (index 0) is: ");
float x = sensors.getTempCByIndex(0);
Serial.print(x);
Serial.print('\n'); //returns a new line*/
Serial.print ("L/hour: "); //Prints "L/hour"
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print('\n'); //returns a new line*/
Serial.print ("PH: THIS WILL BE PHASE 3"); //Prints "PH" - code required below for getting the ph reading to the serial print screen
Serial.print('\n'); //returns a new line*/
Serial.print ("Date: "); //Prints "Date"
Serial.print (rtc.getDateStr()); //Requests the date from the clocl module
Serial.print('\n'); //returns a new line
Serial.print ("Time: "); //Prints "Time"
Serial.print (rtc.getTimeStr()); // Requests the time from the clock module
Serial.print('\n'); //returns a new line
//Send temperature and humidity data to Raspberry Pi
serialPi.print("<");
serialPi.print(x);
serialPi.print(",");
//serialPi.print(humidity);
//serialPi.println(">");
// print First line to LCD - Temp sensor
lcd.setCursor(0, 0);
lcd.print("Temp: C ");
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.setCursor(7, 0);
lcd.print(x);
// print Second line to LCD - waterflow sensor
lcd.setCursor(0, 1);
lcd.print("L/hour: ");
lcd.setCursor(7, 1);
lcd.print(" ");
lcd.setCursor(7, 1);
lcd.print(Calc, DEC);;
// print Third line to LCD - PH probe
lcd.setCursor(0, 2);
lcd.print("PH: ");
lcd.setCursor(7, 2);
lcd.print("PHASE 3");
lcd.setCursor(7, 2);
// print Forth line to LCD - Date - part 1
lcd.setCursor(0, 3);
lcd.print("DATE:");
lcd.setCursor(0, 3);
lcd.print(rtc.getDateStr());
// print Forth line to LCD - Time - part 2
lcd.setCursor(10, 3);
//lcd.print("TIME:");
// lcd.setCursor(12, 3);
lcd.print(rtc.getTimeStr());
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
}
/*
****************************************************************************************************
NOTES - CODE
****************************************************************************************************
CODE
// reading liquid flow rate using Seeeduino and Water Flow Sensor from Seeedstudio.com
// Code adapted by Charles Gantt from PC Fan RPM code written by Crenn @thebestcasescenario.com
// http:/themakersworkbench.com http://thebestcasescenario.com http://seeedstudio.com
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup() //
{
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialised,
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
Serial.print (Calc, DEC); //Prints th
*/