B4R Question p10 led panel library

tango

Active Member
Licensed User
Longtime User
i couldnt solve this problem.

#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public dmd1 As DMD
End Sub

Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
' dmdp10.Initialize(32,16)
' dmdp10.clearScreen(1)
' AddLooper("Draw")
RunNative("loop", Null)
End Sub

Sub Draw
'dmdp10.drawString(1,1,"abc",3,0)
End Sub



B4R version: 1.50
Parsing code. (0.00s)
Compiling code. (0.01s)
Building project (0.02s)
Compiling & deploying Ino project (Arduino Nano - COM4) Error
ayarlar yükleniyor...
paketler ayarlanıyor...
Devre kartları hazırlanıyor...
Dogrulanıyor ve yükleniyor...
In file included from sketch\B4RDefines.h:27:0,
from sketch\B4RArduino.cpp:1:
b4r_main.h:13: error: 'B4RDMD' in namespace 'B4R' does not name a type
static B4R::B4RDMD* _dmd1;
^
exit status 1
'B4RDMD' in namespace 'B4R' does not name a type
 

Attachments

  • dmd-lib.zip
    30.3 KB · Views: 463
Upvote 0

thetrueman

Active Member
Although this is old thread but to continue it for the same question as B4R members have introduced many libraries and examples about different displays so P10, P8, or P5 etc. RGB displays are very good to replace 7-segments displays to display multiple style information.

Here is already a library in the following thread but I would like to expand the capability of B4R to use DMD or any other latest library for such LED matrix panels with ESP8266 to use WiFi or Serial Data to display. Waiting for experts to have a deeper look inside, Thanks.

https://www.b4x.com/android/forum/threads/adafruit-rgb-led-matrix.81157/
 
Upvote 0

thetrueman

Active Member
can you check this wrapper for DMD library ?
Since the library available, I arranged P10 display and studied its connections and then tried the basic DMD library for arduino from freetronics. It worked with Arduino UNO in Arduino 1.8.5 so it confirmed that all boards and connections are fine.

Then I moved to B4R 3.9 and used the library rDMD and its example which gave the errors. By reading logs I found that in DMD.h file included in rDMD.zip, there is path error on line number 47 which I checked from original DMD.h file which I changed from #include <pgmspace.h> to #include <avr/pgmspace.h> but still there are compile errors which logs are attached. Thanks.
 

Attachments

  • B4R Error Logs P10-DMD.txt
    107.5 KB · Views: 17
Upvote 0

candide

Active Member
Licensed User
it seems we have " multiple definition of `DMD::DMD(unsigned char, unsigned char)'"

i don't have issue on a PC but in my case DMD is not installed under arduino

can you remove DMD.h and DMD.cpp in rDMD directory ? just to see if it is better...
 
Upvote 0

thetrueman

Active Member
Thanks candide for hint and I explain to clarify that I just unzipped the rDMD library and put it in additional library folder. DMD.h and DMD.cpp are already included in zip file which were copied with other files. I removed them as you advised and now the compilation completed and uploaded but could not run. There was an error in the end of logs... (Attached)

********************* PROGRAM STARTING ****************
[IDE message - 10:01:30]
An error occurred.
The directory name is invalid

BTW my directory structure is "G:\123\P10 LED Panel\P10 Test B4R"
 

Attachments

  • B4R Error Logs P10-DMD.txt
    64.7 KB · Views: 18
Upvote 0

candide

Active Member
Licensed User
can you remove spaces in directory tree ?
"G:\123\P10 LED Panel\P10 Test B4R" ==> "G:\123\P10_LED_Panel\P10_Test_B4R"
 
Upvote 0

thetrueman

Active Member
I removed spaces and it complied successfully and log shows "App Start" but there is no display.
I restarted the board but no luck. I re-checked with Arduino, which is OK.

test_DMD project is attached. Thanks.
 

Attachments

  • test_DMD.zip
    2 KB · Views: 21
Upvote 0

candide

Active Member
Licensed User
can you change in rDMD.h :

#include "B4RDefines.h"
#pragma once
#include "B4RDefines.h"
#include "DMD.h"

to

#include "B4RDefines.h"
#pragma once
#include "B4RDefines.h"
#include "DMD.h"
#include <SPI.h>
 
Upvote 0

thetrueman

Active Member
Thanks candide for your efforts. I changed the file as you instructed and download the program. This time some random leds flashes on resets the arduino board and then blank display. I retried with arduino again to confirm that my hardware setup is still OK. Thanks.
 
Upvote 0

candide

Active Member
Licensed User
it can be an issue with fonts management,

1) can you modify B4R project in this way and test again ?
#if C
//exemple for 4 fonts
#include <SystemFont5x7.h>
#include <Arial_black_16.h>
#include <Arial_Black_16_ISO_8859_1.h>
#include <Arial14.h>

const uint8_t * B4R::B4RDMD::myfonts[]= {
&System5x7[0], // => setfont(00)
&Arial_Black_16[0], // => setfont(01)
&Arial_Black_16_ISO_8859_1[0], // => setfont(02)
&Arial_14[0] // => setfont(03)
};
#End If


2) if still not working we can check a simple project first without font / text ùanagement (only pixel management) :
- please To test pixel by pixel modification first in a Loop To have hight each pixel And after low.
it is just to see if if an issue with SPI or with fonts
 
Upvote 0

thetrueman

Active Member
@candide I checked as you advised but still same situation. I guess the problem is with SPI because there is no display. At least there should be some display if SPI is working. One thing I had mentioned that I am using Arduino UNO board so I have commented the wifi connect routine and removed the esp8266 references to be on safe side of UNO board.
 
Upvote 0

candide

Active Member
Licensed User
i have no idea to solve this issue...

can you share arduino project working ?

can you share reference of your led panel ? where did you buy it ?
 
Upvote 0

thetrueman

Active Member
Here is all related files in zip format including P10 display datasheet and DMD Library and tested dmd_demo.ino project file.
Also there needed TimerOne library which I have included in zip file. BTW I have added its reference in rDMD.h by myself with no lucked. I hope you could solve this matter as now you will have all working files. Thanks for your efforts.
 

Attachments

  • ArduinoDMD.zip
    324.1 KB · Views: 18
Upvote 0

candide

Active Member
Licensed User
i think timer is not running because start is missing in B4R project.
can you modify in this way and check if
B4X:
    dmd.Initialize(dmd.DISPLAYS_ACROSS,dmd.DISPLAYS_DOWN)
    timer.Initialize("ScanDMD",5000)
    timer.Enabled = True   'missing
    '//clear/init the dmd pixels held in RAM
    dmd.clearScreen(1 )  '//True is normal (all pixels off), False is negative (all pixels on)

    AddLooper("myloop")
End Sub

Sub scanDMD
    Log("scanDMD run")
    dmd.scanDisplayBySPI
End Sub
 
Upvote 0

thetrueman

Active Member
Hi @candide thanks with good news... after some modification the display started to display the data. Here I details what I found during problem solving situation.

First of all the SPI was confirmed that it is working because after 22 seconds the timer fired and four rows (1, 5, 9, 13) of display switched on and then after 22 seconds four rows (2, 6, 10, 14) were on and then next four and next four were on after 22 seconds. This confirmed the proper function of SPI but the timer only fires when whole myloop returns to its start because there are many Delay commands which pauses the execution of program. This was the reason that timer interval had no effect even I changed it.

So I disabled the timer and added new looper AddLooper("scanSPI") with the command dmd.scanDisplayBySPI but this looper did not work. Then I placed this command dmd.scanDisplayBySPI after every new string display command but no luck but some random display. Here was an hint when I placed dmd.scanDisplayBySPI command in a Text Marquee routine which was being update after 30ms and the display started to scroll the text. It confirmed me that we have to fire dmd.scanDisplayBySPI command as fast as possible.

Now I added a Delay Sub with 1ms delay to avoid halting the program and replaced all standard delay commands to use Delay Sub and the whole display started working good except the dmd.drawChar(.....) routines. Please have a look at this problem.

In Arduino's dmd_demo.ino the following Timer Setup is 5000uS = 5mS which is interrupt based to update the SPI data and the main program does not halt even with delay commands. Here is a point that can we use callsubplus type command in B4R to avoid halting program even at 1ms?
-------------------------
void setup(void)
{
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 5000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
-------------------------

Now the problem is that we have to manage the interrupt in B4R to update the SPI data in background and should control the delays in such a way to use the Serial data to display instead of hard coded data to display. Also at next step we will use esp8266 to get data via WiFi to display live changes.

Thank you very much for your time and once the basic problems clear then please make neat and tidy rDMD. Here is my code (with modifications) which is working except dmd.drawChar(.....) routines. Also I have used and tested the original fonts code instead of your advise in post #13. (Original works so no need to play with it.)

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private timer As Timer
'    Private wifi As ESP8266WiFi
    Private dmd As DMD
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    'example of connecting to a local network
'    If wifi.Connect2("SSID", "PASSWORD") Then
'        Log("Connected to network")
'    Else
'        Log("Failed to connect to network")
'    End If
'    dmd.DISPLAYS_ACROSS = 1
'    dmd.DISPLAYS_DOWN = 1
    dmd.Initialize(dmd.DISPLAYS_ACROSS,dmd.DISPLAYS_DOWN)
    timer.Initialize("ScanDMD",100)
'    timer.Enabled = True
    '//clear/init the dmd pixels held in RAM
    dmd.clearScreen(1 )  '//True is normal (all pixels off), False is negative (all pixels on)

    AddLooper("myloop")
    AddLooper("scanSPI")
End Sub

Sub scanDMD
    Log("scanDMD run")
    dmd.scanDisplayBySPI
End Sub

Sub scanSPI
    Log("scanSPI")
    dmd.scanDisplayBySPI
End Sub

Sub DelayMS(TimeMS As Int)
    For t = 0 To TimeMS
        Delay (1)
        dmd.scanDisplayBySPI
    Next
End Sub


'/*--------------------------------------------------------------------------------------
'  Loop
'  Arduino architecture main Loop
'--------------------------------------------------------------------------------------*/
Sub myloop
    Dim b As Byte
  
   '// 10 x 14 font clock, including demo of Or And NOR modes For pixels so that the flashing colon can be overlayed
   dmd.clearScreen( 1 )
   dmd.selectFont(01)
    dmd.drawChar(  0,  3, "1", dmd.GRAPHICS_NORMAL ) ': scanDMD
    dmd.scanDisplayBySPI
    dmd.drawChar(  7,  3, "2", dmd.GRAPHICS_NORMAL ) ': scanDMD
    dmd.scanDisplayBySPI
    dmd.drawChar( 17,  3, "3", dmd.GRAPHICS_NORMAL ) ': scanDMD
    dmd.scanDisplayBySPI
    dmd.drawChar( 25,  3, "4", dmd.GRAPHICS_NORMAL ) ': scanDMD
    dmd.scanDisplayBySPI
    dmd.drawChar( 15,  3, ":", dmd.GRAPHICS_OR     ) ': scanDMD   '// clock colon overlay on
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
    dmd.drawChar( 15,  3, ":", dmd.GRAPHICS_NOR    ) ': scanDMD   '// clock colon overlay off
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
    dmd.drawChar( 15,  3, ":", dmd.GRAPHICS_OR     ) ': scanDMD   '// clock colon overlay on
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
    dmd.drawChar( 15,  3, ":", dmd.GRAPHICS_NOR    ) ': scanDMD   '// clock colon overlay off
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
    dmd.drawChar( 15,  3, ":", dmd.GRAPHICS_OR     ) ': scanDMD   '// clock colon overlay on
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )

   dmd.drawMarquee("HiLOGIX Technologies",20,(32*dmd.DISPLAYS_ACROSS)-1,0)
    dmd.scanDisplayBySPI
   Dim start As ULong =Millis()
   Dim time As ULong =start
   Dim ret As bool =False
   Do While Not(ret)
     If ((time+50) < Millis) Then
        ret=dmd.stepMarquee(-1,0)
        time=Millis
     End If 
        scanSPI
  Loop

   '// half the pixels on
   dmd.drawTestPattern( dmd.PATTERN_ALT_0 )
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )

   '// the other half on
   dmd.drawTestPattern( dmd.PATTERN_ALT_1 )
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
  
   '// display some text
   dmd.clearScreen( 1 )
   dmd.selectFont(00)
   For  x=0 To dmd.DISPLAYS_ACROSS-1 
      For y=0 To dmd.DISPLAYS_DOWN-1
       dmd.drawString(  2+(32*x),  1+(16*y), "freet", 5, dmd.GRAPHICS_NORMAL )
            dmd.scanDisplayBySPI
       dmd.drawString(  2+(32*x),  9+(16*y), "ronic", 5, dmd.GRAPHICS_NORMAL )
            dmd.scanDisplayBySPI
      Next
   Next
    DelayMS( 5000 )
  
   '// draw a border rectangle around the outside of the display
   dmd.clearScreen( 1 )
   dmd.drawBox(  0,  0, (32*dmd.DISPLAYS_ACROSS)-1, (16*dmd.DISPLAYS_DOWN)-1, dmd.GRAPHICS_NORMAL )
'    dmd.scanDisplayBySPI
    DelayMS( 1000 )
  
   For y=0 To dmd.DISPLAYS_DOWN-1
     For x=0 To dmd.DISPLAYS_ACROSS-1
       '// draw an X
       Dim ix As Int =32*x
       Dim iy As Int =16*y
       dmd.drawLine(  0+ix,  0+iy, 11+ix, 15+iy, dmd.GRAPHICS_NORMAL )
'            dmd.scanDisplayBySPI
       dmd.drawLine(  0+ix, 15+iy, 11+ix,  0+iy, dmd.GRAPHICS_NORMAL )
'            dmd.scanDisplayBySPI
            DelayMS( 1000 )
  
       '// draw a circle
       dmd.drawCircle( 16+ix,  8+iy,  5, dmd.GRAPHICS_NORMAL )
'            dmd.scanDisplayBySPI
            DelayMS( 1000 )
  
       '// draw a filled box
       dmd.drawFilledBox( 24+ix, 3+iy, 29+ix, 13+iy, dmd.GRAPHICS_NORMAL )
'            dmd.scanDisplayBySPI
            DelayMS( 1000 )
     Next
   Next

   '// stripe chaser
   Dim b_str As String
   For b = 0 To 20-1
         b_str = NumberFormat(Bit.And(b,1),0,0)
      dmd.drawTestPattern(b_str+dmd.PATTERN_STRIPE_0 )
'        dmd.scanDisplayBySPI
        DelayMS( 300 )
   Next
    DelayMS( 500 )
  
End Sub

#if C
//exemple for 4 fonts
  #include <SystemFont5x7.h>
  #include <Arial_black_16.h>
  #include <Arial_Black_16_ISO_8859_1.h>
  #include <Arial14.h>

  const uint8_t * B4R::B4RDMD::myfonts[]= {
      System5x7,                      // => setfont(00)
      Arial_Black_16,                 // => setfont(01)
      Arial_Black_16_ISO_8859_1,      // => setfont(02)
      Arial_14                       // => setfont(03)
  };
#End If
 
Upvote 0

candide

Active Member
Licensed User
ok, it seems better !

if you want interrupt each 5ms, lines are :
timer.Initialize("ScanDMD",5)
timer.Enabled = True

and you will have similar behavior in B4R
 
Upvote 0

thetrueman

Active Member
if you want interrupt each 5ms, lines are :
timer.Initialize("ScanDMD",5)
timer.Enabled = True

I have tried already as you advised above but it does not work. It seems it is standard timer which does not use interrupts because standard Delay command in B4R halts/pauses the program until the time interval in milliseconds is over. But in Arduino example, timer with interrupt works with delay commands. Can we have more than one loopers or software based listeners in B4R?

Please can you guess why dmd.drawChar(.....) did not work? Thanks.
 
Upvote 0
Top