Arduino Displaying Temperature via 74HC595's to 7-Seg's

Status
Not open for further replies.
My original project is **broken link removed**

Code:
#include <DallasTemperature.h>

int bottomDataPin = 5; 
int bottomLatchPin = 6;
int bottomClockPin = 7;
int topLatchPin = 3;
int topClockPin = 4;
int topDataPin = 2;
int j = 1;
int toShift_Top = 0;
int toShift_Bottom = 0;
char m[4];
byte data;
byte dataArray[10];

DallasTemperature tempSensor0;
DallasTemperature tempSensor1;

void setup() {
  pinMode(topLatchPin, OUTPUT);
  pinMode(bottomLatchPin, OUTPUT);
  Serial.begin(9600);
  tempSensor0.begin(11);
  tempSensor1.begin(12);

  dataArray[0] = 0x3F; // 0
  dataArray[1] = 0x06; // 1
  dataArray[2] = 0x5B; // 2
  dataArray[3] = 0x4F; // 3
  dataArray[4] = 0x66; // 4
  dataArray[5] = 0x6D; // 5
  dataArray[6] = 0x7C; // 6
  dataArray[7] = 0x07; // 7
  dataArray[8] = 0x7F; // 8
  dataArray[9] = 0x67; // 9

  // clear both displays with 0's
  // top
  digitalWrite(topLatchPin, 0);
  shiftOut(topDataPin, topClockPin, dataArray[0]);
  shiftOut(topDataPin, topClockPin, dataArray[0]);
  shiftOut(topDataPin, topClockPin, dataArray[0]);
  shiftOut(topDataPin, topClockPin, dataArray[0]);
  digitalWrite(topLatchPin, 1);
  //bottom
  digitalWrite(bottomLatchPin, 0);
  shiftOut(bottomDataPin, bottomClockPin, dataArray[0]);
  shiftOut(bottomDataPin, bottomClockPin, dataArray[0]);
  shiftOut(bottomDataPin, bottomClockPin, dataArray[0]);
  shiftOut(bottomDataPin, bottomClockPin, dataArray[0]);
  digitalWrite(bottomLatchPin, 1);
}

void loop() 
{
  int k = 1000;
  toShift_Top = (tempSensor0.getTemperature() * 100);

  // the following code is by EmilyJane of arduino.cc forums
  int temp = toShift_Top;
  for (int i = 3; i >= 0; i--)
  {
    m[i] = temp / k;
    temp = temp - (m[i] * k);
    k = k / 10;
  }
  // end
  digitalWrite(topLatchPin, 0);
  shiftOut(topDataPin, topClockPin, dataArray[m[0]]);   
  shiftOut(topDataPin, topClockPin, dataArray[m[1]]);   
  shiftOut(topDataPin, topClockPin, dataArray[m[2]]);   
  shiftOut(topDataPin, topClockPin, dataArray[m[3]]); 
  digitalWrite(topLatchPin, 1);
  
  k = 1000;
  toShift_Bottom = (tempSensor1.getTemperature() * 100);
  // again, the following code is by EmilyJane of arduino.cc forums
  temp = toShift_Bottom;
  for (int i = 3; i >= 0; i--) 
  {
    m[i] = temp / k;
    temp = temp - (m[i] * k);
    k = k / 10;
  }
  // end
  digitalWrite(bottomLatchPin, 0);
  shiftOut(bottomDataPin, bottomClockPin, dataArray[m[0]]);   
  shiftOut(bottomDataPin, bottomClockPin, dataArray[m[1]]);   
  shiftOut(bottomDataPin, bottomClockPin, dataArray[m[2]]);   
  shiftOut(bottomDataPin, bottomClockPin, dataArray[m[3]]); 
  digitalWrite(bottomLatchPin, 1);
}

// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) 
{
  // This shifts 8 bits out MSB first, 
  //on the rising edge of the clock,
  //clock idles low

  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  //for each bit in the byte myDataOut?
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights. 
  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    //if the value passed to myDataOut and a bitmask result 
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000 
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {	
      pinState= 0;
    }

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin  
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }

  //stop shifting
  digitalWrite(myClockPin, 0);

}

Basically, I bought an Arduino from Creatron here in Toronto and decided to learn to code and play around, as they looked like a good way to get into uC's. I wanted to display the temperature from some free DS18S20 sensors I got onto some 7-seg's. However, I quickly realized it was going to kill me in the sheer amount of pins it would need.

After learning about shift registers a week or two in class I figured it would be the perfect test. And after lots of soldering and playing around, I designed this:

**broken link removed**
**broken link removed**
**broken link removed**

And it works great! Best of all, it worked on the first attempt. If you have any questions, comments, suggestions, etc, please feel free to leave them!
 
Last edited:
ParkingLotLust,

It's pretty obvious when you read through that original thread that you had a wonderful and exciting adventure getting this project up and running.

Bravo on great project. Did you ever draw up a proper schematic?

Regards, Mike
 
Nice,

Now look at the concept of multiplexing to see if you can eliminate the 74HC595's. You'll need 7 pins for the 7 segments, plus one pin for each display.

https://www.electro-tech-online.com/threads/k8lh-novelty-single-chip-clock.41255/
Ive looked into multiplexing and if I had to do it again, thatd be the way to go. The only reason I didnt multiplex from the start was because I was/am still new to coding, and I didnt want to add another level of complexity.

Thanks! I never did draw up a proper schematic for it, but if someone wanted one, I would have no problem doing it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…