element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum 4 Digit 7 Segment Thermometer Help
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 10 replies
  • Subscribers 394 subscribers
  • Views 1261 views
  • Users 0 members are here
Related

4 Digit 7 Segment Thermometer Help

Former Member
Former Member over 10 years ago

Hi Guys,

 

So I decided I was going to start learning how to use 7 Segment Displays and shift registers. I am using a 74HC595 to control the anodes of a 4 digit 7 segment display. And 2N3904s for the Cathodes. and a Dallas DS18B20 temperature sensor.

 

However, I am having extreme flicker/timing issues with the display. here is the code I am using. Instead of the display normally updating it cycles through each Digit with a about one second delay before displaying the next digit. So it displays one digit at a time. I have read that DallasTemp library causes delays. But the display shouldn't have large delays in between numbers? So I am slightly confused. Can anyone help me out?

 

Thanks,

Austin

 

/*
* created by Rui Santos, http://randomnerdtutorials.com
* Temperature Sensor Displayed on 4 Digit 7 segment common anode
* 2013
*
* Modified by Austin Pauley for use with DS18B20
* 2015
*/


#include <OneWire.h>
#include <DallasTemperature.h>


#define ONE_WIRE_BUS A0
OneWire ds(ONE_WIRE_BUS);
DallasTemperature sensors(&ds);
DeviceAddress insideThermometer;


const int digitPins[4] = {
  5,4,3,2};                 //4 common anode pins of the display
const int clockPin = 11;    //74HC595 Pin 11 
const int latchPin = 12;    //74HC595 Pin 12
const int dataPin = 13;     //74HC595 Pin 14
const byte digit[10] =      //seven segment digits in bits
{
  B11000000, //0
  B11111001, //4
  B10100100, //2
  B10110000, //3
  B10011001, //4
  B10010010, //5
  B10000010, //6
  B11111000, //7
  B10000000, //8
  B10010000  //9
};
int digitBuffer[4] = {
  0,0,0,0};
int digitScan = 0, flag = 0, soft_scaler = 0;
;
float  tempC, tempF;


void setup(){
  for (int i = 0; i<4; i++)
  {
  pinMode(digitPins[i], OUTPUT);
  }
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  sensors.begin();
  sensors.getAddress(insideThermometer, 0);
  Serial.begin(9600);
  sensors.setResolution(9);

}




void updateDisp(){
  for (byte j = 0; j < 4; j++)
  digitalWrite(digitPins[j], LOW);
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
  digitalWrite(latchPin, HIGH);


  delayMicroseconds(100);
  digitalWrite(digitPins[digitScan], HIGH);


  digitalWrite(latchPin, LOW);


  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);


  digitalWrite(latchPin, HIGH);
  digitScan++;
  if (digitScan>3) digitScan = 0;



}


float getTemp()
{
sensors.requestTemperatures();
tempF = sensors.getTempF(insideThermometer);
}
void loop(){
  int temp = (int)getTemp();


  digitBuffer[3] = int(temp) / 1000;
  digitBuffer[2] = (int(temp) % 1000) / 100;
  digitBuffer[1] = (int(temp) % 100) / 10;
  digitBuffer[0] = (int(temp) % 100) % 10;
  updateDisp();

}

  • Sign in to reply
  • Cancel

Top Replies

  • sftwrngnr
    sftwrngnr over 10 years ago +1
    First off, I would only update the display if the temperature has actually changed, otherwise, you're reloading and cycling the shift register constantly. You could simply retain the previous displayed…
  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago in reply to Former Member +1
    Thats a good start but the call to requestTemperatures is a blocking call and it does several things including reseting the one wire bus, initiating a start conversion on all connected devices and then…
  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago in reply to sftwrngnr +1
    one wire in itself is not blocking, you can initiate the conversion, go away to do something else (Like update a 7Segment display) and come back later to see if the conversion is ready to be read. the…
Parents
  • sftwrngnr
    0 sftwrngnr over 10 years ago

    Props to Peter. I didn't realize the one wire call was blocking.  Since it is one wire, you can't really wait asynch for an interrupt. Its been a while since I've done anything with one wire, so you may want to have a look at the protocol and see if there's anything you can do to speed things up a bit.  As Peter says, "baby steps." Work on incremental improvements and see what does and doesn't work.

     

    Best of luck.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to sftwrngnr

    one wire in itself is not blocking, you can initiate the conversion, go away to do something else (Like update a 7Segment display) and come back later to see if the conversion is ready to be read. the dallas / ti chip fully supports this. the blocking is just the default behaviour of the library to make the basic use easy for beginners

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago in reply to sftwrngnr

    one wire in itself is not blocking, you can initiate the conversion, go away to do something else (Like update a 7Segment display) and come back later to see if the conversion is ready to be read. the dallas / ti chip fully supports this. the blocking is just the default behaviour of the library to make the basic use easy for beginners

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube