0

Building a Graphing Indoor Climate Clock, I hope.
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Building a Graphing Indoor Climate Clock, I hope.

by Disciple on Tue Aug 15, 2017 2:25 am

Okay, I downloaded and installed a fresh copy of RTClib-master.zip, launched 1.8.3 on Windows7, and...

Code: Select all | TOGGLE FULL SIZE
// DHTtester_NokiaLCD_02 - Example testing sketch for DHT22 humidity/temperature sensor
// Adding Nokia 5110 LCD screen display & PCF8523 clock support.
// Written using code by Ladyada, adafruit.com, public domain

#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"

#define DHTPIN 12    // what digital pin we're connected to
#define LEDPIN 13

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

Adafruit_PCD8544 display = Adafruit_PCD8544(8, 6, 5, 4, 3);

RTC_PCF8523 rtc;


void setup() {
  // Serial.begin(9600);
  dht.begin();
  rtc.begin();

  rtc.initialized();
  // following line sets the RTC to the date & time this sketch was compiled,
  // (but only once, not at every restart)
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  write_i2c_register(0x68, 0x0E, 0xE6);  // Please don't fail me

  pinMode(LEDPIN, OUTPUT);

  display.begin();
  display.setContrast(40);
  display.display();  // show Adafruit splashscreen
}

void loop() {
  digitalWrite(LEDPIN, LOW);  // LED off
  // Wait a few seconds between measurements.
  delay(2000);
  digitalWrite(LEDPIN, HIGH);  // LED on

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();  // Read temperature as Celsius (the default)
  float f = dht.readTemperature(true);  // Read temperature as Fahrenheit (isFahrenheit = true)

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    // Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

/*
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
*/
  DateTime now = rtc.now();
   
  // text display tests
  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);
  display.print(f);
//  display.println("°"); // Degrees F
  display.println("F"); // Degrees F
  display.println(" ");
  display.print(h);
  display.println("%"); // Humidity
  display.println(" ");

  if(now.hour() < 10)
    display.print(" ");  // Time display, leading 0's & spaces
  display.print(now.hour());
  display.print(":");
  if(now.minute() < 10)
    display.print("0");
  display.print(now.minute());
  display.print(":");
  if(now.second() < 10)
    display.print("0");
  display.println(now.second());
  display.display();
}
...but the result was the same as before, ’write_i2c_register’ was not declared in this scope

So, here I still am.

Hallelujah!
Disciple

Disciple
 
Posts: 544
Joined: Tue Jan 06, 2015 8:13 pm

Re: Building a Graphing Indoor Climate Clock, I hope.

by adafruit_support_bill on Tue Aug 15, 2017 7:42 am

Sigh.... The Arduino IDE tries to be helpful by doing some pre-processing that automates some of the tedious details of C++ programming. That's nice as long as you stick to plain vanilla programming. But it can create problems some when you stray from that straight & narrow path. Things that you can do in normal C++ don't always work the same in the Arduino environment.

Try pasting in this function definition just before your setup() function:

Code: Select all | TOGGLE FULL SIZE
static void write_i2c_register(uint8_t addr, uint8_t reg, uint8_t val) {
  Wire.beginTransmission(addr);
  Wire.write((byte)reg);
  Wire.write((byte)val);
  Wire.endTransmission();
}

adafruit_support_bill
 
Posts: 67351
Joined: Sat Feb 07, 2009 10:11 am

Re: Building a Graphing Indoor Climate Clock, I hope.

by Disciple on Tue Aug 15, 2017 12:15 pm

*gasp* I have strayed from the straight and narrow!

Your workaround succeeded. It compiles and the project can resume. Now time will tell if my math is correct...literally.
Is there a page where these IDE pitfalls are uncovered? All I can find on google are discussions about coding errors.

Hallelujah!
Disciple

Disciple
 
Posts: 544
Joined: Tue Jan 06, 2015 8:13 pm

Re: Building a Graphing Indoor Climate Clock, I hope.

by adafruit_support_bill on Tue Aug 15, 2017 12:37 pm

I don't know of any comprehensive summary of IDE anomalies and aberrations. What I do know has was mostly taught to me by the school of hard knocks.

Normally in C++ you need to define prototypes for all your functions in an .h file. That is somewhat tedious and repetitive, so the IDE does it for you. That is nice when it works and it generally works well if you have a single program file and use the normal library functions. That probably accounts for 99% of all Arduino projects. Where it starts to get funny is when you have multiple program files, or start using library functions that haven't been explicitly exported by the library. In those cases sometimes you need to second guess the pre-processor and do a bit of extra work to get it to recognize things.

adafruit_support_bill
 
Posts: 67351
Joined: Sat Feb 07, 2009 10:11 am

Re: Building a Graphing Indoor Climate Clock, I hope.

by Disciple on Sat May 19, 2018 8:47 pm

Hello. Many months later and I'm resuming the clock project. I have three questions, easiest first.
  1. My father wants a bigger display, and went for the Graphic ST7565 Positive LCD for the size and color. He's not interested in graphing functions so I think Pro Trinket memory will suffice. I'm still planning to make my 5110-style clock graph-capable, but my question is this. Do the LEDs in the ST7565 need resistors, or are they built in? My guess is resistors will be necessary.
  2. The Adafruit PCF8523 Real Time Clock in my original circuit started losing its time on battery, so I replaced the CR1220, but that didn't help. Both batteries still have energy but the clock can't keep time when unplugged. Are there points on the circuit board I can test with my cheap voltmeter to see if the battery voltage appears in all the places it ought to? (My clocks will have buttons to set the time, but it's a problem I'd still like to fix.)
The third question I'll ask elsewhere. It's off topic.

Hallelujah!
Disciple

Disciple
 
Posts: 544
Joined: Tue Jan 06, 2015 8:13 pm

Re: Building a Graphing Indoor Climate Clock, I hope.

by adafruit_support_bill on Sun May 20, 2018 6:22 am

You will need a current limiting resistor for the LED backlights. About 100 ohms if you are powering from 3.3v. 270 ohms for 5v operation.

How much drift are you seeing on the RTC module? The PCF8523 is not temperature compensated, but is typically good to within a few seconds per day. These need only nano-amps from the battery to keep time, Generally when the battery goes, it stops completely.

adafruit_support_bill
 
Posts: 67351
Joined: Sat Feb 07, 2009 10:11 am

Re: Building a Graphing Indoor Climate Clock, I hope.

by Disciple on Thu May 24, 2018 8:57 pm

Ah. Thanks for the resistor confirmation.

The clock wasn't drifting. It was randomizing. It was, and now it's not. The clock seems to have fixed itself, keeping good time now. Maybe a bit of grit fouled the battery contacts, I dunno, but it's back to the coding bench for me. I'll share pics and sketches here as they develop. Thanks again.

Hallelujah!
Disciple

Disciple
 
Posts: 544
Joined: Tue Jan 06, 2015 8:13 pm

Please be positive and constructive with your questions and comments.