8x10 LED Matrix with TMP36 and DS1307 Question

Hi, this is my first time writing in a forum. I am making an 8x10 LED Matix with a shift register from http://www.instructables.com/id/810-LED-Matrix-with-4017/. When finished I would love to have it show the temp with my TMP36 and possibly the time with my DS1307 Time IC. But I am so confused about how i would code that. I have used the TMP36 on a LCD but not a LED Matrix. Can anyone help me with the coding for that or show me where I can learn how to get data from the IC's and show it on my matrix? I have tried my best looking online for answers but have came up short. This would be a great help. Thank you.

Normally when I see instructables my heart sinks but this one looks reasonably
First read:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Then you will need to work out the bit pattern for all the digits you want to display and store them in an array you call a character generator array.

Then the code needs to get the temperature value and transfer the appropriate bit pattern into the display refresh memory.

To do this you need to read up on how to use arrays. You transfer the bits in the character generator array into the display refresh array depending on what digits the temperature is telling you.

I'll look into it. Thanks for the help. :slight_smile:

Ok, so I'm working off the code the Instructables guy gave and i'm trying my best to figure it out. I think I understand most of it. But i don't understand how I can take a value from the temp sensor and assign it a pattern array. I have a video of me testing it LED 8x10 Matrix Scrolling Test - YouTube So now I want to add a shift register and figure out how to make it scroll lengthwise and have it on it's side. i know I'll have to change the "font." After reading your website, i hope I made it correctly. Do you know of a site that clearly explains how a sensor value like temp or time can be assigned to the right bit pattern to represent it's number? Or an example code to learn from? Thank you

Don't get hung up on the fact that the data comes from a sensor, it is just the same as if it came from a string. Convert the number into a string ( look up the c command to do this) then feed the string to the display just like you are feeding the words you are displaying.

Hey again,
I hope you don't feel you are repeating yourself. I guess I know less about this than I thought, but I would really like to learn. I read up on strings but it's not quite clicking with me. I just don't understand how to make the Matrix read and scroll the temp from the tmp36. Can you maybe give more clear instruction? I have scoured the internet looking for an example with no luck.

Here's the code i'm working from.

int DataPin = 9;
int LatchPin = 11;
int ClockPin = 10;
int clock = 13;
int Reset = 12;
//x,y for the loop
int x;
int y;
// here the definion of all the letter(big ans small) and numbers  (I took out the letters to save space in the forum.)

#define space {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define num_0 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000}
#define num_1 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000}
#define num_2 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000}
#define num_3 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000}
#define num_4 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000}
#define num_5 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000}
#define num_6 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_7 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000}
#define num_8 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000}
#define num_9 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000}
#define times {B00000000,B00000000,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B00000000,B00000000}

const int numPatterns = 17;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space,M,A,D,E,space,B,Y,space,V,A,D,I,M,space};// the patterns order
void setup(){
  pinMode(DataPin,OUTPUT);
  pinMode(ClockPin,OUTPUT);
  pinMode(LatchPin,OUTPUT);
  //simple stuff here
 pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  //reseting the 4017 IC, you have to do this
 digitalWrite(Reset,HIGH);
  delayMicroseconds(5);
  digitalWrite(Reset,LOW);
}

void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it
{ 
  for(x=0;x<numPatterns-1;x++){ // loop over the patterns
   for (int z=0;z<8;z++){ //scrolls one bite at a time 
    for(int t=0;t<loops;t++){// the delay we get with loops
     for(y=0;y<10;y++){// loops over the array of bytes
     byte temp = patterns[x][y]; 
     byte temp_2=patterns[x+1][y];
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,((temp<<z)+(temp_2>>7-z)));//writes digital outputs, Z is for how much bites it need to scroll
          digitalWrite(LatchPin, 1);
      delayMicroseconds(800);
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
      digitalWrite(LatchPin, 1);
     digitalWrite(clock,HIGH);
     digitalWrite(clock,LOW);
   }
  }
 }
}
}

void loop(){
 display_pattern(15);// calls for the display_pattern function and says that int loop = 15(if you do more loop the pattern whould scrrol slower).
}

The example code from the TMP36 i have used in the past is found at Temperature sensor tutorial - Using the TMP36 / LM35

I really appreciate any help making this more clear so i can move on with my project.

OK, I'm still stuck. I added a shift register and it works great. Now I really want it to scroll the temperature from a TMP36. I have tried for some time now and I need help with the code. And can someone tell me how to tweak the code to make it scroll lengthwise? Thanks

I added a shift register and it works great.

...

can someone tell me how to tweak the code to make it scroll lengthwise?

The shift register "works great". Your video shows it scrolling. What is the question exactly?

Nick,
OP doesn't know how to implement GrumpyMike's idea in reply #4 to have the sketch bring in outside data to replace the fixed pattern in the sketch now:

const int numPatterns = 17;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space,M,A,D,E,space,B,Y,space,V,A,D,I,M,space};// the patterns order

Er, right. Well I would turn the defines into a variable array, makes it a bit easier to work with:

#define space {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}

const byte digits [10] [10] = {
 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000}, // 0
 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000}, // 1
 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000}, // 2
 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000}, // 3
 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000}, // 4
 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000}, // 5
 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000}, // 6
 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000}, // 7
 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000}, // 8
 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000}, // 9
};

Let's assume the temperature won't go over 3 digits:

const int numPatterns = 4;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space};// the patterns order

Then loop can look like this (completely untested but it compiles OK):

void loop(){
  
 int temp = 25;  // or whatever from the temperature sensor
 
 char buf [4];  // holds 3 digits plus terminator
 
 sprintf (buf, "%03i", temp);  // turn temperature into a string
 
 // copy the bit patterns for each digit (digit 0, 1, 2)

 for (byte i = 0; i < 3; i++)
   memcpy (&patterns [i], &digits [buf [i] - '0'], 10); 
   
 display_pattern(15);
}

That's the rough idea.

Thanks so much for your time. I'll try it out.
~Matt

Thanks Nick, that worked great. But now I have 2 questions:

  1. i have a 8x10 matrix and the words scroll across the rows (8 wide). I want to have the matrix on its side (10x8) How do I change the code to make the words (temp) scroll across the long ways (10 wide)?

  2. With this code I have just the temperature scrolling. How can I add "degree symbol" and "F" after the temp?
    Thanks

int DataPin = 9;
int LatchPin = 11;
int ClockPin = 10;
int clock = 13;
int Reset = 12;
//x,y for the loop
int x;
int y;
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures

#define space {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}

byte digits [10] [10] = {
 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000},
 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000},
 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000},
 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000},
 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000},
 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000},
 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000},
 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000},
 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000},
 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000},
};

const int numPatterns = 3;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space};// the patterns order

void setup(){
  pinMode(DataPin,OUTPUT);
  pinMode(ClockPin,OUTPUT);
  pinMode(LatchPin,OUTPUT);
  //simple stuff here
 pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  //reseting the 4017 IC, you have to do this
 digitalWrite(Reset,HIGH);
  delayMicroseconds(5);
  digitalWrite(Reset,LOW);
}

void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it
{ 
  for(x=0;x<numPatterns-1;x++){ // loop over the patterns
   for (int z=0;z<8;z++){ //scrolls one bite at a time 
    for(int t=0;t<loops;t++){// the delay we get with loops
     for(y=0;y<10;y++){// loops over the array of bytes
     byte temp = patterns[x][y]; 
     byte temp_2=patterns[x+1][y];
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,((temp<<z)+(temp_2>>7-z)));//writes digital outputs, Z is for how much bites it need to scroll
          digitalWrite(LatchPin, 1);
      delayMicroseconds(800);
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
      digitalWrite(LatchPin, 1);
     digitalWrite(clock,HIGH);
     digitalWrite(clock,LOW);
   }
  }
 }
}
}

void loop(){
  
  
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
 
 // now convert to Fahrenheight
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 
 delay(1000);                                     //waiting a second
  
 int temp = temperatureF;  // or whatever from the temperature sensor
 
 char buf [3];  // holds 3 digits plus terminator
 
 sprintf (buf, "%02i", temp);  // turn temperature into a string
 
 // copy the bit patterns for each digit (digit 0, 1, 2)

 for (byte i = 0; i < 2; i++)
   memcpy (&patterns [i], &digits [buf [i] - '0'], 10); 
   
 display_pattern(15);
}

How can I add "degree symbol" and "F" after the temp?

Define them exactly like you did the numbers.

Can you post your schematic? Need to see the hardware that connects across the 10-bit wide portion vs the 8-bit wide portion.

Here is the schematic I used:

Thanks

Grumpy_Mike:

How can I add "degree symbol" and "F" after the temp?

Define them exactly like you did the numbers.

I tried that, but i must have done it wrong. This is what i tried:

int DataPin = 9;
int LatchPin = 11;
int ClockPin = 10;
int clock = 13;
int Reset = 12;
//x,y for the loop
int x;
int y;
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures

#define space   {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define degree {B00000000,B00001110,B00001010,B00001110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000}
#define F          {B00000000,B01111110,B01000000,B01000000,B01111100,B01000000,B01000000,B01000000,B01000000,B00000000}

byte digits [10] [10] = {
 {B00000000,B00111100,B01000110,B01001010,B01001010,B01001010,B01010010,B01100010,B00111100,B00000000},
 {B00000000,B00001000,B00011000,B00001000,B00001000,B00001000,B00001000,B00001000,B00011100,B00000000},
 {B00000000,B00111100,B01000010,B00000100,B00001000,B00010000,B00100000,B01000000,B01111110,B00000000},
 {B00000000,B01111110,B00000010,B00000010,B00011100,B00000010,B00000010,B01000010,B00111100,B00000000},
 {B00000000,B00000100,B00001100,B00010100,B00100100,B01000100,B01111110,B00000100,B00000100,B00000000},
 {B00000000,B01111110,B01000000,B01000000,B00111100,B00000010,B00000010,B00000010,B01111100,B00000000},
 {B00000000,B00111100,B01000000,B01000000,B01111100,B01000010,B01000010,B01000010,B00111100,B00000000},
 {B00000000,B01111110,B00000010,B00000100,B00001000,B00010000,B00010000,B00010000,B00010000,B00000000},
 {B00000000,B00111100,B01000010,B01000010,B00111100,B01000010,B01000010,B01000010,B00111100,B00000000},
 {B00000000,B00111100,B01000010,B01000010,B01000010,B00111110,B00000010,B00000010,B00111100,B00000000},
};

const int numPatterns = 5;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={space,degree,F};// the patterns order

void setup(){
  pinMode(DataPin,OUTPUT);
  pinMode(ClockPin,OUTPUT);
  pinMode(LatchPin,OUTPUT);
  //simple stuff here
 pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  //reseting the 4017 IC, you have to do this
 digitalWrite(Reset,HIGH);
  delayMicroseconds(5);
  digitalWrite(Reset,LOW);
}

void display_pattern(int loops)//int loop acts like a delay, it take 8 mSecands to scan all of the rows so int loops = 15 is a good time for it
{ 
  for(x=0;x<numPatterns-1;x++){ // loop over the patterns
   for (int z=0;z<8;z++){ //scrolls one bite at a time 
    for(int t=0;t<loops;t++){// the delay we get with loops
     for(y=0;y<10;y++){// loops over the array of bytes
     byte temp = patterns[x][y]; 
     byte temp_2=patterns[x+1][y];
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,((temp<<z)+(temp_2>>7-z)));//writes digital outputs, Z is for how much bites it need to scroll
          digitalWrite(LatchPin, 1);
      delayMicroseconds(800);
      digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
      digitalWrite(LatchPin, 1);
     digitalWrite(clock,HIGH);
     digitalWrite(clock,LOW);
   }
  }
 }
}
}

void loop(){
  
  
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
 
 // now convert to Fahrenheight
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 
 delay(1000);                                     //waiting a second
  
 int temp = temperatureF;  // or whatever from the temperature sensor
 
 char buf [3];  // holds 3 digits plus terminator
 
 sprintf (buf, "%02i", temp);  // turn temperature into a string
 
 // copy the bit patterns for each digit (digit 0, 1, 2)

 for (byte i = 0; i < 2; i++)
   memcpy (&patterns [i], &digits [buf [i] - '0'], 10); 
   
 display_pattern(15);
}
byte patterns[numPatterns][10]={space,degree,F};// the patterns order

I see you have changed it to 2 digits (let's hope it doesn't get over 99 F eh?).

You need to allow for the two digits, eg.

byte patterns[numPatterns][10]={space, space, degree, F};// the patterns order

Here is the schematic I used:

Thats an incredibly large image file (2.25Mb). It took about 5 minutes to download for me. Haven't Instructables heard of PNG files? That was a BMP file which isn't compressed at all.

I tried that, but i must have done it wrong. This is what i tried:

So what did it look like?

Ok, and you want to move the bytes down the page now, vs across the page.
You need to flip your loop around so that happens, and rotate the pattern with it.

Try this:
make z go up 10
make y go up to 8
swap x & y in these two

byte temp = patterns [ x ] [ y ];
byte temp_2=patterns [ x+1 ] [ y ];

What you to end up with is writing a byte (which you need as the vertical column of a letter now vs the horizontal row)
to the shift register, make it show with a low bit from the 4017, turn it off, put out the next column and make it show with the next bit low from the 4017, ...

Has anyone worked with a DS1307 RTC before? I would also like to scroll the time with the temp and add some buttons to fix the time so a computer is not needed. How can I add a clock code to the code i have? Can this easily be done?

[quote author=Nick Gammon link=topic=73657.msg563419#msg563419 date=1318107219]

byte patterns[numPatterns][10]={space,degree,F};// the patterns order

I see you have changed it to 2 digits (let's hope it doesn't get over 99 F eh?).

You need to allow for the two digits, eg.

byte patterns[numPatterns][10]={space, space, degree, F};// the patterns order[/quote]

sorry that image was so big. Your idea worked though, I didn't allow for the 2 digits. I did change the temp to 2 digits because the display always had a "0" before the 2 digit temp. I can now display the "degrees F." So, I'm understanding better now. Thanks guys