Temp Display

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
ledsarecool
Posts: 18
Joined: Tue Aug 04, 2015 5:45 pm

Temp Display

Post by ledsarecool » Sat Aug 08, 2015 7:23 am

hello.

Can anyone help me out with displaying temp ect with a decimal.
The is the code I use for pretty much all decimal reading where needed but I cant get the hundreds to display I get zero.
This is normally part of a - void printNumberC(float num) - code but I have changed and used in a loop.

Code: Select all


   float t = dht.readTemperature();
    
   float   num = t;
   int ones;
   int tens;
   int hundreds;
   int v=(float)num;
   int diff=num-v;
   diff=diff*100;
   int fones,ftens;
   fones=(byte)diff%10;
   diff=diff/10;
   ftens=(byte)diff%10;
   diff=diff/10;
   ones=v%10;
   v=v/10;
   tens=v%10;
   v=v/10;
   hundreds=v;  
  dmd.selectFont(Arial_Black_16);
  dmd.drawChar( 0,  0, '0' + tens, GRAPHICS_NORMAL );
  dmd.drawChar( 9,  0, '0' + ones, GRAPHICS_NORMAL );  
  dmd.drawChar( 17,  0, '.', GRAPHICS_NORMAL );
  dmd.drawChar( 22,  0, '0' + hundreds, GRAPHICS_NORMAL );




angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Temp Display

Post by angusgr » Mon Aug 10, 2015 6:41 am

Hi,

There are a few different approaches to this, but here's one that should work (I haven't tested this on a DMD but it should be OK):

Code: Select all

float t = dht.readTemperature();
char str_buf[16];
snprintf(str_buf, 16, "%d.%d", (int)t, (int)(t*100)-(int)t*100);
dmd.drawString(0, 0, str_buf. GRAPHICS_NORMAL);
If you want a different number of decimal places, replace the two '100's in the snprintf line with 10, 1000, etc.

Angus

ledsarecool
Posts: 18
Joined: Tue Aug 04, 2015 5:45 pm

Re: Temp Display

Post by ledsarecool » Mon Aug 10, 2015 1:01 pm

Hi Angus.

I have tried your code and would not compile.

I made changes to your code (dmd.drawString) and (dht.readTemperature) and it now compiles and works great!

Thank you very much! :mrgreen:

Code: Select all


int x,y;
float t = dht.readTemperature()+0.6; // Temp Fine tune.
char str_buf[16];
snprintf(str_buf, 16, "%d.%d", (int)t, (int)(t*100)-(int)t*100);

dmd.drawString( 1+(32*x), 2+(16*y), str_buf,4, GRAPHICS_NORMAL);    


angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Temp Display

Post by angusgr » Mon Aug 10, 2015 10:52 pm

Great news, sorry for the typos in the original reply! Thanks for posting the working version.

Angus

francisco2v
Posts: 19
Joined: Fri Aug 21, 2015 8:25 am

Re: Temp Display

Post by francisco2v » Fri Aug 21, 2015 8:35 am

Dear friends:
It would be possible to publish the full code for those who are learning.
"excuse my English"
Thank you

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Temp Display

Post by angusgr » Mon Aug 24, 2015 7:00 am

Hi Francisco,

This was just the code to display a number on the DMD, so it's hard to create aw full sample without some context about what you'd like to display.

Can you give any details, or maybe post what you've got so far?


Angus

francisco2v
Posts: 19
Joined: Fri Aug 21, 2015 8:25 am

Re: Temp Display

Post by francisco2v » Fri Aug 28, 2015 11:24 am

I thought she had made full ..... I'm beginning ... so I need information. Thank you.
I would like to make a simple thermometer DS18B20 with big font.
But first do with DMD.

ledsarecool
Posts: 18
Joined: Tue Aug 04, 2015 5:45 pm

Re: Temp Display

Post by ledsarecool » Tue Sep 01, 2015 5:25 am

Hello.

DS18d20 scrolling/static code from my Arduino UNO, should be simple enough to understand, Im a noob also.
Just remove/comment the static display if not wanted and change your pin numbers if needed. ;)
I have removed some code of my own and compiled so should work fine.

Code: Select all


#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 <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
#include <OneWire.h>
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
// http://www.pjrc.com/teensy/td_libs_OneWire.html
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire  ds(3);  // on pin 10 (a 4.7K resistor is necessary maybe 500ohm i used for s/steel probe not sure sorry)

#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
 int x;
 int y;
void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}
void setup(void)
{
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   Timer1.initialize(1800);           //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( true );   //true is normal (all pixels off), false is negative (all pixels on)
   Serial.begin(9600); 
}
void loop(void){
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;
  
  ds.search(addr);
 
    delay(250);

  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  } 

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end
  
  delay(750);     // maybe 750ms is enough for correct start up temp, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  
  celsius = raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  celsius = celsius +1; //fine tune temp here if out
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  dmd.clearScreen(true);
  int x,y;
  float t = celsius; // Temp Fine tune.
  char str_buf[20];
  snprintf(str_buf, 20, "Temperature %d.%d" "*C", (int)t, (int)(t*100)-(int)t*100);  // string with degree C

   dmd.selectFont(Arial_Black_16);
   dmd.drawMarquee(str_buf,20,(32*DISPLAYS_ACROSS)-1,1);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){ 
   if ((timer+35) < millis()) {
   ret=dmd.stepMarquee(-1,0);
   timer=millis();
   }  
   } 
  delay(1500);   
  dmd.selectFont(System5x7);
  dmd.drawChar( 1,  0, 'T', GRAPHICS_NORMAL);   
  dmd.drawChar( 8,  0, 'E', GRAPHICS_NORMAL);   
  dmd.drawChar( 16,  0, 'M', GRAPHICS_NORMAL);   
  dmd.drawChar( 24,  0, 'P', GRAPHICS_NORMAL);   
  
  char str2_buf[20];
  snprintf(str2_buf, 20, "%d.%d" , (int)t, (int)(t*100)-(int)t*100);  // string with degree C
  dmd.drawString( 0+(32*x), 8+(16*y), str2_buf,6, GRAPHICS_NORMAL);    
  //              ^text position^temp  string^ ^ number of char to print 
  delay(5000);
  
  }
 

francisco2v
Posts: 19
Joined: Fri Aug 21, 2015 8:25 am

Re: Temp Display

Post by francisco2v » Sun Sep 06, 2015 10:46 am

Thank you very much ... now I have to study it to understand its functionality.

ledsarecool
Posts: 18
Joined: Tue Aug 04, 2015 5:45 pm

Re: Temp Display

Post by ledsarecool » Tue Sep 15, 2015 11:07 am

Trying to clear up a problem with this display print out with decimals.

When the temperature is 21.00 or 21.10 or 21.20 ect.
It will only show the first digit after the decimal point.
How can i print 1 decimal place also?

Post Reply