DMD + DHT + Eleven

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
DMD + DHT + Eleven

Post by dudleydo » Sun Apr 22, 2012 3:04 pm

I have finally gotten it to work :geek:

See what you all think of this code - cobbled together over many hair pulling sessions, no hacking of libraries needed.
#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 "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 1
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN, DISPLAYS_BPP);
DHT dht(DHTPIN, DHTTYPE);
String outstring0, outstring1, outstring2, outstring3, outstring4, outstring5, outstring6, outstring7;

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();
}

void loop(void)
{
  outstring1 = "Temp : ";
  int t = dht.readTemperature();
  outstring2 = outstring1 + t;
  outstring3 = outstring2 + "C ";
  outstring4 = "Humidity : ";
  int h = dht.readHumidity();
  outstring5 = outstring4 + h;
  outstring6 = outstring5 + "%";
  outstring7 = outstring3 + outstring6;
char buf[46];
outstring7.toCharArray(buf, 46);

char* messages[] = {buf," Whatever messages You Want "," They can be any length, with any characters "," I do suggest putting a space at the front and back "};
  for (int i = 0; i < 4; i++){

  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.println(buf);
    Serial.print(dht.readTemperature());
    Serial.print("C ");
    Serial.print(dht.readHumidity());
    Serial.println("%");
}
  
    
// 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,WHITE,BLACK);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+15) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  }
}



Binary sketch size: 16380 bytes (of a 32256 byte maximum)

Arduino IDE 1.0

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

Re: DMD + DHT + Eleven - with floating point in the display

Post by dudleydo » Sun Apr 22, 2012 3:39 pm

#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 1
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN, DISPLAYS_BPP);
DHT dht(DHTPIN, DHTTYPE);
String outstring0, outstring1, outstring2, outstring3, outstring4, outstring5, outstring6, outstring7;

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();
}

void loop(void)
{
  outstring1 = "Temp : ";
  float t = dht.readTemperature();
  char tbuf[6];
  dtostrf(t,5,2,tbuf);
  outstring2 = outstring1 + tbuf; 
  outstring3 = outstring2 + "C ";
  outstring4 = "Humidity : ";
  float h = dht.readHumidity();
  char hbuf[6];
  dtostrf(h,5,2,hbuf);
  outstring5 = outstring4 + hbuf;
  outstring6 = outstring5 + "%";
  outstring7 = outstring3 + outstring6;
char buf[46];
outstring7.toCharArray(buf, 46);

char* messages[] = {" TLCIT Hawkesbury "," 0409 741 579 "," mobile@tlcit.com.au "," http://www.tlcit.com.au ",buf};
  for (int i = 0; i < 5; i++){

  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.println(buf);
    Serial.print(dht.readTemperature());
    Serial.print("C ");
    Serial.print(dht.readHumidity());
    Serial.println("%");
}
  
    
// 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,WHITE,BLACK);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+20) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  }
}




Binary sketch size: 17550 bytes (of a 32256 byte maximum)
Arduino 1.0 IDE

Going to be for a display in my back windows when my brake light is on - or a party sign this weekend :geek:

Buzbot
Posts:22
Joined:Wed Dec 14, 2011 10:03 am

Re: DMD + DHT + Eleven

Post by Buzbot » Sat Apr 28, 2012 7:08 am

Hi,

Great effort on getting this to work. Unfortunately I could not get the code to compile. I suspect I am using an old library for either the DHT or the DMD.

Could upload the library files you are using. It would be most appreciated.

Many Thanks

Buzbot

Post Reply