Android Question LED sign application

techknight

Well-Known Member
Licensed User
Longtime User
I am making a simple little application to send text to a 1-bit per pixel LED matrix.

I know this has been done at least 1000 times, with all the LED signs and software out there, but there really isnt a good explanation on HOW its done.

The question is this: How would you take a simple font/typeface, any installed font, any size, italics, etc.. and convert it into a bitmap to be displayed on a pixel array?

With B4A, or any other language, its simple to make a font or convert a font by hand into a bitmap pixel format, and just use a lookup table and if the ASCII character is found, then copy the bitmap of that character into the memory to be written to the LED matrix. The problem with this approach is, sizing and spacing cannot be proportional. it has to be fixed. Then of course, a bitmap of every single character of the font, upper and lower case, plus numbers and symbols would have to be made. And for each and every font, AND size. Seems like a nightmare scenario.

But with different justify alignments, sizes, etc it just doesnt seem that everyone is doing it this way. I think fonts are being rendered into bitmaps somehow.

I've seen software that has a "simulated" LED matrix window on the screen, and anything you type, pick a font and size, gets rendered onto that simulation screen. How do they do that? I assume the term is rasterization.

Does anyone know how to do this in B4a?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Have you tried Drawing the text on a canvas then capturing it's bitmap?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I would say you need to think old-school...
I remember back in my ZX Spectrum days, making basic graphics using peek and poke to set bits on the 8 bit font..

best approach to you would be to define a canvas with the same size as you display... a 1led per 1pixed relation
Draw your text into that canvas, keep it simple using only 2 solid colors, background and foreground, then go picel by pixel and go a "bit map" from your canvas.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I had a feeling it was going to be something like that.

Because I know in VB6 you can get pixel info from a picturebox.

Then the next question is, How do you do scrolling or any type of "effects" with it? Just curious.

I did run into a bucketload of bitmap fonts from about 1993 or so.

As an electronics engineer, it drives me nuts seeing these window LED displays running text, and doing crazy animations at the same time the text is scrolling, within the text, etc.. How do they do it... haha.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Coming back to this thread, There is no "canvas" control on B4A designer.

Looking at the Wiki, it shows a canvas function. However, it doesnt appear that I can specify a certain pixel size, and it also doesnt appear that I can read the pixel data out of it in any other way than a bitmap.PNG type method, which wont work. I need the pixel data in binary to build a packet to be sent to the LED sign.
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
You should declare a bitmap, and initialize mutable with the width and height of your display.

Then initialize a canvas with this bitmap (canvas.Initialize2(...)) and draw onto it.

If you only want one bit per pixel, then draw only with one color

Once drawn, you can get the pixels in any position with bitmap.getpixel(...) And send them to your display

look here, I did something similar with B4A and some leds

https://www.b4x.com/android/forum/threads/jg-ledstrip-apa102.50708/page-2#post-376729
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I don't understand why would you convert the text to a bitmap if you want to display text and not images.. you already have the text.
The best bet is, no tech details though, is to (lay) the letter, say "A", to its side.. or rotate it 90 degrees, then you will have the byte array of that letter rotated.
It's your responsibility then to output it byte by byte to the display in high frequency.. you will have the letter "A" displayed and stay there. If you want it to
scroll, then you will need two counters with two frequencies.. the multiplexing frequency and the shifting frequency.. I did this in 1987 when I soldered all
of the LED grid of the display by hand, ending with 7 common anodes, and 50 common cathodes. You will need to design and build the multiplex controller/LED driver
Well I leave here and wish you a good luck.. I think you've got the idea.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
you cant just throw "text" on an LED display. you have to convert it into some sort of bitmap/pixel array so it can be written into the multiplex refresh buffer. We are talking 8-bit micros here, much as like what you worked with in 1987. LED signs have been around for years and I hate re-inventing the wheel, but it seems as if all LED stuff was never open source, and the ones that are, are about as useless as a screen door on a submarine, or written in a language that I dont develop in, reverting back to my previously mentioned phrase.

The closest thing I found to a "real" LED sign was LEDScape. But thats way more sophisticated than what I need here.

Also, the LED hardware is complete. and working. But I just dont have a good way to display sizeable text. I can run fixed font, 5x7 by a huge ass lookup table in the LED sign firmware, but thats clunky. The best thing I found so far was the old school VGA fonts which are already binary bitmap things. Making it easy to use on the hardware side by again, building large flash space eating tables... Downside to these though, is the fact that they are not scalable. they are all only 8 px wide. but dynamically tall, such as 8 pix tall, or 14, or 17.

This is the reason why I wanted to use dynamically generated fonts into bitmap. This way, I can put a huge text on there, itallic, or bold, or whatever, make it say HELLO! or even display the time of day or temperature which would require some sort of font table in the sign itself to do.

Scrolling will come later. All I need is static text. My plan was to render the frame on the tablet, and then store them into memory on the sign itself. The sign loads and displays frame by frame. one by one. with a programmable delay in between.
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Which is your display size?

The function you are looking for is canvas.DrawText(...) for drawing and Bitmap.GetPixel(..) for getting the pixel value.

But, as your display is one bit per pixel, you will have to do some thresholding, since canvas.DrawText(...) will draw "half-tones" on those pixels corresponding to the character's outer borders.

Something similar to (not complete and not tested)
B4X:
Dim ww as int = 128  'your display size in pixels
Dim hh as int =64
Dim message as string="Hello"
Dim size as float=5.0  ' you will have to experiment

Dim xpos as int=0
Dim ypos as int = hh/2 + c.measureStringHeight(message,Typeface.DEFAULT,size)/2

Dim B_disp as Bitmap
B_disp.initialize(ww,hh)
Dim c as canvas
c.initialize2(B_disp)
c.DrawColor(Colors.Black)
c.DrawText(message,xpos,ypos,Typeface.DEFAULT,size,Colors.White,"LEFT")

'Now get the pixels
dim myPixels(ww*hh) as byte
for row=0 to hh-1
  for col=0 to ww-1
    Dim myColor as Int = B.GetPixel(col,row)
    If Bit.And(myColor,255)>100 then ' or any other threshold, values can go from 0 to 255
      myPixels(ww*row + col)=1
    Else
      myPixels(ww*row+col)=0
    End If
  Next
Next
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi Technight

You are right if you want sizable fonts.. I was discussing a simple system to display char-to-5x7, from what you said:
(I am making a simple little application to send text to a 1-bit per pixel LED matrix.).
If it was just simple text then all you need is a (raw) LED matrix and design a microcontroller with two frequencies as mentioned, one fast for the multiplexing, and the other
slow for moving the text (shifting).
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I have 5x7 covered, that wasnt my issue. my issue was dynamic fonts and size. But anyways. The application is simple, or well at least what I thought was simple. and its still 1-bit per pixel text. I guess I never specified "what" text.

Oh, and my matrix size is 48x112. I designed 16x16 tiles that use piranha LEDs, and are powered by ATmega8s and individually addressable. it uses RS485 interconnects, and run at 250K baud from the master card.

the master card is what stores all the fonts/que and sends the data to the matrix tiles through a secondary UART.

The master card is using an ATXmega128A, which runs at 32Mhz. Now currently I am using as I mentioned before, VGA fonts stored in flash memory. the routine that pulls the font data out of the lookup table, and writes into the output buffer. But its fixed width 8pixels.

Dynamically sizing them using truetype fonts like a PC uses seems like a feat which is why I asked about it here. Also I dont know C at all, or any form thereof. I am a BASIC programmer which is why I use B4A. So using C libraries on the sign itself for drawing text is beyond my knowledge scope.
 
Last edited:
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hmm.. tricky. But I like the challenge
Two choices.. Map or Bitmap.
BRB
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I created a 48x112 pixel preview window by using a label array. background red = on, background grey = off. These are loaded inside a panel.

Works great, BUT... it is very very very horrifyingly slow when that thing is visible on the activity window. the whole GUI goes to 486 speeds. My assumption is because there are now 5376 tiny little pixel size labels on the screen laid out in a grid.

is there a more efficient way to layout a preview pixel grid?
 
Upvote 0
Top