7 segment display reverse digits

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 7 segment display reverse digits

#41 Post by jph »

I am sorry Keith but I dont understand what you are saying re - 'we both agree that is the wiring on the displays'
As I do not have any 3 digit or 6 digit max7219 based display I cannot comment on how it they are wired hence I cannot say I agree.
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 7 segment display reverse digits

#42 Post by jph »

If you want to test a display against the format that SI use then simply send '01234567' to the display from AM as AM is set up for an 8 digit display.
The number shown on whatever display you have will indicate the digit number due to the way the max is controlled.

You can do it on the Arduino as well if you want, but no real need.
Here is the basis of the 7219 control I use for both numeric and matrix control. This is used with messageport of course.
If you look at the datasheet for the 7219 then you will see the control is fairly simple. I use hardware SPI with simple control of the chip select pin.

ALL 7219 control I do is based on this code of mine.
You are welcome to use it with appropriate acknowledgements. You can do absolutely anything within the capabilities of the 7219 with this code.

Code: Select all

/* 
******************************************************************************************************
*                                                                                                    *
*                             Joe Hanley 2022  (JPH Air Manager forums)                              *
*                                                                                                    *
******************************************************************************************************
*  Base level programming for MAX7219 controller IC. 
*  Using full hardware SPI up to 10 MHz on appropriate controller (No faster as 7219 is rated for no more than 10 MHz SPI)
*  NOT to be used for commercial purposes without permission !.  
*/

// Serial3 is for STLink serial on Nucelo board with messageport

// includes 
#include <SPI.h> 
                                                                                 		 
// defines
#define MAX7219_CS 10

// MAX7219 SPI LED Driver maxCmd Codes
#define MAX7219_TEST        0x0f    // in real code put into a .h file
#define MAX7219_BRIGHTNESS  0x0a    // in real code put into a .h file
#define MAX7219_SCAN_LIMIT  0x0b    // in real code put into a .h file
#define MAX7219_DECODE_MODE 0x09    // in real code put into a .h file
#define MAX7219_SHUTDOWN    0x0C    // in real code put into a .h file

// constants
 
// variables

//****************************************************************************************************

void setup() {                                // setup: run once

  
  pinMode(MAX7219_CS, OUTPUT);  // set out chip select pin as output.
  
  // clock and data on 7219 go to standard hardware SPI CLK and MOSI pins on your micro.
  
  SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));  // maximum 10 MHz max speed of MAX7219 SPI, MSBFIRST and MODE0.
  /*  SPISettings
   *  the UNO and almost ALL 'arduino' are not going to make 10 Megahertz SPI but will work. Ideally use a Pi Pico or STM32 / ESP32. 
   *  MODE0 is BY FAR the most common mode used in SPI, it is almost universal.
   *  MSBFIRST is used with the MAX7219
   */

  SPI.begin();                   // Start SPI // Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.

  // set up and ititialise the max7219
  maxTransferCmd(MAX7219_TEST,        0x01 );    // run test - all LED segments lit. 
  delay(1000);                                   // allow time for leds to be illuminated for test.
  maxTransferCmd(MAX7219_TEST,        0x00 );    // finish led all lit test.
  maxTransferCmd(MAX7219_DECODE_MODE, 0x00 );    // disable BCD mode.  // disabled to allow full matrix control. Set as required.
  maxTransferCmd(MAX7219_BRIGHTNESS,  0x0f );    // set intensity. 0 - 15  // 0x00 to 0x0F 
  maxTransferCmd(MAX7219_SCAN_LIMIT,  0x0F );    // Scan all digits. // DO NOT CHANGE without referring to datasheet. This does NOT refer to number of 7219 devices !!
  maxTransferCmd(MAX7219_SHUTDOWN,    0x01 );    // Turn on chip. NOT shutdown.


}  // run once setup end

//****************************************************************************************************

void loop() {                  // main program loop 
  
  // do something here
  
  
}                              // main program loop end

/*
              ****************************************************************************************************** 
              *                                           Subroutines                                              *
              ******************************************************************************************************
*/
/* transfer a CMD code and its value to the MAX7219 */

void maxTransferCmd(uint8_t maxAddress, uint8_t maxData) {    // we could use same call as maxTransferData but this makes it easier to read
  maxWrite16bits(maxAddress,maxData);
}

/* ************************************************************************************************ */

/* transfer data address and row value to MAX7219 // here it is 'row' (or digit) with value 1 to 8 */ corresponding to D0 to D7

void maxTransferData(uint8_t maxAddress, uint8_t maxData) {   // we could use same call as maxTransferCmd but this makes it easier to read
  maxWrite16bits(maxAddress,maxData);
}
/* ************************************************************************************************ */

void maxWrite16bits(uint8_t maxAddress,uint8_t maxData) {    // sends the Hardware SPI data to the MAX7219
                                                             // same routine for CMD or DATA, just different call for clarity
  digitalWrite(MAX7219_CS, LOW);    // start transfer        // take CS low  
  SPI.transfer(maxAddress);         // Send the address byte     
  SPI.transfer(maxData);            // Send the data byte 
  digitalWrite(MAX7219_CS, HIGH);   // finish transfer       // Finished so take CS HIGH
   
}                                                            // end of maxWrite16bits

/* **************************************************************************************************


 */
 /* transparent delay constituents
 // constants
const uint16_t DELAY_PERIOD = 1000;     // delay period
// variables
uint32_t millisLast = millis();         // for our transparent delay 
//transparent delay wrapper
  if (millis() - millisLast >= DELAY_PERIOD) {    
    // do things
    millisLast = millis();
  }
*/
Last edited by jph on Mon Aug 29, 2022 12:53 pm, edited 2 times in total.
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: 7 segment display reverse digits

#43 Post by Keith Baxter »

jph wrote: Sun Aug 28, 2022 5:17 pm I am sorry Keith but I dont understand what you are saying re - 'we both agree that is the wiring on the displays'
As I do not have any 3 digit or 6 digit max7219 based display I cannot comment on how it they are wired hence I cannot say I agree.
Joe,

I think what I need to do is draw up some schematics with just the IC to led display. My bad explanations are obviously lacking.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 7 segment display reverse digits

#44 Post by jph »

If you want to, that is up to you but you are wasting your time. As said, just send '01234567' to the display being tested with AM and you can see which digit is wired to which 7219 output (by referring to the schematic of single standard 8 digit 7219 cheap module that is ubiquitous). It is as simple as that.

Schematics are of absolutely no point at all as you know the primary layout of the standard ancient 8 digit 7219 module then everything else can be deduced by sending the simple number combination, nothing at all more is needed. I also said this about 197 posts ago. :lol:

I don't think you grasp that part ? - just send the number combination and read off the digit order. Cannot be simpler. :D

edit - to know EXACTLY which actual 7219 hardware pin (d0-d7) the digits are connected to - when using AM, you actually send '76543210'

then it is pin for pin. so wherever the number 3 is shown on the display you have (from AM) then that digit is connected to 7219 D3 etc etc.
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 7 segment display reverse digits

#45 Post by jph »

the above works because of the way the ubiquitous module is wired.
Knowing this, then you can use AM to see the wiring on ANY 7219 module WITHOUT other schematics using the '76543210' method
image.png
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: 7 segment display reverse digits

#46 Post by Keith Baxter »

Ahhh,

You are now starting to get my beef. ;) A MAX7219 could also be wired 0,1,2,3,4,5,6,7 or anything between 0 and 7
This is a design I did for a com radio. I use the standard AM MAX7219 HW add using a MAX7219 IC (NOT A BOARD) and 2 x 3 digit displays for a 6 digit led.
I could also do the same using 1 x 6 digit display but the schematic would be different. ( 5,4,3,2,1,0)

This is the pcb tracts.
ice_screenshot_20220828-202149.png
This is the front 3D pcb view.
ice_screenshot_20220828-202117.png
This is the back 3D pcb view
ice_screenshot_20220828-202044.png

This is the schematic for that com radio.
ice_screenshot_20220828-202027.png

Take note of how the displays are numbered.

This is the code for that.

The point is. If I had not taken into account that indexing is from right to left I would have had issues.
Anyone using that code that is in the store would just have to change the indexing direction if it is wired left to right. No string formatting, no hacking, just a simple argument change in the HW add.


Keith

EDIT: I think I have flogged this to death. It was just a :idea: to make things easy, both for the user and for future popular IC's
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: 7 segment display reverse digits

#47 Post by Keith Baxter »

Hi,
EDIT: I think I have flogged this to death. It was just a :idea: to make things easy, both for the user and for future popular IC's
Sorry apparently not. Last one. Or maybe JUST another one or two. :mrgreen:

I can take any 7-segment decoder (or 14-segment decoder for that matter) [IC], but we talk to 7 segment IC here and wire it up so that it outputs to "AM digital" inputs and then write code to a HW 8 Segment display (The 8th segment being the DP.) then whatever IC I use the code would be consistent. That is because what ever is coming out of <7-segment decoder> will be going into the arduino as 01234567 .

If a IC (chip) drives a led display or the arduino does, surly that can be done in AM internal code?
But this Corjan has already done. Saving pin count.

I think we should standardize on 01234567 for all IC's and make a option for 76543210.

I will do a coding impact of string.reverse() as to index reverse so that when fewer digits are used on a chip, what is involved in hacking the string and expected results.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: 7 segment display reverse digits

#48 Post by jph »

Keith Baxter wrote: Sun Aug 28, 2022 9:26 pm Hi,
EDIT: I think I have flogged this to death. It was just a :idea: to make things easy, both for the user and for future popular IC's
Sorry apparently not. Last one. Or maybe JUST another one or two. :mrgreen:

I can take any 7-segment decoder (or 14-segment decoder for that matter) [IC], but we talk to 7 segment IC here and wire it up so that it outputs to "AM digital" inputs and then write code to a HW 8 Segment display (The 8th segment being the DP.) then whatever IC I use the code would be consistent. That is because what ever is coming out of <7-segment decoder> will be going into the arduino as 01234567 .

If a IC (chip) drives a led display or the arduino does, surly that can be done in AM internal code?
But this Corjan has already done. Saving pin count.

I think we should standardize on 01234567 for all IC's and make a option for 76543210.

I will do a coding impact of string.reverse() as to index reverse so that when fewer digits are used on a chip, what is involved in hacking the string and expected results.


Keith
Hi Keith,
Can you repost your schematic - but larger. My eyes are good, but not that good ;)
As for the 'universal decoder' well no, it doesn't work like that unfortunately as you would still have to tell the code in the Arduino what exact type of hardware was in use - the type of 7 segment decoder , 7219, 1637 / 8 etc, and the digit order. Forget the term 'index' as it is misleading. Index tend to indicate a flow from a lower to a higher or visa versa, that is not the case as I showed with the TM1637 where there are two digit blocks (2 x 3 digits blocks) and the addressing is non linear so no reversal of a string would work. separation of the string into parts and then reversal and reassembly of each part would, but not a straight reversal as it is totally non linear to start with. Not an issue though to a man of your mean. ;) Any string manipulation prior to sending (in AM) will have absolutely no impact at all unless you were running on a TRS-80 model 1 (although mine was a 'level 2' with the 48kb expansion). :)
Joe
Joe. CISSP, MSc.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: 7 segment display reverse digits

#49 Post by Keith Baxter »

HI,

Lets consider A MAX7219 that has 8 digits and is wired 76543210
If we set the text ....hw_chr_display_set_text(display_chr_id, 0, 0, "123.45")
The display shows <123.45▒▒▒>
If I now reverse the string ....hw_chr_display_set_text(display , 0, 0,string.reverse(tostring(123.45)))
The display shows <54.321▒▒▒>
Because the string is only 5 digits long the MAX7219 IC is only using digits 76543. Digits 210 are blank and not used

This time Lets consider A MAX7219 that has 8 digits and is wired 01234567
If we set the text ....hw_chr_display_set_text(display_chr_id, 0, 0, "123.45")
The display shows <▒▒▒54.321>
If I now reverse the string ....hw_chr_display_set_text(display , 0, 0,string.reverse(tostring(123.45)))
The display shows <▒▒▒123.45>
This time the MAX7219 IC is only using digits 34567. Digits 012 are blank and not used.

In order to get the string to display in the correct position we now have to format the string
-------------------------------------------------------------------------------------------------------------------------

Lets consider A MAX7219 that has 5 digits and is wired 43210
If we set the text ....hw_chr_display_set_text(display_chr_id, 0, 0, "123.45")
The display shows <45▒▒▒>
If I now reverse the string ....hw_chr_display_set_text(display , 0, 0,string.reverse(tostring(123.45)))
The display shows <21▒▒▒>
In order to move the string to the right we format it ...hw_chr_display_set_text(display , 0, 0,string.format("% 9.02f",tostring(123.45)))
The display shows <123.45>
If we now reverse the string ...hw_chr_display_set_text(display , 0, 0,string.format("% 9.02f",string.reverse(tostring(123.45))))
The display shows <▒54.32> This is because string is formatted for 2 decimals.
-------------------------------------------------------------------------------------------------------------------------

The dilemma come in. How should a 5 digit display be wired to the MAX7219

If you are building one yourself then 43210. and a simple hw_chr_display_set_text(display , 0, 0,string.format("% 9.02f",tostring(123.45))) will do the trick.
But if you buy one it is most likely wired 01234. and then all sorts of string hacking is required.
--------------------------------------------------------------------------------------------------------------------------

Lets now talk about the TM1637 4 digit it is wired 0123 and the 6 digit is wired 543210.
All the above applies.

Hence I feel it is far easier for newbies to have a direction argument than having to hack the strings.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: 7 segment display reverse digits

#50 Post by Keith Baxter »

jph wrote: Mon Aug 29, 2022 7:13 am
Hi Keith,
Can you repost your schematic - but larger. My eyes are good, but not that good ;)
Joe
Joe,

Sorry the forum only allows for small size.
I normally click on the image and it opens on the DT. I then CTRL scroll-wheel to enlarge.
Schematic_Com Radio Boeing 737_2022-08-29.pdf
(166.06 KiB) Downloaded 57 times
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply