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.
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.
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);
}
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.
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.