AM 4.1 Beta MAX7219 Not Working

Discuss suspected bugs with other users and Sim Innovations Staff

Moderators: russ, Ralph

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

Re: AM 4.1 Beta MAX7219 Not Working

#11 Post by jph »

Perhaps you can help me here with the LUA script - I dont follow the displayX part(s) ?

regarding a line such as - display1 = string.sub(line_text,0,9 )
Would that not be greater than the number of digits in the display ?
Joe. CISSP, MSc.

User avatar
Sling
Posts: 5242
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: AM 4.1 Beta MAX7219 Not Working

#12 Post by Sling »

ReeceRobinson wrote: Sat Oct 16, 2021 9:05 am Hi,
I am trying AM 4.1 Beta as I wanted to test the improved support for MAX7219 chained displays. I am building a com/nav flight radio that uses 3 of these displays in a chain to display the 4 groups of frequency numbers. I was using the released version of AM 4.0.2 but I could only get 2 displays working and hoped to new improved support in AM 4.1 would solve my issue.

This code initially displays the x-plane radio frequencies but will not update if any value changes. If I comment out the third hw_chr_display_set_text line and change the number of displays to 2 from 3, then the first two displays update correctly.

Am I missing something? Does the current AM 4.1 Beta contain the improved MAX7219 handling logic?

I would appreciate your help.
Hi Reece,

It looks like you are not using string.sub() correctly. For starters Lua's indexing starts at 1 so starting at zero is incorrect. Secondly your string handling seems a bit weird. Try printing the 3 strings you are sending to each display to the console and you will see what i mean. You are trying to extract strings of 10 characters when the displays only have 8. i'm not sure why you are creating one big string from the 4 subscribe arguments and then trying to strip it out into 3 strings. It would be simpler to just create the 3 strings directly with whatever combination of sim data you want. I could show an example if i knew what you wanted each display to show.

I don't know if the character display functions are any better now because i haven't tried them myself recently so i would suggest that as an initial test rather than mess about with the string creation discussed above just use three 8 character strings as variables and use these to test the display operation. If all is good after this quick test you can proceed with confidence that the displays operation is working and all you need to figure out is the string creation.

I hope this makes sense.

ReeceRobinson
Posts: 18
Joined: Sun Jun 13, 2021 6:28 am

Re: AM 4.1 Beta MAX7219 Not Working

#13 Post by ReeceRobinson »

I took Joe's suggestion and validated the hardware using the LedControl library in an Arduino program.

Code: Select all

#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
***** Please set the number of devices you have *****
But the maximum default of 8 MAX72XX wil also work.
*/
LedControl lc=LedControl(2,4,3,3);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

/*
This time we have more than one device.
But all of them have to be initialized
individually.
*/
void setup() {
//we have already set the number of devices when we created the LedControl
int devices=lc.getDeviceCount();
//we have to init all devices in a loop
for(int address=0;address<devices;address++) {
/*The MAX72XX is in power-saving mode on startup*/
lc.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,8);
/* and clear the display */
lc.clearDisplay(address);
}
}

void loop() {
//read the number cascaded devices
int devices=lc.getDeviceCount();

//we have to init all devices in a loop
for(int row=0;row<8;row++) {
for(int col=0;col<8;col++) {
for(int address=0;address<devices;address++) {
delay(delaytime);
lc.setLed(address,row,col,true);
delay(delaytime);
lc.setLed(address,row,col,false);
}
}
}
}
This worked exactly as expected so I can rule out any electrical or hardware connection issues.

ReeceRobinson
Posts: 18
Joined: Sun Jun 13, 2021 6:28 am

Re: AM 4.1 Beta MAX7219 Not Working

#14 Post by ReeceRobinson »

Hi Sling,

Thanks for looking at this issue.

Let me explain the reason for the strange string stuff. I am using the ideas for a DIY COM/NAV radio from here -> https://flyingforfun.weebly.com/cessna- ... /#RadioDIY. The total digits needed is 24 which is 3 x 8 char displays in a chain. The reason that the number of digits and the string slicing appear weird is that the decimal point don't count as a digit i.e., the first and last displays have one decimal point and the middle display has two. That makes the string size different but the display is correct.
This image shows the three displays with the four com/nav frequencies from x-plane Image
Using the string manipulation method makes the code simpler in my opinion.

If I can get this working then I will cut down the excess circuit board to remove the gaps between the modules.

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

Re: AM 4.1 Beta MAX7219 Not Working

#15 Post by jph »

Hi Reece,
There is a minor issue with the way the guy wires his displays. (It is a bloody excellent resource though !)

I have edited his wiring diagram for the 'cut down' displays.
I have added the 5V path in yellow. If you use his original path then the first display will be seeing around 0.7V less than the other 2 due to the diode hence that would affect the brightness levels a small amount.
Also, out of interest, where he wires his GND, which is fine, there is usually a 10uF electrolytic capacitor and he is wiring in the area that the -V should go, which is fine. You may find that your boards actually have the capacitor fitted (His do not!) and you can wire the grounds AND 5V to the two pins if you want and it still bypasses the diode drop of the first display.
The other issue you may WELL find is that the use of the 'round pin' sockets for the display pins leads to intermittent display issues due to bad connections. Round (or 'turned') pin sockets are excellent - but not here really. Once you have all the displays aligned you can actually solder the led pins to the socket pins to get rid of the issues. It might melt the sockets a bit but hey ;)
max7219-connecting-1_orig.png
Joe. CISSP, MSc.

ReeceRobinson
Posts: 18
Joined: Sun Jun 13, 2021 6:28 am

Re: AM 4.1 Beta MAX7219 Not Working

#16 Post by ReeceRobinson »

Thanks Joe. Just need to get AirManager to work and I think a lot of people would like to try this. When I get it working I'll post the details and my Lua hardware script on this forum.

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

Re: AM 4.1 Beta MAX7219 Not Working

#17 Post by jph »

Looking forward to it Reece, looks great.
Just to go over something again though where I mentioned the string.sub lua function, and I think sling did too, afaik the indexing starts from 1 with this function, not 0. (I had to look it up myself ;)).
Not sure what starting from 0 would do here as the first character index appears that it should be one ? . possibly completely on the wrong track. :) .
Here's a link to the Lua org string section that I saw the reference to the first sub string index being 1

https://www.lua.org/pil/20.html

If that doesn't make any difference then it would be good to ask Corjan to look at the code ?
Joe
Joe. CISSP, MSc.

ReeceRobinson
Posts: 18
Joined: Sun Jun 13, 2021 6:28 am

Re: AM 4.1 Beta MAX7219 Not Working

#18 Post by ReeceRobinson »

I updated the code to start at 1 and it displays as correctly (see photo provided in previous post). I can confirm the code is not a factor as the chained displays work when only 2 displays are configured in the code. It stops working when changed to 3.

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

Re: AM 4.1 Beta MAX7219 Not Working

#19 Post by jph »

Hi Reece,
Ok, thanks. If I may I will ask @Corjan to have a look at your code in the first post of this thread (the mention here will notify him.)
At least you have fully verified that all is ok from a hardware perspective and flashed with the latest Beta. Let's hope he can offer some insight.
Fingers crossed ;)
Joe.
Joe. CISSP, MSc.

User avatar
Sling
Posts: 5242
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: AM 4.1 Beta MAX7219 Not Working

#20 Post by Sling »

ReeceRobinson wrote: Mon Oct 18, 2021 8:04 am I updated the code to start at 1 and it displays as correctly (see photo provided in previous post). I can confirm the code is not a factor as the chained displays work when only 2 displays are configured in the code. It stops working when changed to 3.
OK. I had a bit of time so i had a look at this for you and I have it working. There are issues as you discovered. This is what i found using an UNO I had laying around.

The 4.1 beta Arduino flash does not work. You need to flash the Arduino with AM 4.0.2.

Both AM 4.0.2 and AM 4.1 works with 3 displays in a chain. I tested with AM 4.1 beta 14.

Your code works but this is more precise. The string.format() should be 6 characters to format what comes from xplane correctly because string.format counts the decimal point so 118.40 is 6 charcters long not 5. This is even though the decimal points are combined with preceeding digits when you use the hw_chr_display_set_text() function. It's a little confusing to actually send 9, 10 and 9 characters respectively to the displays when they only have 8 digits each but as long as one knows not to count dp's as part of the 8 then all is good. Again this could be another helpful note for the wiki.

Code: Select all

    line_text = string.format("%06.02f", comA / 100) .. string.format(" %06.02f ", comB / 100) .. string.format(" %06.02f", navA / 100) .. string.format(" %06.02f", navB / 100)
 
    display1 = string.sub(line_text, 1, 9)	--9 characters total (8 digits and 1 dp)
    display2 = string.sub(line_text, 10, 19)	--10 characters total (8 digits and 2 dp's)
    display3 = string.sub(line_text, 20)	--9 characters total (8 digits and 1 dp)
Oh and make sure the displays are well powered. If you try to daisy chain the 5V line through too many boards then boards down the chain can see significantly reduced voltages. I would limit it to only 2 in a power chain or better still take all the 5V power lines back to the 5V source. OK to daisy chain everything else.

I hope this helps.

Post Reply