A problem with Seven Segment.. Help me !!! Plz

Hi All,

I'm a beginner in programming so please explain in easy words.

My project is to send a unique code from sender(Nano) to receiver (Uno) to display sender's number via wireless connection(HC-12)

Used 7 Segment 4 digit

It is similar to wireless calling system, broadly used in restaurant, hospital

Problem is when I press the button on the sender, it only shows by each segment.

Here it is my code for sender

SoftwareSerial mySerial(2, 3); //RX, TX

int buttonPin = 8;
boolean onOff = 0; //I have no idea what it does but seems working well

void setup() {
pinMode(buttonPin, INPUT);
mySerial.begin(9600);
}

void loop() {

int buttonState = digitalRead(buttonPin);//read button state

if(buttonState == 1){
mySerial.println(1234); { //send unique code to the receiver to turn on.
onOff = 1;//set boolean to 1
delay(100);
}
}
}

Receiver code

#include "SevSeg.h"
#include <SoftwareSerial.h>

SevSeg sevseg; //Initiate a seven segment controller object
SoftwareSerial mySerial(0,1); // RX, TX

void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);

mySerial.begin(9600);

}

void loop() {

if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)

if(input == 1234){ //**Want to add some time to display number until other code is receive **
sevseg.setNumber(4);
sevseg.refreshDisplay();
delay(100);
}

if(input == 5678){//if on code is received
sevseg.setNumber(5);
sevseg.refreshDisplay();
delay(100);
}
}
mySerial.flush();

delay(10);
}

Thank you all in advance :slight_smile:

ckor01:
Problem is when I press the button on the sender, it only shows by each segment.

could you explain the problem a bit more please... to me your the problem is unclear

did you try to print out to serialmonitor 'input' at the receiver to see if you received correctly your sender id?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

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

Thanks... Tom.. :slight_smile:

Well, if you are getting anything at all to display on the seven segment devices, that is a good start.
Without looking at it too deeply, I suggest first to change this on the RX side:

SoftwareSerial mySerial(0,1); // RX, TX   // DON'T USE 0 or 1 for software serial

Once you have done that, and changed the wiring to match, you can use Serial.begin() and Serial.print() to print debug messages, for example the contents of your variable input.

1st, you should check if transmission is working OK.

2nd, check if pins are defined and connected correctly on sevseg library. You can make a simple program on that microcontroller to check if it displays your desired numbers. Oh, also nothe that you may need to call SevSeg::refreshDisplay() on loop!

3rd, you may try other libraries, as this one I developed and is now on Arduino IDE Library Manager: GitHub - Naguissa/uSevenSegmentLib: Arduino, ESP8266 and STM32 7-segment multiplexed displays library - uSevenSegmentLib

(also intall uTimerLib, needed to work and also available on Library Manager).

void loop() {

/// test 7 segment display then delete / comment out
{ // test code block
sevseg.setNumber(4); // does display shows digit 4 ? where - MSD or LSD?
sevseg.refreshDisplay(); /// may need this here, just once

while(1); // just temporary loop to show display is working
} // test code block

if(mySerial.available() > 1){

this will execute AFTER there are 2 or more data in mySerial.buffer

int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)

if(input == 1234){ //**Want to add some time to display number until other code is receive **

//temporary copy AFTER loop () starts - see above TEST 7 segment display

sevseg.setNumber(4);
sevseg.refreshDisplay();

delay(100);
}

// in practice you could use else if since you have only two choises
// else if( input == 5678)

if(input == 5678){//if on code is received
sevseg.setNumber(5);
sevseg.refreshDisplay();
delay(100);
}
}

// perhaps display something here as an indicator that both above "ifs" failed
// maybe your library can display characters, like this ?
sevseg.setNumber("0000"); // or "----" ??
sevseg.refreshDisplay();

mySerial.flush(); // awaits for Serial output to complete - why?

delay(10);
}