looking at the built in examples and code I've seen online, its not too crazy at all.
Just make sure you use the right IDE, I've run into instances where they were coded using IDE 022 that would give me errors on the newer IDE builds.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
looking at the built in examples and code I've seen online, its not too crazy at all.
#include <OneWire.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
int n = 1;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
OneWire ds(10); //temp sensor on pin 10
void setup()
{
lcd.begin (20,4);
Serial.begin(9600);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.print("Temp:");
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print("Middle TN Reef Club");
lcd.setCursor ( 0, 2 ); // go to the next line
lcd.print("TheJoshDavis");
lcd.setCursor ( 0, 3 ); // go to the next line
lcd.print("myReef Controller");
lcd.setCursor ( 0, 4 ); // go to the next line
// lcd.print("Iteration No: ");
}
void loop()
{
// Backlight on/off every 3 seconds
//lcd.setCursor (14,3); // go col 14 of line 3
//lcd.print(n++,DEC);
//lcd.setBacklight(LOW); // Backlight off
//delay(3000);
//lcd.setBacklight(HIGH); // Backlight on
//delay(3000);
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
delay(250);
return;
}
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print(" Data = ");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.print(" CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// convert the data to actual temperature
unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");
//Display current temperature*****************************************************************************
lcd.setCursor ( 0, 0 ); // go to the next line
lcd.print("Current Temp:");
lcd.print(fahrenheit);
lcd.print(" F");
}
Why does programmng need so many winky faces :banghead:
Sent from my VS930 4G using Tapatalk 2
Its called "the Boolean wink". :D
There are 10 kinds of people in the world... those who understand binary, and those who don't.
Geek it till it Mhz!
Ok, I'm done... :D
Brandon
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
char buffer[20];
getDate(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.cursorTo(0,0);
sprintf(buffer, "d:d:d", hour, minute, second);
lcd.print(buffer);
lcd.cursorTo(1,0);
sprintf(buffer, "d:d:d:d", dayOfWeek, dayOfMonth, month, year);
lcd.print(buffer);
}
// Convert binary coded decimal to decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val) );
}
// Gets the date and time
void getDate(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(0x68);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(0x68, 7);
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}