Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronic Content > Electronic Projects


Electronic Projects A collection of small electronic circuits and projects you can build.

Reply
 
Tools
Old 24th July 2009, 03:02 AM   #1
Default Arduino Displaying Temperature via 74HC595's to 7-Seg's

My original project is here

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:





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 by ParkingLotLust; 24th July 2009 at 03:03 AM.
ParkingLotLust is offline  
Old 30th July 2009, 03:37 PM   #2
Default

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.

K8LH Novelty Single Chip Clock
bobledoux is offline  
Old 10th August 2009, 12:49 PM   #3
Default

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
Mike, K8LH is offline  
Old 12th August 2009, 12:31 AM   #4
Default

Quote:
Originally Posted by bobledoux View Post
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.

K8LH Novelty Single Chip Clock
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.

Quote:
Originally Posted by Mike, K8LH View Post
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
Thanks! I never did draw up a proper schematic for it, but if someone wanted one, I would have no problem doing it.
ParkingLotLust is offline  
Reply

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Any Arduino fans out there? Leftyretro AVR 48 15th November 2009 10:37 AM
Arduino Code on Non Arduino? axro Micro Controllers 1 16th July 2009 06:25 PM
Arduino for the PIC Karbos Robotics Chat 6 19th May 2009 01:51 PM
Arduino Thermostat prock Electronic Projects Design/Ideas/Reviews 2 21st April 2008 04:34 PM



All times are GMT. The time now is 08:58 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker