ATTINY 2313 serial 7 segment Display

Im try to display receive RS 232 (i use RS232 to ttl converter)numeric value in to 7 segment display. (SEND BY COMPUTER 0 TO 6, DIGIT NUMBER CONTINOUSLY)currently i have this code, it work and display only assign number on 7 segment display(long a =123456;). i cant add library for this becouse of limited memory.

/* Attiny2313 6 Digit Common Anode 7-Segment.
 * Flip the bit to use common cathode.
 * 7Seg : PORTB
 * A:PB4
 * B:PB5
 * C:PB2
 * D:PB0
 * E:PB6
 * F:PB7
 * G:PB3
 * DP:PB1
 * Base digit:PD5
 * Tens digit:PD1
 * Hundred digit:PD2
 * Thousand digit:PD4
 */

#define num0 B11110101 //FEBAGC.D arrangement
#define num1 B00100100 //FEBAGC.D arrangement
#define num2 B01111001 //FEBAGC.D arrangement
#define num3 B00111101 //FEBAGC.D arrangement
#define num4 B10101100 //FEBAGC.D arrangement
#define num5 B10011101 //FEBAGC.D arrangement
#define num6 B11011101 //FEBAGC.D arrangement
#define num7 B00110100 //FEBAGC.D arrangement
#define num8 B11111101 //FEBAGC.D arrangement
#define num9 B10111101 //FEBAGC.D arrangement
#define dp   B00000010 //FEBAGC.D arrangement

#define base_num    B11011111 // PD5
#define tens_num    B11111101 // PD1
#define hund_num    B11111011 // PD2
#define thsn_num    B11101111 // PD4
#define xthsn_num    B11110111 // PD3
#define ythsn_num    B10111111 // PD6

uint8_t number[] = {num0,num1,num2,num3,num4,num5,num6,num7,num8,num9,dp};
uint8_t digit [] = {ythsn_num,xthsn_num,thsn_num,hund_num,tens_num,base_num};
int base = 0;
int tens = 0;
int hund = 0;
int thsn = 0;
int xthsn = 0;
int ythsn = 0;


void setup()
{
  DDRB = B11111111; // All PORTB as outputs
  DDRD = B01111110; // PORTD 1-6 as output
  

 
}

void loop()
{ 
 long a =123456;
   
  base = (a%10);
  tens = ((a/10)%10);
  hund = ((a/100)%10);
  thsn = ((a/1000)%10);
  xthsn = ((a/10000)%10);
  ythsn = (a/100000);
  
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[5];
  PORTB = number[base];
  delay(1); 
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[4];
  PORTB = number[tens];
  delay(1); 
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[3];
  PORTB = number[hund];
  delay(1); 
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[2];
  PORTB = number[thsn];
  delay(1); 
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[1];
  PORTB = number[xthsn];
  delay(1); 
  PORTB = B11111111; //Blanking Signal
  PORTD = digit[0];
  PORTB = number[ythsn];
  delay(1); 
  }

I add serial option to code but it not work and attiny receive data only store in CHAR variable. Can you guys help me to Display received number on 7 segment display.

void setup()
{
  DDRB = B11111111; // All PORTB as outputs
  DDRD = B01111110; // PORTD 1-6 as output
  
 Serial.begin(4800);

 
}

void loop()
{ 
  if (Serial.available() > 0)
  {
    char num = Serial.read() - '0'; 
   long a = atoi( num );
   
  base = (a%10);
  tens = ((a/10)%10);
  hund = ((a/100)%10);
  thsn = ((a/1000)%10);
  xthsn = ((a/10000)%10);
  ythsn = (a/100000);

Is it RS232 or is it TTL?
RS232 is a voltage protocol as well as an asynchronous protocol. If it is an RS232 signal then you need an RS232 to TTL converter board.
But then maybe you use the wrong words.

The second code that actually reads the serial signal looks very wrong. First it will not compile due the missing two braces at the end } and }.

Second because you just read one byte at a time and then go and try to split it up onto various units of time when the variable a can only be a single byte. Just print out the num variable to see what you are getting.

Can you please supply a schematic of what you have in the way of hardware.

im sorry to didnt mention that i use rs 232 to ttl converter.

im realy dont have experiance in serial communcation. can you give me a correct one?

i just add serial option to original code. the only edited part i post.

its a yhl-5 display i replace attiny 2313 ic insted of STC ic.

Then time to read about it try reading:-

That was a photograph it is not a substitute for a schematic.

What is the number's delimiter? That is how do you know when one lot of numbers is finished being sent?

It is going wrong because unless you have received anything on the serial port your display is not being refreshed. In the first code before the serial input the display was being continuously refreshed because the code was not waiting for anything and could constantly be refreshed. Anyway 1mS is way too short a time to show each digit for.

Write the refresh part of the code as a separate function and call that function at the start of each loop.

Better still trigger the changing of the digit being displayed currently in and ISR (Interrupt Service Routine) triggered at regular intervals with a timer.

Now i change the code and board, now i use arduino uno and 7 segment. when i input some number it display perfectly but i continously send number it show the number and 7 segment display start flickering. How to stop these flicker.currently i send continuous data via serial port software to arduino with 10Hz speed (i cant change this speed because weight scale send data in this speed). sending 1 number its ok but continuously send number start flicker. Please check below video.Youtube video. this is how scale send data to uno board Youtube video.

#include<SevSeg.h>
SevSeg sevSeg;           //create object sevSeg



void setup()
{
  Serial.begin(4800);
  byte segDPins[] = {6, 7, 4, 2, 8, 9, 5, 3}; //DPin-8 = seg-a, …, DPin-7 = seg-p
  byte caDPins[] = {A5, A2, A3, A1, A0, A4};   //DPin-A2 = ca0, DPin-A3 = ca1
  sevSeg.begin(COMMON_CATHODE, 6, caDPins, segDPins, true, false, false, true);
  /*
    sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
    updateWithDelays, leadingZeros, disableDecPoint); arg5 = resistors are present; 
    arg6= false; arg7=false (no leading zeto; arg8 = true (no decimal point)
  */
 
}


void loop()
{
  long T = 0;

  unsigned long prMillis = millis();
  while (millis() - prMillis < 100) //wait for 2-second
  {
    sevSeg.refreshDisplay();
    //keep refreshing display until 2-sec has elapsed
  }
  T = Serial.parseInt();
  sevSeg.setNumber(T, 0, LOW);

}

Have you read about Serial.parseInt() ?

serial parseint
I see you have not set the timeout at all.
Do you know exactly what you are being sent? - for example what is the delimiter separating readings, and what indicates the end of a batch of numbers?

How do you know there is something to read in the serial buffer? - You don't

see if

while ((millis() - prMillis) < 100) //wait for 2-second

Helps.

However this is blocking code which will allow stuff to build up in the serial buffer, and possibly block it. I don't see how you are expecting each digit of the long number to appearer one digit at a time from your code as it is written.

Still waiting for a schematic to see how things are wired up.

Showing a long number (six digits) on a seven segment display is never going to work with data coming in continuously at 4800 baud.

Have you tried not connecting your external data and trying things from the serial monitor only. There you can type in your long numbers, so you know that you are getting into your program. Then you can use the serial print in your code to see exactly what is going on.

by single space
ghg

this is simplest diagram
uyuuy
everything work great received number display in 7 segment but 7 segment blink is the only one problem

OK so that is four seven segment displays not a seven segment display. That had me fooled.

I can't see any current limiting resistors on that schematic, are they there in real life? Each segment needs its own resistor. Have you read the ReadMe file inside the library folder?
It says

Current-limiting Resistors

Don't forget that the display uses LEDs, so you should use current-limiting resistors in series with the digit pins. 330 ohms is a safe value if you're unsure. If you use current-limiting resistors on the segment pins instead, then open up the SevSeg.h file and set RESISTORS_ON_SEGMENTS to 1 for optimal brightness.

There is other good stuff as well you need to use.

That picture looks like it is showing about three spaces between the numbers.

When the display is being refreshed it will show the number. But once you are doing other things the display will only show one digit and so will appearer to be off. It seems to me like this is causing the problem.

In fact the example for the library has some code whose last line has the comment

sevseg.refreshDisplay(); // Must run repeatedly

But you are not doing that in your code.

One solution might be to use a timed interrupt that calls the

sevseg.refreshDisplay();

At a regular interval.
Unfortunately I do not know the structure of the timers on the ATtiny 2313, so I don't know if this is possible or not.

Hi Kamonita, did you manage to solve your problem.
Would you be able to post some photos as to where your connection on the board is going, I am especially interested in the blue and green connections and what power supply you are using on the board.

Would appreciate it if you could assist.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.