Monday, September 1, 2014

Bubble Display, Shift Register and a TMP36 (Showing temperature on a tiny led display)

A few days ago a friend of mine lend me an SparkFun ProMicro. It's a 5v, 16mhz Arduino compatible development board that fits on a breadboard.

After i soldered its legs i had to run something cool on it, so i thought it would be fun to hook up an (also small) hp 7 segment bubble led display, but it's easy to connect it directly to the atmega pins, so i got it connected with 7 instead of 12 cables thanks to an 74HC595 Shift Register, just to add a little more complexity fun on this.

So, what is a shift register? it's a kind of buffer chip on which you load the state of the n-bits (8 in the case of the 74hc595), and then you say: "ok, show me what i wrote there", and the D0-to-D7 pins on the chip get HIGH or LOW, depending on which bitmask you stored earlier.

That's perfect for the 7 segments plus dot of the LED display, with 3 pins you decide the state of the 8 segments of the display.

But this Bubble display got 4 characters, so i still need 4 pins to control the 4 common cathodes of the display, and choose where to display each character. This could be controlled with another 595, but each one use 3 pins, and there was just 4 cathodes, so there wasn't much advantage on using another chip.

Here a pic of this super tiny led display:

I got the code from luiSantos instructables tutorial, with some modifications, some of them pointed out in the comments below that tutorial, where a guy posted a modified version that works with common cathode displays, like this little bubble display.

I got the bitmasks for the characters from SparkFun's SevSeg Library. on the ".h" file you can find the definitions for the character's segments on the display.

They are written as 0bABCDEFGX, where x is the decimal dot, which the display has for every character block, and A-to-G are the segments of the display on this form:

f        b
f        b
f        b
e       c
e       c
e       c
  ddd   X

The display needs to be continuously updated because only one character is displayed each time. I found 7msec to be a good refresh rate for this display, lower than this makes the display blurry (with 6msec got the decimal dot jumping between the sides or appearing twice), with 8msec it gets flickery and is hard to read on it.

The parts:

4x    330 ohm Resistor
1x    74HC595 Shift register
1x    HP QDSP-6064 Bubble 7 segments LED display
1x    TMP36 Analog devices Temperature sensor
1x    SparkFun's ProMicro Arduino compatible Board
1x    Breadboard (or 2 half-sized ones)
Alot  Jumper cables

This is the assembling of what i did with the parts:

There are a lot of cables, but just a few more than when i tried the display alone with the arduino, and now got me only 7 arduino pins instead of 12, so you can for example keep rx and tx serial pins (0,1) and some PWM capable pins on the Arduino UNO free for other tasks better than show your room's current temperature.

The Code looks like this:

* created by Rui Santos,
* modified by: Raphango
* Still more changes by: rccursach 2014
* Temperature Sensor Displayed on 4 Digit 7 segment common CATHODE
* 2013
* A Small portion from SparkFun's SevSeg Libray
* SparkFun, Nathan Seidle, 2012 (Beerware license). Based on Dean Reading, 2012.

const int digitPins[4] = {4,5,6,7}; //4 common CATHODE pins of the display.
const int clockPin = 10;    //74HC595 Pin 11
const int latchPin = 16;    //74HC595 Pin 12
const int dataPin = 14;     //74HC595 Pin 14
const int tempPin = A0;     //tmp36 temperature sensor pin

//As seen on SparkFun's SevSeg Library
const byte digit[10] =      //seven segment digits
  0b11111100, // 0
  0b01100000, // 1
  0b11011010, // 2
  0b11110010, // 3
  0b01100110, // 4
  0b10110110, // 5
  0b10111110, // 6
  0b11100000, // 7
  0b11111110, // 8
  0b11110110  // 9

int digitBuffer[4] = {0};
int digitScan = 0;
float tempC;

void setup(){               
  for(int i=0;i<4;i++)
  pinMode(tempPin, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 

void loop(){
  float temp_v = (float)(analogRead(tempPin) * (5.0 / 1023.0));
  tempC = (100 * temp_v) - 50;

  printDisp(tempC, 1000); //params are: Float value, msec it will be displayed

void printDisp(float value, int msec){
  digitBuffer[3] = (int(value) % 1000)/10;
  digitBuffer[2] = (int(value) % 10);
  digitBuffer[1] = (int(value*10) % 10);
  digitBuffer[0] = (int(value*100) % 10);
  //Get it displayed until msec Milliseconds passed
  long ti = millis();
  long tf = millis();
  while(tf-ti < msec){
    tf = millis();

//writes the temperature on display
void updateDisp(){
  for(int i=0; i<4; i++){
    digitalWrite(digitPins[i], LOW); //Changed to LOW for turning the leds on.
    if(i==2) //Add decimal dot
      shiftOut(dataPin, clockPin, LSBFIRST, digit[digitBuffer[i]] | 0b00000001);
      shiftOut(dataPin, clockPin, LSBFIRST, digit[digitBuffer[i]]);
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
    delay(7); //If not delayed, digits are seen brurry, if the value is 8 you migth see the display frickering.

void clearDisp(){
  for(byte j=0; j<4; j++) {digitalWrite(digitPins[j], HIGH);} // Turns the display off. Changed to HIGH

Because this code is just demostrative, now i want to make a library for this little displays to be managed with the shift register, maybe auto-refreshed with a timer. If i got some time i will write it and put the link on this post as an update.

Now this is how it looks like:

After i put on my protoboard a 5v Step-up converter and 2 AA Batteries and got it running all night just because this little red numbers look pretty cool in the dark.

And that's it!

No comments :

Post a Comment