Jump to content

Arduino vs 7-segment LED


Marcin_B

Recommended Posts

Hi!

 

Trying to connect the 7-segment display at the clock A-10C(only seconds). Unfortunately, my code is an error that can not be found. Does anyone have an idea what's wrong?

 

#define DCSBIOS_IRQ_SERIAL
#include <DcsBios.h>
#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object
 
 byte numDigits = 2;   
 byte digitPins[] = {10,11};
 byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
 
 void onClockSsChange(char* newValue) {
 sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
 sevseg.setBrightness(90);
 sevseg.refreshDisplay(); // Must run repeatedly
}
DcsBios::StringBuffer<2> clockSsBuffer(0x1102, onClockSsChange);

void setup() {
   DcsBios::setup();
}

void loop() {
   DcsBios::loop();
}

Link to comment
Share on other sites

sevseg.refreshDisplay(); // Must run repeatedly

 

That line will not be called repeatedly, but only once in a while when the clock second value actually changes. You should call it from your loop() function instead.

 

The call to sevseg.begin() should go into the setup() function.

 

Also, I cannot see any place in your onClockSsChange() where you are actually writing the newValue to the display. So even if the rest of the sketch had no issues the display wouldn't show anything, because you never tell it what digits to show.

 

Unfortunately, my code is an error that can not be found.

Do you mean there is some error that you cannot find? If there is an actual error message when you try to compile, please post it.

 

When writing a bug report, remember to answer the following three questions:

 

What did you do? Posting the code is a very good start, but it is a good idea to mention whether you could successfully compile it and upload it to your board. Sometimes it is also helpful to know the model of Arduino board that you are using and which versions of DCS-BIOS and the DCS-BIOS Arduino Library you are using.

 

What did you expect to happen?

In this case, the answer to this question can be mostly inferred from what you are trying to achieve, but it doesn't hurt to specify this explicitly.

 

What happened instead?

I am going to assume here that the sketch compiled and was uploaded to the board, but the display stayed blank (because that's what I would expect that code to do).

Link to comment
Share on other sites

Also, I cannot see any place in your onClockSsChange() where you are actually writing the newValue to the display. So even if the rest of the sketch had no issues the display wouldn't show anything, because you never tell it what digits to show.

 

I don't have any idea how to use newValue in my code. Are you use in your code libraries Sevseq or other?

 

sevseg.setNumber(newValue, 1); - 'newValue' was not declared in this scope

 

I can't declare a variable sent with DCS :(

 

Arduino Uno

DCS-BIOS 0.5.0

DCS Arduino library 0.2.3

Link to comment
Share on other sites

This is the part of using DCS-BIOS where you need to understand some programming basics.

The following link looks like a good place to start:

https://www.arduino.cc/en/Tutorial/Foundations#programming

 

Reading the "Variables" and "Functions" sections at the link above should help you understand how variables and functions work, and explain what the "not in scope" error message means.

 

You also need to understand the flow of your program: the setup() method will be called once at the start, so that's where all of your initialization code goes, and where you call DcsBios::setup() so DCS-BIOS can do its own initialization. Then loop() gets executed over and over again. From the loop() function, we call DcsBios::loop() so DCS-BIOS can check if any input has changed or an output needs updating.

Whenever the seconds value of the clock changes, DCS-BIOS will call onClockSsChange and pass the new value as a parameter.

Link to comment
Share on other sites

I changed the library on SevenSeg, Now numbers are displayed correctly but does not shine permanently only flash when changing numbers.

 

#define DCSBIOS_IRQ_SERIAL
#include <SevenSeg.h>
#include <DcsBios.h>
 
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
 
 const int numOfDigits = 2;   
 int digitPins[] = {10,11};


void onDcsBiosFrameSync() {
}

void onClockSsChange(char* newValue) {
       disp.write(newValue);
     }
DcsBios::StringBuffer<2> clockSsBuffer(0x1102, onClockSsChange);



void setup() {
   DcsBios::setup();
   disp.setDigitPins(numOfDigits, digitPins); 
   }
     

void loop() {
   DcsBios::loop();
   }

 

I don't understand why... :(

 

 

Arduino Uno

DCS-BIOS 0.5.0

DCS Arduino library 0.2.3

Link to comment
Share on other sites

Quoting from the SevenSeg documentation, section 4.1:

The high-level printing functions take care of parsing and printing numbers, text strings, etc. for you as long as they are run in an endless loop

 

You are not calling disp.write() from an endless loop; your sketch only calls it once every time the value changes.

 

Try this one instead:

#define DCSBIOS_IRQ_SERIAL
#include <SevenSeg.h>
#include <DcsBios.h>
 
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
 
 const int numOfDigits = 2;   
 int digitPins[] = {10,11};

DcsBios::StringBuffer<2> clockSsBuffer(0x1102, NULL);



void setup() {
   DcsBios::setup();
   disp.setDigitPins(numOfDigits, digitPins); 
   }
     

void loop() {
   DcsBios::loop();
   disp.write(clockSsBuffer.getData());
   }

 

By the way, don't try to use the timer-based multiplexing that the SevenSeg library offers. It is so slow that it ends up blocking other interrupts for so long that incoming data will get lost, so things will stop working. (We recently had that problem on the german forum.)

Link to comment
Share on other sites

Thanks Ian. Everything works. I have just one question - I tried to connect two LCD display and display two different indications. Separately everything works but at this same time LED displays incorrectly. What is the reason?

 

#define DCSBIOS_IRQ_SERIAL
#include <SevenSeg.h>
#include <DcsBios.h>

SevenSeg disp1(2, 3, 4, 5, 6, 7, 8);
SevenSeg disp2(2, 3, 4, 5, 6, 7, 8);  
 
 const int numOfDigits1 = 2;   
 const int numOfDigits2 = 2;   
 
 int digitPins1[] = {9,10};
 int digitPins2[] = {11,12};

DcsBios::StringBuffer<2> ClockMmBuffer(0x1100, NULL);
DcsBios::StringBuffer<2> ClockSsBuffer(0x1102, NULL);

void setup() {
   DcsBios::setup();
  disp1.setDigitPins(numOfDigits1, digitPins1); 
  disp2.setDigitPins(numOfDigits2, digitPins2); 
   }

void loop() {
   DcsBios::loop();
       disp1.write(ClockMmBuffer.getData());
       disp2.write(ClockSsBuffer.getData());
   }

 

 

Arduino Uno

DCS-BIOS 0.5.0

DCS Arduino library 0.2.3

Link to comment
Share on other sites

I tried to connect two LCD display and display two different indications. Separately everything works but at this same time LED displays incorrectly. What is the reason?

 

What does "display incorrectly" mean? This is one of the times where a photo or video is worth a thousand words (or more than two words are required). Don't tell me what it's not doing ("working correctly"), tell me what it's actually doing instead.

 

Some possible issues are described in the SevenSeg documentation, section 3.6, "Example: Multiple Displays".

Link to comment
Share on other sites

Thanks Ian. My fault. I forgot insert line clearDisp in the loop.

Correctly is:

 

 void loop() {
   DcsBios::loop();
       disp1.write(ClockMmBuffer.getData());
       disp1.clearDisp();
       disp2.write(ClockSsBuffer.getData());
       disp2.clearDisp();
   }

 

Now I have two displays (2 x 2 digits) connect to Arduino Uno in this same time.

 

Arduino Uno

DCS-BIOS 0.5.0

DCS Arduino library 0.2.3


Edited by Marcin_B
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...