Hi Andrew, again sorry for the delay getting back ( same as last time unfortunately ).
So have gone about things differently, and it works. Learning how C/C++ coding works is a different game to any of the programming I've done before ... V.Different. Checked all my folders and YES I did have multiple versions of the RTC files, but they were installed by either the ZIP's or EXE's, all of my ' messing ' has been done in a Top_Level Folder away from the Arduino Files.
Anyway my final code is attached, no use of RTC, comment if you want/need but it works for me.
// -----------------------------------------------------
//
// This is for the HCMODU0163 2004 I2C LCD Display
// from HOBBYCOMPONENTS
//
// REMEMBER
//
// "Wire.h", "SmartLCDI2C.h", <HCRTC.h>
//
// LIBRARIES
//
// -----------------------------------------------------
#include "Wire.h"
#include "SmartLCDI2C.h"
#include <HCRTC.h>
#define I2CDS3231Add 0x68 // DS3231 RTC ADDRESS
#define SMARTLCD_I2C_ADD 0x27 // LCD ADDRESS
// -----------------------------------------------------
// Set the TEMPERATURE Address of DS3231
// If DS1307 RTC comment next 2 lines out as no Temp
// -----------------------------------------------------
#define DS3231_TEMPS_MSB 0x11
#define DS3231_TEMPS_LSB 0x12
HCRTC HCRTC;
SmartLCD SmartLCD(SMARTLCD_I2C_ADD);
char WDAY[7][12] = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
char Beta[] = {0b11100010, '\0'};
byte WDPOS[] = { 6, 7, 7, 6, 6, 6, 7 };
byte DegC[] = {0x17,0x05,0x04,0x05,0x07,0x00,0x00,0x00};
byte CPRT[] = {0x1C,0x10,0x1F,0x04,0x1E,0x04,0x07,0x00};
byte InvC[] = {0x1F,0x11,0x15,0x17,0x15,0x11,0x1F,0x00};
byte CurrDay;
byte temp_msb;
byte temp_lsb;
byte Temp_Adj = 2; // Set this value to DS3231 +- Value ( or leave 0 )
byte Temp_cnt;
// -----------------------------------------------------
// Define any FUNCTION CALLS before we start
// -----------------------------------------------------
// Get DS3231 Temperature 'MSB' ( UNITS )
// -----------------------------------------------------
byte DS3231_get_MSB()
{
Wire.beginTransmission(I2CDS3231Add);
Wire.write(DS3231_TEMPS_MSB);
Wire.endTransmission();
Wire.requestFrom(I2CDS3231Add, 1);
temp_msb = Wire.read();
// If DS3231 Temp reads POS reduce
temp_msb = temp_msb - Temp_Adj;
// If DS3231 Temp reads NEG increase
// temp_msb = temp_msb + Temp_Adj;
}
// -----------------------------------------------------
// Get DS3231 Temperature 'LSB' ( DECIMAL )
// -----------------------------------------------------
byte DS3231_get_LSB()
{
Wire.beginTransmission(I2CDS3231Add);
Wire.write(DS3231_TEMPS_LSB);
Wire.endTransmission();
Wire.requestFrom(I2CDS3231Add, 1);
temp_lsb = Wire.read() >> 6;
}
void setup()
{
// Make sure we can TALK to the LCD
// Make sure LCD is CLEARED of ****
SmartLCD.init();
SmartLCD.Clear();
// Dim the Backlight
// 0 = OFF --- 10 = FULL
SmartLCD.Backlight(2);
// Adjust the Contrast
// 0 = FULL --- 255 NONE
SmartLCD.Contrast(75);
// Make sure Cursor NOT Blinking
// 0 or OFF --- 1 or ON
SmartLCD.CursorBlink(OFF);
// Create the CUSTOM Characters
// Pnt DegC InvC and store them
SmartLCD.DefCustChar(0, DegC);
SmartLCD.DefCustChar(6, CPRT);
SmartLCD.DefCustChar(7, InvC);
// Print STATIC TEXT to Display. Do not want
// to keep printing what never changes.
// Remember this is for a 4 line LCD so
// ROWS are numbered 0 to 3 & Char Position
// Char Position is 0 to 19 i.e. 4R x 20C
SmartLCD.CurPos(0,1);
SmartLCD.Print( "DS" );
SmartLCD.CurPos(0,16);
SmartLCD.Print( "3231" );
SmartLCD.CurPos(3,0);
SmartLCD.Print( Beta );
SmartLCD.Print( "A00");
SmartLCD.CurPos(3,18);
SmartLCD.PrintCustChar(6);
SmartLCD.PrintCustChar(7);
}
void loop()
{
// Now lets print Day,Date,Time,Temp
Temp_cnt = 250;
while (1)
{
Temp_cnt ++;
// Read the current DATE from the RTC module
// Output to the SmartLCD
HCRTC.RTCRead(I2CDS3231Add);
HCRTC.RTCRead(I2CDS3231Add);
// Work out what day/date it is
// Only print if it changes
if ( CurrDay != HCRTC.GetWeekday() )
{
// Clear previous WDAY display
SmartLCD.CurPos(0,6);
SmartLCD.Print(" ");
// Print new WDAY display
SmartLCD.CurPos(0,WDPOS[HCRTC.GetWeekday()-1]);
SmartLCD.Print(WDAY[HCRTC.GetWeekday()-1]);
// Print date as DD/MM/YY
SmartLCD.CurPos(1,6);
SmartLCD.Print( HCRTC.GetDatestring());
CurrDay = HCRTC.GetWeekday();
}
// Read the current TIME from the RTC module
// Print TIME as HH:MM:SS
SmartLCD.CurPos(2,6);
HCRTC.RTCRead(I2CDS3231Add);
SmartLCD.Print(HCRTC.GetTimestring());
// Every 15secs check for Temperature change
if ( Temp_cnt >= 250 )
{
// Get DS3231 Temperature readings
temp_msb = DS3231_get_MSB();
temp_lsb = DS3231_get_LSB();
SmartLCD.CurPos(3,7);
SmartLCD.Print(temp_msb);
switch(temp_lsb)
{
case 0:
SmartLCD.Print(".00");
break;
case 1 :
SmartLCD.Print(".25");
break;
case 2:
SmartLCD.Print(".50");
break;
case 3:
SmartLCD.Print(".75");
break;
}
SmartLCD.PrintCustChar(0);
Temp_cnt = 0;
}
}
// Wait 1/10 of a second before reading again
// Using 1/10th Sec as At somepoint will include
// Humidity on 2004 LCD
delay(100);
}
SmartLCD and RTC
Forum for posting topics and questions about anything.
Return to “General Discussion”
Jump to
- Terms & Conditions / Privacy Policy
- ↳ Terms & Conditions
- ↳ Privacy Policy
- General Discussion
- ↳ General Discussion
- ↳ HobbyComponents.com shop
- ↳ Ebay shop
- Hobby Components Branded Products
- ↳ Arduino
- ↳ Development boards
- ↳ Kits
- ↳ 4x4x4 Version 2 Cube Kits
- ↳ Shields
- ↳ mLink
- ↳ SmartRFy
- ↳ Expressive (ESP8266)
- ↳ Prototyping
- ↳ Test Equipment
- ↳ Kits
- ↳ 4x4x4 Version 2 Cube Kits
- ↳ Modules
- ↳ EDTracker
- Development Boards, Programmers & Accessories From Other Manufacturers
- ↳ Arduino
- ↳ Kits
- ↳ Arduino Projects Handbook Kits
- ↳ Arduino Development Boards
- ↳ Arduino Shields
- ↳ Cases
- ↳ ESP32
- ↳ ESP8266
- ↳ Raspberry Pi
- ↳ Atmel
- ↳ Microchip
- ↳ ST Microelectronics
- ↳ Altera
- ↳ Cypress
- ↳ Arm
- ↳ TinyCircuits
- ↳ WeMos
- ↳ Pine64
- ↳ Microduino
- Modules
- ↳ Wireless / Wired
- ↳ Sensors
- ↳ Display
- ↳ Motor drivers
- ↳ Relay
- ↳ Power
- ↳ Adaptor
- ↳ RTC
- ↳ Audio
- ↳ Interface
- ↳ Measurement / Signal Generation
- Home Automation
- ↳ Sonoff
- 3D Printing / CNC
- ↳ 3D Printing / CNC
- Robotics / Mechanical
- ↳ Kits & Parts
- ↳ Motors & Servos
- Radio Control
- ↳ Radio Control
- Security/RFID
- ↳ Security/RFID
- Arcade
- ↳ Arcade
- Other
- ↳ Electronics Kits / Bundles
- ↳ Components
- ↳ ICs
- ↳ Hardware
- ↳ Project / Soldering
- ↳ Test
- ↳ Cables
- ↳ Other
- Software
- ↳ Arduino
- ↳ Microchip PIC
- ↳ Great Cow Basic
- Community Projects