2 x DMD + DS3231 + DHT22

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
dudleydo
Posts:13
Joined:Fri Dec 30, 2011 4:57 am
2 x DMD + DS3231 + DHT22

Post by dudleydo » Sun Apr 07, 2013 4:39 am

#include <Time.h>  
#include <Wire.h>
#include <DS3231.h> // a basic DS1307 library that returns time as a time_t
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //
#include <TimerOne.h>   //
#include<stdlib.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include "DHT.h"
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
DHT dht(DHTPIN, DHTTYPE);
String outstring0, outstring1, outstring2, outstring3, outstring4, outstring5, outstring6, tempstring, humidstring, datestring, timestring;
String ystring, mthstring, dstring, hstring, mstring, sstring;


DS3231 Clock;

bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;

byte date, DoW;

void ScanDMD()

  dmd.scanDisplayBySPI();
}

void setup(void)
{
   Timer1.initialize( 5000/DISPLAYS_BPP );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
   Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
   //clear/init the DMD pixels held in RAM
   dmd.clearScreen( BLACK );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
Wire.begin();

}

void loop(void)
{
ystring = String(Clock.getYear(), DEC);
mthstring = String(Clock.getMonth(Century), DEC);
dstring = String(Clock.getDate(), DEC);
hstring = String(Clock.getHour(h12, PM), DEC);
mstring = String(Clock.getSecond(), DEC);
sstring = String(Clock.getSecond(), DEC);
datestring = dstring + "-" + mthstring + "-" + dstring;
timestring = hstring + ":" + mstring + "." + sstring;

outstring1 = "Temp : ";
  float t = dht.readTemperature();
  char tbuf[6];
  dtostrf(t,5,2,tbuf);
  outstring2 = outstring1 + tbuf; 
  outstring3 = outstring2 + "C";
  char tfbuf[16];
  outstring3.toCharArray(tfbuf, 16);

  outstring4 = "Humid : ";
  float h = dht.readHumidity();
  char hbuf[6];
  dtostrf(h,5,2,hbuf);
  outstring5 = outstring4 + hbuf;
  outstring6 = outstring5 + "%";
  char hfbuf[16];
  outstring6.toCharArray(hfbuf, 16);

char datebuf[9];
datestring.toCharArray(datebuf, 9);

char timebuf[9];
timestring.toCharArray(timebuf, 9);



char* messages[] = {" Message 1 "," Message 2 "," Message 3 "," Message 4 ", tfbuf, hfbuf, datebuf, timebuf};
  for (int i = 0; i < 8; i++){

  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.println(tfbuf);
    Serial.println(hfbuf);
    Serial.print(dht.readTemperature());
    Serial.print("C ");
    Serial.print(dht.readHumidity());
    Serial.println("%");
}
  
Serial.print("T=");
Serial.println(Clock.getTemperature(), 2);
  
// stripe chaser
   byte b1;
   for( b1 = 0 ; b1 < 5 ; b1++ )
   {
      dmd.drawTestPattern( (b1&1)+PATTERN_STRIPE_0 );
      delay( 200 );
   }
   delay( 200 );

   dmd.clearScreen( BLACK );
   dmd.selectFont(Arial_Black_16);

int txt2Displen = strlen(messages);
   dmd.drawMarquee(messages,txt2Displen,(32*DISPLAYS_ACROSS)-1,0);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  }
}




Binary sketch size: 20,024 bytes (of a 32,256 byte maximum)

Been playing around getting the DMD to display what I want and here is the result.

Change the messages and number of messages as needed, just the last 4 variables are string to char conversions as needed by the DMD library.

As it is - there is no check for single digits in date or time, and extra zero added. I just had to get this code out there for people - I know I had been sweating on how to get the date done right.

OOOO Btw - the DS3231 module I am using, had been sitting in another part of the office for like 5 months. I actually had modified an Eleven to have it installed permanently. Fired it up with the DS3231 test routine that came with library - and the Time was correct, even the daylight savings was spot on.

Arduino 1.04 with existing libraries
Last edited by dudleydo on Sun Apr 07, 2013 1:46 pm, edited 1 time in total.

dudleydo
Posts:13
Joined:Fri Dec 30, 2011 4:57 am

Re: 2 x DMD + DS3231 + DHT22

Post by dudleydo » Sun Apr 07, 2013 12:43 pm

#include <Time.h>  
#include <Wire.h>
#include <DS3231.h> // a basic DS1307 library that returns time as a time_t
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //
#include <TimerOne.h>   //
#include <stdlib.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include "DHT.h"
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
DHT dht(DHTPIN, DHTTYPE);
String outstring0, outstring1, outstring2, outstring3, outstring4, outstring5, outstring6, tempstring, humidstring, datestring, timestring;
String ystring, mthstring, dstring, hstring, mstring, sstring;
int m = 0;
int s = 0;

DS3231 Clock;

bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;

byte date, DoW;

void ScanDMD()

  dmd.scanDisplayBySPI();
}

void setup(void)
{
   Timer1.initialize( 5000/DISPLAYS_BPP );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
   Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
   //clear/init the DMD pixels held in RAM
   dmd.clearScreen( BLACK );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
Wire.begin();

}

void loop(void)
{

ystring = String(Clock.getYear(), DEC);
mthstring = String(Clock.getMonth(Century), DEC);
dstring = String(Clock.getDate(), DEC);
hstring = String(Clock.getHour(h12, PM), DEC);

m = Clock.getMinute(), DEC;
if (m<10) {
  mstring = "0" + String(m);
}
else {
  mstring = String(m);
}

s = Clock.getSecond(), DEC;
if (s<10) {
  sstring = "0" + String(s);
}
else {
  sstring = String(s);
}

datestring = dstring + "-" + mthstring + "-" + ystring;
timestring = hstring + ":" + mstring + "." + sstring;
if (h12) {
if (PM) {
timestring = timestring + " PM";
else {
timestring = timestring + " AM";
}
else {
timestring = timestring + " 24h";
}

outstring1 = "Temp : ";
  float t = dht.readTemperature();
  char tbuf[6];
  dtostrf(t,5,2,tbuf);
  outstring2 = outstring1 + tbuf; 
  outstring3 = outstring2 + " C";
  char tfbuf[17];
  outstring3.toCharArray(tfbuf, 17);

  outstring4 = "Humid : ";
  float h = dht.readHumidity();
  char hbuf[6];
  dtostrf(h,5,2,hbuf);
  outstring5 = outstring4 + hbuf;
  outstring6 = outstring5 + "%";
  char hfbuf[16];
  outstring6.toCharArray(hfbuf, 16);

char datebuf[9];
datestring.toCharArray(datebuf, 9);

char timebuf[13];
timestring.toCharArray(timebuf, 13);



char* messages[] = {" HI ! "," How are you ? "," Good to hear "," Nice LED Sign eh ? ", tfbuf, hfbuf, datebuf, timebuf};
  for (int i = 0; i < 8; i++){

  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.println(tfbuf);
    Serial.println(hfbuf);
    Serial.print(dht.readTemperature());
    Serial.print("C ");
    Serial.print(dht.readHumidity());
    Serial.println("%");
}
  
Serial.print("T=");
Serial.println(Clock.getTemperature(), 2);
  
// stripe chaser
   byte b1;
   for( b1 = 0 ; b1 < 5 ; b1++ )
   {
      dmd.drawTestPattern( (b1&1)+PATTERN_STRIPE_0 );
      delay( 200 );
   }
   delay( 200 );

   dmd.clearScreen( WHITE );
   dmd.selectFont(Arial_Black_16);

int txt2Displen = strlen(messages);
   dmd.drawMarquee(messages,txt2Displen,(32*DISPLAYS_ACROSS)-1,0);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  }
}




Binary sketch size: 20,564 bytes (of a 32,256 byte maximum)

Single DMD - but easy to spot where to change it :)

Fixed an error in time encoding and added a zero for minutes and second

dudleydo
Posts:13
Joined:Fri Dec 30, 2011 4:57 am

Re: 2 x DMD + DS3231 + DHT22

Post by dudleydo » Sun Apr 07, 2013 2:09 pm

picture of the Eleven with the RTC and DHT22
Attachments
IMAG1359.jpg
pic of the DHT22 and RTC with the Eleven

Post Reply