0

I am new to Arduino and I'm trying my first Pro Mini. I was able to find DS1302 code from github that runs perfectly. My problem is trying to add some LM35 code to also display temperature data as well as the time data.

The code doesn't seem to run the Celsius and Fahrenheit functions. I have attached my code. Any help will be appreciated.

//Required library - http://www.rinkydinkelectronics.com/library.php?id=5
//Blog Post - http://overskill.alexshu.com/ds1302-real-time-clock-w-arduino/

#include "U8glib.h"
#include <DS1302.h>
#include <PreciseLM35.h>
//int float pinLM35 = A0;
const int pinLM35 = A0;
PreciseLM35 lm35(pinLM35, DEFAULT);

DS1302 rtc(2, 3, 4);
U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE); 

void setup(void) {
  rtc.halt(false);
  rtc.writeProtect(false);

  // The following lines can be commented out to use the values already stored in the DS1302
  // Once you flash the Arduino with the correct time.

  //rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
  //rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010

  // assign default color value
  if (u8g.getMode() == U8G_MODE_R3G3B2)
    u8g.setColorIndex(255); // white
  else if (u8g.getMode() == U8G_MODE_GRAY2BIT)
    u8g.setColorIndex(3); // max intensity
  else if (u8g.getMode() == U8G_MODE_BW)
    u8g.setColorIndex(1); // pixel on
}

void draw(void) {
  u8g.setFont(u8g_font_04b_03);
  u8g.drawStr( 2,5, "******************************");
  u8g.drawStr( 13,10, "Arduino Pro Mini Control ");
  u8g.drawStr( 24,20, (rtc.getTimeStr()));
  u8g.drawStr( 1,20, "TIME: ");
  u8g.drawStr(70,20,  "Temp (C): ");
  u8g.drawStr (80,20, (lm35.readCelsius()));
  u8g.drawStr( 25,30, rtc.getDOWStr());
  u8g.drawStr(70,30, "Temp (F): ");
  u8g.drawStr(3,30, "DAY: ");
  u8g.drawStr(80,30, (lm35.readFahrenheit()));
  u8g.drawStr( 24,40, rtc.getDateStr());
  u8g.drawStr(1,40, "DATE: ");
  u8g.drawStr(70,40, "AREF : ");
  u8g.drawStr(80,40, (lm35.readPreciseAref()));
  u8g.drawStr( 15,55, "DS1302 Real Time Clock");
  u8g.drawStr( 2,65, "********************************");
}

void loop(void) {
  // picture loop
  u8g.firstPage();
  do {
    draw();
  } while(u8g.nextPage()); //u8g.nextPage()
  // rebuild the picture after some delay
  delay(500);
}
  • 2
    Have you tried sending the output of the functions to the serial monitor and seeing if its a problem with the display library or the functions? – Code Gorilla Oct 23 '17 at 7:18
  • I used this code: u8g.setPrintPos(110,20); – Michael Bennett Oct 23 '17 at 16:57
1

Use an DS3231 RTC instead. It include a temperature sensor with digital output. No need to read an analog value and it means less component in your PCB.

  • I used this code: u8g.setPrintPos(110,20); and then u8g.Print(temps.TempInCelcuis);and its working great. Thanks for the helpful suggestions. – Michael Bennett Oct 23 '17 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.