I had a little stroke of luck discovering that on displays that are not supposed to be able to support transparency, it is still possible to get transparent text. The text component does not give you the option of a transparent background on Basic and Enhanced displays. And Intelligent displays are not available in the smaller sizes. The docs suggest this is a technical limitation of the lower cost displays. But I found that the xstr command does support transparent backgrounds (use ‘3’ for the last but one parameter). This allows you, for instance, to add legends and markers to guages and progress bars. The next problem you hit though is that updating said gauge or bar will overwrite your text. Rewriting your text after the update does not seem to work. But add a little delay between the update and the text rewrite and back it comes (5ms seems to work for me). There is an occasional flicker but it’s not terrible. Hope this helps somebody one day.
I’ve never played with this.
Does this mean you can write text on the screen in an adhoc way?
(Rather than sending it to a predefined txt object.)
usage: xstr <x>,<y>,<w>,<h>,<font>,<pco>,<bco>,<xcen>,<ycen>,<sta>,<text> <x> is the x coordinate of upper left corner of defined text area <y> is the y coordinate of upper left corner of defined text area <w> is the width of the defined text area <h> is the height of the defined text area <font> is the number of the Resource Font <pco> is the foreground color of text (Color Constant or 565 color value) <bco> is a) background color of text, or b) picid if <sta> is set to 0 or 2 <xcen> is the Horizontal Alignment (0 – left, 1 – centered, 2 – right) <ycen> is the Vertical Alignment (0 – top/upper, 1 – center, 3 – bottom/lower) <sta> is background Fill (0 – crop image, 1 – solid color, 2 – image, 3 – none) <text> is the string content (constant or .txt attribute), ie “China”, or va0.txt xstr 10,10,100,30,1,WHITE,GREEN,1,1,1,va0.txt
You are obviously referring to the sta parameter.
Can you please cut 'n paste your line of code that does this, and a screen shot of the result?
Sure. So this shows a single line on a slider with a black background. h0.val updates it. the fill and cirs are the horizontal line and blue dot. The rest is the radio frequency text laid out like the ol’ days.
h0.val=0 delay=5 fill 14,92,288,2,65535 cirs 50,92,7,31 xstr 18,64,30,30,11,WHITE,GREEN,0,0,3,"AM" xstr 62,64,30,30,11,WHITE,GREEN,0,0,3,"6" xstr 106,64,30,30,11,WHITE,GREEN,0,0,3,"8" xstr 146,64,30,30,11,WHITE,GREEN,0,0,3,"10" xstr 192,64,30,30,11,WHITE,GREEN,0,0,3,"12" xstr 235,64,30,30,11,WHITE,GREEN,0,0,3,"14" xstr 275,64,30,30,11,WHITE,GREEN,0,0,3,"16" xstr 18,98,30,30,11,WHITE,GREEN,0,0,3,"FM" xstr 58,98,30,30,11,WHITE,GREEN,0,0,3,"89" xstr 106,98,30,30,11,WHITE,GREEN,0,0,3,"92" xstr 165,98,30,30,11,WHITE,GREEN,0,0,3,"96" xstr 206,98,30,30,11,WHITE,GREEN,0,0,3,"100" xstr 266,98,30,30,11,WHITE,GREEN,0,0,3,"104"
Gives this the dial part of this:
The fonts are a bit crap but at this scale it’s not a problem.
That’s really neat.
Thanks for sharing.
Is your MCU controlling an SDR or some other receiver module?
With the 5mS pause required, have you tried sending to the Nextion at faster baud rates, or is this a limitation within the Nextion and showing its lack of processing grunt?
Thanks! I’m between commercial jobs at the moment so this is one of those, fun and maaaybe it’ll make some money, projects. It’s going to be driving a Silicon Labs tuner chip. Multiband if I can get the RF to work, FM only if I can’t. And the display will change depending on how many bands I can get it to work with. I’ll also be able to reproduce analog style displays for different regions.
The 5mS pause is in the Nextion code so, I assume, running as fast as possible. BUT, NEWS JUST IN, I tried making the delay=0 and it still worked. Took the line out and it didn’t. So, I’m guessing, just the delay caused by the extra instruction is enough of a delay. It still flickers a bit though, unfortunately. Maybe there is an instruction that is faster than the delay but would be fast enough to fool the eye. Or maybe that is just a limitation of the display.
Instead of a 0ms delay, use doevents, then it will just take the time needed to update the display (or none).
That’s a good idea. I just tried it. It doesn’t improve the flicker at all but at least there is no serial blocking at all. Thanks for the heads up
Now I need to understand the differences in the way fonts are handled between TJC and Nextion and see if I can make this display look a little sharper. Any pointers?