B4R Question Adafruit RGB Led Matrix 64x32

demasi

Active Member
Licensed User
Longtime User
Hello,
I have this led panel https://www.adafruit.com/product/2279 connected to an Arduino Mega, and working well, in arduino's IDE.

It uses this 2 libraries:

#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

I want to use this panel with B4R. Looking at B4R forum I found Adafruit GFX. I think is the same. But I still need the other library RGBmatrixPanel.
I love VB,, and is far easier to program Arduino with B4R, is simple to use timers and everything else.

Is there a version of this lib for B4R? or is possible to include it via Native Code?
I saw somewhere in the forum it's possible to copy the library files to arduino libraries folder and use via Native Code. But I could not find this post again. I saw also that this approach is not ok for big libraries, it's better to write a wrapper. I still don't know to create wrappers.
I tried this, but something is going wrong.

Any help is welcome.
Thanks!

Edit: I found the post:
https://www.b4x.com/android/forum/threads/inline-c-c.65714/#content
I tried to include this way but something is missing.
 
Last edited:

demasi

Active Member
Licensed User
Longtime User
Thank you, Erel.
this is the code that came with the library. It works well with 64x32 boards with Arduino Mega.

B4X:
// testshapes demo for RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x64 RGB LED matrix.

// NOTE THIS CAN ONLY BE USED ON A MEGA! NOT ENOUGH RAM ON UNO!

#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library

#define OE   9
#define LAT 10
#define CLK 11
#define A   A0
#define B   A1
#define C   A2
#define D   A3

//Byte array of bitmap of 32 x 32 px:
  
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);

void setup() {

  matrix.begin();
  // draw a pixel in solid white
  matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
  delay(500);

  // fix the screen with green
  matrix.fillRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(0, 7, 0));
  delay(500);

  // draw a box in yellow
  matrix.drawRect(0, 0, matrix.width(), matrix.height(), matrix.Color333(7, 7, 0));
  delay(500);
  // draw an 'X' in red
  matrix.drawLine(0, 0, matrix.width()-1, matrix.height()-1, matrix.Color333(7, 0, 0));
  matrix.drawLine(matrix.width()-1, 0, 0, matrix.height()-1, matrix.Color333(7, 0, 0));
  delay(500);
  // draw a blue circle
  matrix.drawCircle(10, 10, 10, matrix.Color333(0, 0, 7));
  delay(500);
  // fill a violet circle
  matrix.fillCircle(40, 21, 10, matrix.Color333(7, 0, 7));
  delay(500);
  // fill the screen with 'black'
  matrix.fillScreen(matrix.Color333(0, 0, 0));
  // draw some text!
  matrix.setTextSize(1);     // size 1 == 8 pixels high
  matrix.setTextWrap(false); // Don't wrap at end of line - will do ourselves

  matrix.setCursor(8, 0);    // start at top left, with 8 pixel of spacing
  uint8_t w = 0;
  char *str = "AdafruitIndustries";
  for (w=0; w<8; w++) {
    matrix.setTextColor(Wheel(w));
    matrix.print(str[w]);
  }
  matrix.setCursor(2, 8);    // next line
  for (w=8; w<18; w++) {
    matrix.setTextColor(Wheel(w));
    matrix.print(str[w]);
  }
  matrix.println();
  //matrix.setTextColor(matrix.Color333(4,4,4));
  //matrix.println("Industries");
  matrix.setTextColor(matrix.Color333(7,7,7));
  matrix.println("LED MATRIX!");
  // print each letter with a rainbow color
  matrix.setTextColor(matrix.Color333(7,0,0));
  matrix.print('3');
  matrix.setTextColor(matrix.Color333(7,4,0));
  matrix.print('2');
  matrix.setTextColor(matrix.Color333(7,7,0));
  matrix.print('x');
  matrix.setTextColor(matrix.Color333(4,7,0));
  matrix.print('6');
  matrix.setTextColor(matrix.Color333(0,7,0)); 
  matrix.print('4');
  matrix.setCursor(34, 24); 
  matrix.setTextColor(matrix.Color333(0,7,7));
  matrix.print("*");
  matrix.setTextColor(matrix.Color333(0,4,7));
  matrix.print('R');
  matrix.setTextColor(matrix.Color333(0,0,7));
  matrix.print('G');
  matrix.setTextColor(matrix.Color333(4,0,7));
  matrix.print("B");
  matrix.setTextColor(matrix.Color333(7,0,4));
  matrix.println("*");


  // whew!
}

void loop() {
  // do nothing
}


// Input a value 0 to 24 to get a color value.
// The colours are a transition r - g - b - back to r.
uint16_t Wheel(byte WheelPos) {
  if(WheelPos < 8) {
   return matrix.Color333(7 - WheelPos, WheelPos, 0);
  } else if(WheelPos < 16) {
   WheelPos -= 8;
   return matrix.Color333(0, 7-WheelPos, WheelPos);
  } else {
   WheelPos -= 16;
   return matrix.Color333(0, WheelPos, 7 - WheelPos);
  }
}
]


I was trying to do something like your example, but my knowledge of C is still very basic. (basic??? :))

B4X:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("LedPanel", 0)
  
End Sub

#if C
#include <RGBmatrixPanel.h>
void Delay (B4R::Object* o) {

    RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);

    // matrix.begin(o->toULong());
      matrix.begin();
      // draw a pixel in solid white
      matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
}
#End if

congrats for this one great software. thank you for your support.
 
Last edited:
Upvote 0

demasi

Active Member
Licensed User
Longtime User
I tried all day and I can turn on some leds on the board.
The probem now is with the functions parameters. I don't know how to pass the parameters correctly.

this is my code:

B4X:
#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
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("begin", Null)
    RunNative("drawPixel", Null)
   
End Sub

#if C
#include <Adafruit_GFX.h>   // Core graphics library
#include <RGBmatrixPanel.h>
#define OE   9
#define LAT 10
#define CLK 11
#define A   A0
#define B   A1
#define C   A2
#define D   A3

//Byte array of bitmap of 32 x 32 px:
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);

void begin(B4R::Object* o) {
    matrix.begin();
}   

// draw a pixel in solid white
void drawPixel(B4R::Object* o) {  
  matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
  matrix.drawPixel(1, 0, matrix.Color333(2, 4, 7));
  matrix.drawPixel(2, 0, matrix.Color333(7, 3, 7));
  matrix.drawPixel(3, 0, matrix.Color333(7, 1, 7));
  matrix.drawPixel(4, 0, matrix.Color333(7, 5, 0));
  matrix.drawPixel(5, 0, matrix.Color333(7, 2, 7));
  matrix.drawPixel(6, 0, matrix.Color333(7, 5, 6));
}
#End if

this code turns on leds 0 to 6 on line in, in different colors.
I don't understand this parameters notation.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please try this code:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private matrix As RGBmatrixPanel
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   Dim p As Pin 'ignore
   matrix.Initialize32(p.A0, p.A1, p.A2, p.A3, 11, 10, 9, False, 64)
   matrix.FillScreen(matrix.Color333(7, 0, 0))
   matrix.GFX.DrawCircle(5, 5, 3, matrix.Color333(0, 0, 7), True)
   Log(matrix.GFX.Width, " x ", matrix.GFX.Height)
   matrix.UpdateDisplay 'not sure if required or not
End Sub

The beta library is attached.
You need to add a reference to rAdafruitRGBMatrix and rAdafruitGFX.
 

Attachments

  • rAdafruitRGBMatrix.zip
    12.9 KB · Views: 424
Upvote 0

demasi

Active Member
Licensed User
Longtime User
Thank you. I tried, but the library does not appear in the libs tab. Maybe because the xml file is missing?
 
Upvote 0

demasi

Active Member
Licensed User
Longtime User
I am at work now. When I go back home I will try the library. Thank you.
This project will be used in a school´s science fair is some days. Then, it will be used in a food bike at a regional june party, to display messages and images, and advertising, to atract people.
My project will use bluetooth, SD card to store messages and images (I will use your suggestion to convert bitmaps to code), the led panel, some relays, and an B4A app to control this and, of course, :) control some lights. A rotating led light will be installed and controled by the app, for demonstration purposes.
I don´t know if I can do this in time, but my idea is to build an app and store in the school network, for all people install it and the can change the messages displayed, the effects, pictures, etc. And turn on/off the lights. Technology is very fun. I think I have the knowledge and can do this, with B4A and B4R and the help I receive in this comunnity.
After this events, I will try to change the project to be a spectrum analyzer, a bargraph reacting to sound, and put in my room. :) I will use an ADC I have to capture the sound and a routine that uses Fourier calculations to divide by frequencies, using Arduino Mega.
If possible, I will post pictures, wiring and the code of these projects here.
Thank you again.
 
Upvote 0

demasi

Active Member
Licensed User
Longtime User
It worked! Thank you!
 

Attachments

  • 20170629_121111 (4).jpg
    20170629_121111 (4).jpg
    92.2 KB · Views: 1,661
Upvote 0

demasi

Active Member
Licensed User
Longtime User
I was looking at Erel's library code, and I could successfully include a method, the DrawPixel.
I did this manually, looking at the code and changing apropriately.
Now I want to include all methods from GFX library and RGB Matrix.
My question: is there some tool to help this job, or it have to be made as I did, manually, one by one.
Looking for the XML file, it seemed to me that at least it was generated by an automatic tool.
Thank you.
 
Upvote 0
Top