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) schematic, but when I uploaded sketch to Nano - only dots are turn on dots.
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.
1 Answer 1
The vendor description is not very good, however it is clear that 5 volts is not enough for these displays implying that you have to redesign the circuit to include a higher voltage power source. It does appear from the description, however, to be a common anode device. The screen shot from the data sheet shows each segment has 4 diodes in series and the DP has 2 diodes in series. That the DP lights with 5 volts indicates that the segments will light with 10 volts (possibly a bit less). Because it is common anode type you could use a TPIC6B595 shift register to replace the 74HC595. You need also 4 high side switches (each 1xPNP + 1xNPN transistor) for the 4 anodes. For this, you could also use a high side driver chip, say a MIC2981. Since the segment diode voltage drop is not shown, but should be in the range 2.1 to 4 volts, you really need to do a test to discover the optimum value of the segment current limiting resistors to give the 10mA talked about in the description, at the voltage you decide to drive the display at. The DP really requires a correspondingly higher value current limiting resistor.
-
Thank You for Your support! Does changing 74HC595 to TPIC6B595 is requiring changing code or circuit? And to be sure - on the output of D3-D6 I need to place MIC2981?Krzychotnik– Krzychotnik04/08/2023 14:30:29Commented Apr 8, 2023 at 14:30
-
The wiring to the TPIC6B595 is different to that of the 74HC595. You'd best search for a tutorial Arduino TPIC6B595. Also, the data you send is inverted because sending a "1" switches on a segment by pulling it LOW. On the 74HC595, sending a "1" would have switched the segment off by pulling it HIGH. It would be easiest to invert the table, for example "8" is currently B01111111, //8. You'd change this to B10000000, //8 . The MIC2981 is an 8 channel source driver. You'd connect Arduino pins D3 to D6 to MIC2981 pins 1 to 4. The MIC2981 outputs 18 to 15 would go to the display common anodes.6v6gt– 6v6gt04/08/2023 17:43:11Commented Apr 8, 2023 at 17:43
-
Looking at your code, it is difficult to see how all four dots could be displayed simultaneously as in your picture. Only the dot on the second digit should be displayed. However, the pinout of the display on the schematic differs from that on the vendor document. The anode is connected to pins 3 & 8 on the schematic and 1 & 5 in the vendor document. This implies also that you have wired the display incorrectly. The code change for the TPIC6B595 should be even easier than I said earlier. Simply remove the inverting tildas '~' in the two shiftOut() statements.6v6gt– 6v6gt04/09/2023 01:51:28Commented Apr 9, 2023 at 1:51
//pins to control the 4 common anode pins of display
Remember also the absolute max 40mA limit for Arduino pins especially relevant for d3 to d6 here