Seven segment LED for cathode

With a common cathode, you should be getting something:-) Can you check you have assigned the arduino pins as OUTPUTs, that you have resistors between the arduino pins and the display (say 330r to test).
Set the outputs (in code) to HIGH, then check the arduino output voltages with a multi-meter. Should be over 4.5v for most MCUs.
BTW if you disconnect your display, you can get each segment to glow with the multimeter (in diode-check mode). Then you can verify you have your display connection pins correct.

That looks like the MSb 1 is the decimal point… that’s all you’re lighting up.
0000000 isn’t ‘zero’, it’s all the digit segments turned off.

int DS_pin = 7; // Data pin of 74hc595 connected to the 11th pin of Arduino Uno(7 for TPIC6C596)
int STCP_pin = 6; // Latch pin of 74hc595 connected to the 12th pin of Arduino Uno(6 for TPIC6C596)
int SHCP_pin = 5; // Clock pin of 74hc595 connected to the 8th pin of Arduino Uno(5 for TPIC6C596)
int gpin = 4; // G pin of 74hc595 connected to the 4th pin of Arduino Uno(4 for TPIC6C596)
//int samplse = 0; // the first sensor value
float sensorvalue = 4.9;
/* values that are assigned to the name of the macros */
//#define x1 0.564662421366142
//#define x2 1.22135167695223

/* 7 segment common anode values ranging from 0 to 9 */
int dec_digits [11] = {
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111, //9
};

/* setup initializes serial and the pin settings */
void setup()
{
Serial.begin(9600); // 9600 Baud Rate
Serial.println(" Metal Width Detector\n ");
//set pins to output
pinMode(DS_pin, OUTPUT); // Setting Data Pin as an OUTPUT
pinMode(STCP_pin, OUTPUT); // Setting Latch Pin as an OUTPUT
pinMode(SHCP_pin, OUTPUT); // Setting Clock Pin as an OUTPUT
pinMode(gpin, OUTPUT); // Setting gPin as an OUTPUT
digitalWrite(SHCP_pin, LOW); // Write Pin as LOW
digitalWrite(DS_pin, LOW); // Write Pin as LOW
digitalWrite(STCP_pin, LOW); // Write Pin as LOW
digitalWrite(gpin, LOW); // Write Pin as LOW
}

/* loop checks the sensor state and will send serial after calibration /
void loop()
{
// read the first sensor
//int samplse = analogRead(6);
/
map(value, fromLow, fromHigh, toLow, toHigh)
map - maps a number from one range to another.
value - the number to map.
fromLow - the lower bound of the value’s current range.
fromHigh - the upper bound of the value’s current range.
toLow - the lower bound of the value’s target range.
toHigh - the upper bound of the value’s target range.
*/
//float sensorvalue = 1.23;
updateDisplay();
}

void updateDisplay()
{
/* To print the values in the serial monitor, if necessary /
Serial.println(sensorvalue, 2);
char buf[10]; // A variable that contains char values
/
dtostrf - This function converts the float values to the char.
dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);
floatvar - float variable
StringLengthIncDecimalPoint - This is the length of the string that will be created
numVarsAfterDecimal - The number of digits after the decimal point to print
charbuf - the array to store the results
*/
dtostrf(sensorvalue, 4, 2, buf);
Serial.println(buf[0]);
Serial.println(buf[1]);
Serial.println(buf[2]);
Serial.println(buf[3]);
// Writing LOW on the STCP pin allows us to send data to the IC

/* for loop execution /
for (int i = 0; i <= 3; i++)
{
if (buf[i] != ‘.’)
{
if (buf[i + 1] == ‘.’)
{
/
shiftOut(dataPin, clockPin, bitOrder, value)
shiftOut - Shifts out a byte of data one bit at a time.
dataPin - the pin on which to output each bit. Allowed data types: int.
clockPin - the pin to toggle once the dataPin has been set to the correct value. Allowed data types: int.
bitOrder - which order to shift out the bits; either MSBFIRST or LSBFIRST.
value - the data to shift out. Allowed data types: byte.
converting the resultant char value to a decimal value.
adding the decimal point wherever we want in the seven segment display
*/
digitalWrite(STCP_pin, LOW);
shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] & 0x0f)] | 0x80);
delay(1000);
digitalWrite(STCP_pin, HIGH);
}
else
{
digitalWrite(STCP_pin, LOW);
shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] & 0x0f)]);
delay(1000);
digitalWrite(STCP_pin, HIGH);
}
}
}
// Writing HIGH on the STCP pin, no longer needs to listen for information

// waits for a second
delay(1000);
}

This is my code… i cannot display a value with dot.

I am using 1 only to light a segment. My question is I need to display 1., 2., 3., for that i used 0b00111111 | 0b1000000. For this i need 0. instead of that I am getting only .(dot).
The issue would be with hardware or the software?

I have checked with all the pins. My concern is when I add decimal point to any digit, the segment gives priority to the decimal point only. The digit is not displaying with the decimal point. Is this the issue with the hardware or the software?

Hi, @manoj_maniyan
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.

To add code please click this link;

Before you post your code, in the IDE press CTRL T to auto format your code.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Here I am using the arduino code. I want to display my numbers with dot.
but unfortunately I am not getting this.
am using Seven segment cathode display. I need to display 1., 2., 3., 4., etc. When i do coding like B00111111 | B10000000, this should display as 0. (zero+dot)
But I am not getting this result. I am getting only ‘.’ (dot)
Help me?

int DS_pin = 7; // Data pin of 74hc595 connected to the 11th pin of Arduino Uno(7 for TPIC6C596)
int STCP_pin = 6; // Latch pin of 74hc595 connected to the 12th pin of Arduino Uno(6 for TPIC6C596)
int SHCP_pin = 5; // Clock pin of 74hc595 connected to the 8th pin of Arduino Uno(5 for TPIC6C596)
int gpin = 4; // G pin of 74hc595 connected to the 4th pin of Arduino Uno(4 for TPIC6C596)
//int samplse = 0; // the first sensor value
float sensorvalue = 4.9;
/* values that are assigned to the name of the macros */
//#define x1 0.564662421366142
//#define x2 1.22135167695223

/* 7 segment common anode values ranging from 0 to 9 */
int dec_digits [11] = {
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111, //9
};

/* setup initializes serial and the pin settings */
void setup()
{
Serial.begin(9600); // 9600 Baud Rate
Serial.println(" Metal Width Detector\n ");
//set pins to output
pinMode(DS_pin, OUTPUT); // Setting Data Pin as an OUTPUT
pinMode(STCP_pin, OUTPUT); // Setting Latch Pin as an OUTPUT
pinMode(SHCP_pin, OUTPUT); // Setting Clock Pin as an OUTPUT
pinMode(gpin, OUTPUT); // Setting gPin as an OUTPUT
digitalWrite(SHCP_pin, LOW); // Write Pin as LOW
digitalWrite(DS_pin, LOW); // Write Pin as LOW
digitalWrite(STCP_pin, LOW); // Write Pin as LOW
digitalWrite(gpin, LOW); // Write Pin as LOW
}

/* loop checks the sensor state and will send serial after calibration /
void loop()
{
// read the first sensor
//int samplse = analogRead(6);
/
map(value, fromLow, fromHigh, toLow, toHigh)
map - maps a number from one range to another.
value - the number to map.
fromLow - the lower bound of the value’s current range.
fromHigh - the upper bound of the value’s current range.
toLow - the lower bound of the value’s target range.
toHigh - the upper bound of the value’s target range.
*/
//float sensorvalue = 1.23;
updateDisplay();
}

void updateDisplay()
{
/* To print the values in the serial monitor, if necessary /
Serial.println(sensorvalue, 2);
char buf[10]; // A variable that contains char values
/
dtostrf - This function converts the float values to the char.
dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);
floatvar - float variable
StringLengthIncDecimalPoint - This is the length of the string that will be created
numVarsAfterDecimal - The number of digits after the decimal point to print
charbuf - the array to store the results
*/
dtostrf(sensorvalue, 4, 2, buf);
Serial.println(buf[0]);
Serial.println(buf[1]);
Serial.println(buf[2]);
Serial.println(buf[3]);
// Writing LOW on the STCP pin allows us to send data to the IC

/* for loop execution /
for (int i = 0; i <= 3; i++)
{
if (buf[i] != ‘.’)
{
if (buf[i + 1] == ‘.’)
{
/
shiftOut(dataPin, clockPin, bitOrder, value)
shiftOut - Shifts out a byte of data one bit at a time.
dataPin - the pin on which to output each bit. Allowed data types: int.
clockPin - the pin to toggle once the dataPin has been set to the correct value. Allowed data types: int.
bitOrder - which order to shift out the bits; either MSBFIRST or LSBFIRST.
value - the data to shift out. Allowed data types: byte.
converting the resultant char value to a decimal value.
adding the decimal point wherever we want in the seven segment display
*/
digitalWrite(STCP_pin, LOW);
shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] & 0x0f)] | 0x80);
delay(1000);
digitalWrite(STCP_pin, HIGH);
}
else
{
digitalWrite(STCP_pin, LOW);
shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] & 0x0f)]);
delay(1000);
digitalWrite(STCP_pin, HIGH);
}
}
}
// Writing HIGH on the STCP pin, no longer needs to listen for information

// waits for a second
delay(1000);
}

Your duplicate topics have been merged into this one

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

But I am not getting the clear solution still. I have tried all the possibilities to get the output.
Can someone please help me?

If you are not getting answers to a topic then the wrong thing to do is start a second topic on the same subject.

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code

okay


digitalWrite(STCP_pin, LOW);
{
shiftOut(DS_pin, SHCP_pin, MSBFIRST,   dec_digits[(buf[i] & 0x0f)] | 0x80) // dp ‘on’
} else {
shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] & 0x0f)]); // no dp
}
digitalWrite(STCP_pin, HIGH);

Obviously, you’re setting up the data with the high bit (dp) set when needed…
I didn’t look at all your code, because it’s not posted properly…

Yes sir. But that is not working. If I set dp over there, I am getting only dp and not the other digits. Instead of dec_digits[(buf[i] & 0x0f)] | 0x80), If I use dec_digits[(buf[i] & 0x0f)] | 0x01) this working fine.
I don’t know why dp is getting prioritization when I add to another digit.

Well, I’m guessing your dec_digits isn’t holding what you expected…

You could try putting a Serial.print in there temporarily, to see what’s coming in. Everything will slow down, but you can watch the data values as they’re processed.

Like I said, and I don’t think I’m alone… you should reformat your code in tags so people will read it.

Another way if you can’t spot the issue soon, is to minimalise your code to just a loop() that calls the display function - getting rid of all the fluff for now.

Then you’ll know what’s being generated, and what’s being displayed- finding the difference will be a lot easier.

I am posting the code again.
//int DS_pin = 7; // Data pin of 74hc595 connected to the 11th pin of Arduino Uno(7 for TPIC6C596)
//int STCP_pin = 6; // Latch pin of 74hc595 connected to the 12th pin of Arduino Uno(6 for TPIC6C596)
//int SHCP_pin = 5; // Clock pin of 74hc595 connected to the 8th pin of Arduino Uno(5 for TPIC6C596)
//int gpin = 4; // G pin of 74hc595 connected to the 4th pin of Arduino Uno(4 for TPIC6C596)
////int srclr = 8;
////int samplse = 0; // the first sensor value
//float sensorvalue = 1.49;
///* values that are assigned to the name of the macros /
////#define x1 0.564662421366142
////#define x2 1.22135167695223
//
///
7 segment common anode values ranging from 0 to 9 /
//int dec_digits [11] = {
// B00111111, //0
// B00000110, //1
// B01011011, //2
// B01001111, //3
// B01100110, //4
// B01101101, //5
// B01111101, //6
// B00000111, //7
// B01111111, //8
// B01101111, //9
//};
//
///
setup initializes serial and the pin settings /
//void setup()
//{
// Serial.begin(9600); // 9600 Baud Rate
// Serial.println(" Metal Width Detector\n ");
// //set pins to output
// pinMode(DS_pin, OUTPUT); // Setting Data Pin as an OUTPUT
// pinMode(STCP_pin, OUTPUT); // Setting Latch Pin as an OUTPUT
// pinMode(SHCP_pin, OUTPUT); // Setting Clock Pin as an OUTPUT
// // pinMode(srclr, OUTPUT);
// pinMode(gpin, OUTPUT); // Setting gPin as an OUTPUT
// digitalWrite(SHCP_pin, LOW); // Write Pin as LOW
// digitalWrite(DS_pin, LOW); // Write Pin as LOW
// digitalWrite(STCP_pin, LOW); // Write Pin as LOW
// digitalWrite(gpin, LOW); // Write Pin as LOW
// //digitalWrite(srclr, HIGH);
//}
//
///
loop checks the sensor state and will send serial after calibration /
//void loop()
//{
// // read the first sensor
// //int samplse = analogRead(6);
// /
map(value, fromLow, fromHigh, toLow, toHigh)
// map - maps a number from one range to another.
// value - the number to map.
// fromLow - the lower bound of the value’s current range.
// fromHigh - the upper bound of the value’s current range.
// toLow - the lower bound of the value’s target range.
// toHigh - the upper bound of the value’s target range.
// /
// //float sensorvalue = 1.23;
// updateDisplay();
//}
//
//void updateDisplay()
//{
// /
To print the values in the serial monitor, if necessary /
// Serial.println(sensorvalue, 2);
// char buf[10]; // A variable that contains char values
// /
dtostrf - This function converts the float values to the char.
// dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);
// floatvar - float variable
// StringLengthIncDecimalPoint - This is the length of the string that will be created
// numVarsAfterDecimal - The number of digits after the decimal point to print
// charbuf - the array to store the results
// /
// dtostrf(sensorvalue, 4, 2, buf);
//// Serial.println(buf[0]);
//// Serial.println(buf[1]);
//// Serial.println(buf[2]);
//// Serial.println(buf[3]);
// // Writing LOW on the STCP pin allows us to send data to the IC
// digitalWrite(STCP_pin, LOW);
// /
for loop execution /
// for (int i = 0; i <= 3; i++)
// {
// if (buf[i] != ‘.’)
// {
// if (buf[i + 1] == ‘.’)
// {
// /
shiftOut(dataPin, clockPin, bitOrder, value)
// shiftOut - Shifts out a byte of data one bit at a time.
// dataPin - the pin on which to output each bit. Allowed data types: int.
// clockPin - the pin to toggle once the dataPin has been set to the correct value. Allowed data types: int.
// bitOrder - which order to shift out the bits; either MSBFIRST or LSBFIRST.
// value - the data to shift out. Allowed data types: byte.
// converting the resultant char value to a decimal value.
// adding the decimal point wherever we want in the seven segment display
// */
// digitalWrite(STCP_pin, LOW);
// shiftOut(DS_pin, SHCP_pin, MSBFIRST, (dec_digits[(buf[i] - 0x30)])|0X80);
// //shiftOut(DS_pin, SHCP_pin, MSBFIRST, 0X80);
//
// delay(2000);
// digitalWrite(STCP_pin, HIGH);
// //Serial.println(dec_digits[i]);
// }
// else
// {
// digitalWrite(STCP_pin, LOW);
// shiftOut(DS_pin, SHCP_pin, MSBFIRST, dec_digits[(buf[i] - 0x30)]);
// delay(2000);
// digitalWrite(STCP_pin, HIGH);
// }
// }
// }
// // Writing HIGH on the STCP pin, no longer needs to listen for information
// digitalWrite(STCP_pin, HIGH);
//
// // waits for a second
// delay(1000);
//}

And you still have not done it properly

As previously requested, please post your code following the advice given in the link below

As per your guidelines, I gave used serial.println. my dec_digits is not holding my decimal point

But you still have not put your code in code tags

So what happens f you don’t add the dp, just use one condition (the first one)…
Does it display the digits ?

Yes it displays the same digit.