marcmerlin / SmartMatrix_GFX

SmartMatrix::GFX: Allow using Adafruit::GFX as well as FastLED_NeoMatrix code with SmartMatrix backend,
GNU General Public License v3.0
80 stars 11 forks source link

Simple code lights up the whole display #2

Closed GeorgeFlorian closed 5 years ago

GeorgeFlorian commented 5 years ago

Hello !

I've tried a simple code:

#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <SmartMatrix_GFX.h>
#include <SmartMatrix3.h>

#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <SmartMatrix_GFX.h>
#include <SmartMatrix3.h>

// ========================== CONFIG START ===================================================

/// SmartMatrix Defines
#define COLOR_DEPTH 24                  // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
#define kMatrixWidth  64       // known working: 32, 64, 96, 128
#define kMatrixHeight 32       // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 24;       // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 2;       // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_64COL_MOD8SCAN_L540_2727;   // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
//const uint8_t kPanelType = SMARTMATRIX_HUB75_64ROW_MOD32SCAN;
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE);      // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrixLayer, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

// const int defaultBrightness = (100*255)/100;        // full (100%) brightness
const int defaultBrightness = (15*255)/100;       // dim: 15% brightness

#define mw kMatrixWidth
#define mh kMatrixHeight
#define NUMMATRIX (kMatrixWidth*kMatrixHeight)

CRGB leds[kMatrixWidth*kMatrixHeight];

// Sadly this callback function must be copied around with this init code
void show_callback() {
    for (uint16_t y=0; y<kMatrixHeight; y++) {
    for (uint16_t x=0; x<kMatrixWidth; x++) {
        CRGB led = leds[x + kMatrixWidth*y];
        // rgb24 defined in MatrixComnon.h
        backgroundLayer.drawPixel(x, y, { led.r, led.g, led.b } );
    }
    }
    // This should be zero copy
    // that said, copy or no copy is about the same speed in the end.
    backgroundLayer.swapBuffers(false);
}

SmartMatrix_GFX *matrix = new SmartMatrix_GFX(leds, mw, mh, show_callback);

// ========================== CONFIG END ======================================================

uint16_t myWHITE = matrix->Color(255,255,255);
uint16_t myRED =  matrix->Color(255, 0, 0);
uint16_t myGREEN =  matrix->Color(0, 255, 0);
uint16_t myBLUE =  matrix->Color(0, 0, 255);
uint16_t myYELLOW =  matrix->Color(255, 255, 0);
uint16_t myCYAN =  matrix->Color(0, 255, 255);
uint16_t myMAGENTA =  matrix->Color(255, 0, 255);
uint16_t myBLACK =  matrix->Color(0, 0, 0);

void go_right(unsigned int space){
  matrix->clear();
  matrix->setTextWrap(false);
  matrix->setRotation(0);
  matrix->setTextColor(myGREEN);
  matrix->setCursor(5,5); //- cursor for 1 digit number
  matrix->setTextSize(3);
  if(space == 0) {
    matrix->setTextColor(myRED);
  } else if(space >9) {
    matrix->setCursor(5,5); //- cursor for 2 digits number
  } 
  matrix->print(space);  
  matrix->drawTriangle(41,5,41,25,58,15,myWHITE);
  matrix->fillTriangle(41,5,41,25,58,15,myWHITE);
}

void setup() {
  matrixLayer.addLayer(&backgroundLayer); 
  matrixLayer.begin();
  matrixLayer.setBrightness(defaultBrightness);
  matrixLayer.setRefreshRate(240);
  backgroundLayer.enableColorCorrection(true);

  // Time for serial port to work?
  delay(1000);
  backgroundLayer.fillScreen( {0x80, 0x80, 0x80} );
  backgroundLayer.swapBuffers();

  Serial.begin(115200);
  Serial.print("Matrix Size: ");
  Serial.print(mw);
  Serial.print(" ");
  Serial.println(mh);
  matrix->begin();
  matrix->setTextWrap(false);
  Serial.println("If the code crashes here, decrease the brightness or turn off the all white display below");
  // matrix->
  go_right(10);
  delay(1000);
}

void loop() {

}

But it lights up the whole display in white.

I am sorry to bother you but I have no experience using this. I've defined my own scan pattern kPanelType = SMARTMATRIX_HUB75_32ROW_64COL_MOD8SCAN_L540_2727 and made FastLED_Functions example work.

marcmerlin commented 5 years ago

I'd have to look at how triangle is supposed to work, I've never used it, but is there a chance your coordinates are wrong? Are you still having the problem if you draw a rectangle instead?

marcmerlin commented 5 years ago

I had a look at

void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);

an it seems that your example should work but maybe the coordinates are wrong somehow. For one, remove the filltriangle and use the drawtriangle to check the difference

GeorgeFlorian commented 5 years ago

I had a look at

void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);

an it seems that your example should work but maybe the coordinates are wrong somehow. For one, remove the filltriangle and use the drawtriangle to check the difference

As I said on SmartMatrix's forum, not the coordinates are the problem, because changing them did nothing.

This is the color defintion:

uint16_t myWHITE = matrix->Color(255,255,255);
uint16_t myRED =  matrix->Color(255, 0, 0);
uint16_t myGREEN =  matrix->Color(0, 255, 0);

This is the method called in void setup() to print a number and a triangle:

void go_right(unsigned int space){
  matrix->clear();
  matrix->setTextWrap(false);
  matrix->setRotation(0);
  matrix->setTextColor(myGREEN);
  matrix->setCursor(5,5); //- cursor for 1 digit number
  matrix->setTextSize(2);
  if(space == 0) {
    matrix->setTextColor(myRED);
  } else if(space >9) {
    matrix->setCursor(5,5); //- cursor for 2 digits number
  } 
  matrix->print(space);  
  matrix->drawTriangle(41,5,41,25,58,15,myWHITE);
  matrix->fillTriangle(41,5,41,25,58,15,myWHITE);
  // backgroundLayer.swapBuffers();
  // delay(5000);
}

The problem is that it doesn't print the number either. It's not just about the triangle.

So matrix->print(space); , where unsigned int space = 10, does nothing. The same goes with matrix->drawTriangle(41,5,41,25,58,15,myWHITE); and matrix->fillTriangle(41,5,41,25,58,15,myWHITE);

marcmerlin commented 5 years ago

Ok, I think I see a problem. adafruit::gfx takes a 16bit 565 color for historical reasons. Give it a color of 0x0300 and see if that works

Then look in the lib for setpassthroughcolor (from memory) to pass a 24 bit color instead

marcmerlin commented 5 years ago

See also https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/blob/7de4be717269ca0f7ce50a6a6490fa9450e804b0/GFX/fontzoom/fontzoom.ino#L19

GeorgeFlorian commented 5 years ago

Give it a color of 0x0300 and see if that works

Ok. I've changed the colors:

  matrix->setTextColor(0x0300);
  matrix->drawTriangle(41,5,41,25,58,15,0x0300);
  matrix->fillTriangle(41,5,41,25,58,15,0x0300);

It still doesn't work.

marcmerlin commented 5 years ago

Ok, honestly I can't debug your code remotely. Also, given the turnaround time and the fact that you're asking for my time to help you, you really have to do better than "it doesn't work". Is it blank? Wrong color? other? (see http://www.catb.org/~esr/faqs/smart-questions.html for general tips. Yes, it's long, but it's full of good tips if you ask others for help). More generally you have to do more work on your side to explain why it's a problem on my side or at least in the documentation.

You said my code works, my code does draw rectangles and works for you. Take my code, change it to draw triangles instead. Once that's working, morph my code into what you're trying to do with your code and eventually you'll get there. If something is wrong/broken with my published code, do let me know and I'll try to fix it, but I can't help you write or debug your code, especially remotely and apparently in totally different timezones. I'll close this but if you find something wrong in the lib or the example I provide, or the documentation, feel free to reopen and I'll look at what can be improved. Good luck with your project.

GeorgeFlorian commented 5 years ago

Ok, honestly I can't debug your code remotely. Also, given the turnaround time and the fact that you're asking for my time to help you, you really have to do better than "it doesn't work". Is it blank? Wrong color? other? (see http://www.catb.org/~esr/faqs/smart-questions.html for general tips. Yes, it's long, but it's full of good tips if you ask others for help). More generally you have to do more work on your side to explain why it's a problem on my side or at least in the documentation.

You said my code works, my code does draw rectangles and works for you. Take my code, change it to draw triangles instead. Once that's working, morph my code into what you're trying to do with your code and eventually you'll get there. If something is wrong/broken with my published code, do let me know and I'll try to fix it, but I can't help you write or debug your code, especially remotely and apparently in totally different timezones. I'll close this but if you find something wrong in the lib or the example I provide, or the documentation, feel free to reopen and I'll look at what can be improved. Good luck with your project.

I understand that and I am sorry if I bothered you. We are an estimate of 8 hours apart. I'm beginning to get a little obsessed with this project. I've been trying to finish it for the last month and I have little patience to spare. You are perfectly right and I will try to make it work. Thank you for all your time and help !

GeorgeFlorian commented 5 years ago

As a little after-the-holidays update: we forgot to use matrix->show();. Adding this to the code made it work.