I am trying to run a thermometer with thermocouple sensor on Arduino Nano.
I have bought 4x 7 segment display and 74HC595 chip. Everything is connected like in the attached diagram below (without DS18B20)
, but when I uploaded sketch to Nano - only dots are turn on
.
Below You Can find my code
#include <OneWire.h>
const int latchPin = 8; // Pin connected to ST_CP of 74HC595
const int clockPin = 9; // Pin connected to SH_CP of 74HC595
const int dataPin = 10; // Pin connected to DS of 74HC595
const int digitPins[4] = {
3, 4, 5, 6}; // pins to control the 4 common anode pins of display
// seven segment digit bits + blank + minus
const byte digit[12] = {
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
B00000000, // Blank
B01000000 //-
};
int digitBuffer[4] = {1};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;
boolean sign = false;
void setup()
{
TCCR2A = 0;
TCCR2B = (1 << CS21);
TIMSK2 = (1 << TOIE2);
TCNT2 = 0;
for (int i = 0; i < 4; i++)
pinMode(digitPins[i], OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
ISR(TIMER2_OVF_vect)
{
soft_scaler++;
if (soft_scaler == 15)
{
refreshDisplay();
soft_scaler = 0;
}
};
void refreshDisplay()
{
for (byte k = 0; k < 4; k++)
digitalWrite(digitPins[k], LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(50);
digitalWrite(digitPins[digitScan], HIGH);
digitalWrite(latchPin, LOW);
if (digitScan == 1)
{
shiftOut(dataPin, clockPin, MSBFIRST,
~(digit[digitBuffer[digitScan]] | B10000000));
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
}
digitalWrite(latchPin, HIGH);
digitScan++;
if (digitScan > 3)
digitScan = 0;
}
void loop()
{
tempC = 90.8;
tmp = int(tempC * 10);
if (tempC < 0)
{
sign = true;
tmp = abs(tmp);
}
else
{
sign = false;
}
if (int(tmp) / 1000 == 0)
{
digitBuffer[3] = 10;
if (sign)
{
digitBuffer[3] = 11;
}
}
else
{
digitBuffer[3] = int(tmp) / 1000;
}
if (int(tmp) / 1000 == 0 && (int(tmp) % 1000) / 100 == 0)
{
digitBuffer[2] = 10;
if (sign)
{
digitBuffer[2] = 11;
digitBuffer[3] = 10;
}
}
else
{
digitBuffer[2] = (int(tmp) % 1000) / 100;
}
digitBuffer[1] = (int(tmp) % 100) / 10;
digitBuffer[0] = (int(tmp) % 100) % 10;
delay(500);
}
I didn't connect thermocouple yet, but I use constant "tempC" with value = 90.8, to check if it works. If I change the value to higher - dots on displays are more dimmed.
//pins to control the 4 common anode pins of displayRemember also the absolute max 40mA limit for Arduino pins especially relevant for d3 to d6 here