This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

2 digit - 7 Segment Display Example

Is there an example for using a 10 pin 2 digit 7 segment display similar the picture below?

It is common anode and actually has 10 pins (pin 2 is the DP or decimal point). I have all of the LED pins (1-4 and 5-9) hooked up to their own GPIO and the common anodes are hooked up to pins 10 and 5 through a PNP transistor. Those 2 transistors are hooked up their own GPIO pins. I need an example to multiplex the 2 displays without adding any other chips.

I did this before on Arduino using an old library I found but not sure how to do this on nRF51822.

I am using a custom board with nrf51822 chip. SDK 12.

Any help would be appreciated!

2 digit 10 pin 7 segment display 7 segment display?

Parents
  • Have no idea if there's sample code for that, but it's very simple to write. You just want to round-robin between the two segments giving each a fraction of a second, then going back to the other one.

    Keep the current bitmap of on/off for each segment for each of the two (or more) segments, you can update that whenever you like. Then set up a repeating app timer, or any other repeating timer, which alternately puts one or other bitmap onto the cathode pins and sets/resets the correct one of the anode pins. Adjust the interval to be fast enough not to flicker, slow enough to give the LEDs time to light up.

    You change the value displayed by simply writing one or other of the bitmaps in memory, it will show on the next cycle for that digit, completely asynchronous and about 5 lines of code.

    I think you have your GPIO numbers wrong, you've used 5 twice, so you probably mean 1-4 and 6-9, and hopefully you don't have the cathodes connected directly to the GPIO pins because any LED display I've come across will need way more current than the nRF can sink.

Reply
  • Have no idea if there's sample code for that, but it's very simple to write. You just want to round-robin between the two segments giving each a fraction of a second, then going back to the other one.

    Keep the current bitmap of on/off for each segment for each of the two (or more) segments, you can update that whenever you like. Then set up a repeating app timer, or any other repeating timer, which alternately puts one or other bitmap onto the cathode pins and sets/resets the correct one of the anode pins. Adjust the interval to be fast enough not to flicker, slow enough to give the LEDs time to light up.

    You change the value displayed by simply writing one or other of the bitmaps in memory, it will show on the next cycle for that digit, completely asynchronous and about 5 lines of code.

    I think you have your GPIO numbers wrong, you've used 5 twice, so you probably mean 1-4 and 6-9, and hopefully you don't have the cathodes connected directly to the GPIO pins because any LED display I've come across will need way more current than the nRF can sink.

Children
  • Yes - you are correct, I typed the numbers wrong - should have been 1-4 and 6-9 as you said. 5 and 10 are common anodes.

    You have been a big help so far!

    Can you explain more (or example code) the repeating app timer (new to nRF). I set the individual led segments up as LEDs and the Comman Anodes as GPIOs. I am able to get "Ao" to show on the display with the following code for about 5 seconds with a for loop when a button is pressed but ends up just saying "o" at the end of the for loop:

                {
            LEDS_OFF(LEDS_MASK);
            LEDS_ON(SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G);
            nrf_gpio_pin_write(COMAN1,1);
            nrf_gpio_pin_write(COMAN2,0);
            nrf_delay_ms(5);
            LEDS_OFF(LEDS_MASK);
            LEDS_ON(SEG_C | SEG_D | SEG_E | SEG_G);
            nrf_gpio_pin_write(COMAN1,0);
            nrf_gpio_pin_write(COMAN2,1);
            nrf_delay_ms(5);
            }
    

    Obviously, that will not work in a complete program - mainly with the delay (I need to avoid using that as the program hangs while in delay) and the fact that I assume that I should not be running that in a for loop.

    Can you suggest a proper way to code this? I want the display to say one thing constantly until a button is pressed to change a setting and then the display will say something else. I assume this will be done in memory and asynchronously as you stated but I have no idea where to begin with nRF. Thanks in advance!

Related