Go Down

Topic: LED matrix display - MD_Parola, MD_MAX72xx and MD_MAXPanel (Read 570962 times) previous topic - next topic

Ysayyed

Hi marco,

I made a small program to display txt using sd card module. Look I have make sincere efforts to do the job but I am still not getting the results. Please help me with this codes.

Code: [Select]


#include<SPI.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SD.h>
#include "Fonts.h"
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

//************************************//
#define  MAX_DEVICES_DISPLAY 8
#define MAX_ZONES_DISPLAY 2
#define DZ0 0
#define DZ1 1

#define CS_PIN_DISPLAY    29
#define CLK_PIN   52
#define DATA_PIN  51
#define CS_SD 53

MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN_DISPLAY, MAX_DEVICES_DISPLAY);
int     eng_msg=1; // int def of eng_msg set to 1
char    Eng_Buf[20]="";
String  Rand_FileName="";
String  English_Msg="";
File    fp_Rand_File;

void setup() {
    Serial.begin(9600);
    Display.begin(MAX_ZONES_DISPLAY);   
    Display.setIntensity(0);
    Display.setZone(DZ0, 0, 3);
    Display.setZone(DZ1, 4, 7);
    Display.setFont(DZ0, BigFontLower);
    Display.setFont(DZ1, BigFontUpper );
    if (!SD.begin(CS_SD)) {
    Serial.println("SD Initialization failed!");
    return;
    }
    else
    {
    Serial.println("SD Initialization Success\n");
    }
    Display_Msg_From_SD();
}

void loop() {
    Display_Custom_Msg_English(Eng_Buf);
}

void Display_Custom_Msg_English(char* Buf)
{
     
      if (Display.getZoneStatus(DZ0) && Display.getZoneStatus(DZ1) )
      {
          if((eng_msg == 1))
          {
              Display.displayZoneText(DZ0,Buf, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
              Display.displayZoneText(DZ1,Buf, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
          }
         
      }
     
      Display.displayAnimate();
      Display.synchZoneStart();
 
           
}

void Display_Msg_From_SD()
{
    Rand_FileName = "1.txt";
    Serial.print(Rand_FileName);
   
    fp_Rand_File = SD.open(Rand_FileName);

    if(fp_Rand_File)
         Serial.println("Success opening :"+ Rand_FileName);
    else
    {
         Serial.println("error opening :"+ Rand_FileName);
         while(1);
    }
    int Eng_Chars2Read = 0;
    char char_read =0;
    English_Msg="";
    Serial.println(fp_Rand_File.available());
    for(;fp_Rand_File.available();)
    {
         //Complete Reading English Message
         for(;;)
         {
             char_read = fp_Rand_File.read();
             if((char_read != ',') && ( char_read != '.'))
             {
                  English_Msg += char_read;
                  Eng_Chars2Read++;
                  continue;
             }
             else if (char_read == ',')
                  continue;
             else if (char_read == '.')
                  break;
             else
                  break;
          }

    English_Msg.toCharArray(Eng_Buf,Eng_Chars2Read+1);
    Display_Custom_Msg_English(Eng_Buf);
}
}


marco_c

When you describe a problem, you should be specific about what your issue is. For example, if you take a car into a mechanic, you don't say 'there is something wrong' and walk away, you usually have to say that there is 'a noise in the front near the wheel, etc', so that the mechanic knows where to look. 'I am not getting results' gives me no clue as to where you think this code is not doing what it is supposed to be doing.

* Display.synchZoneStart() only needs to be done once when you set up the message. If you do it every time through the loop I am not sure that you will even get a message as you probably mess up the animation timers. (I have not tried this).
* I would avoid using String as this is unreliable when there is only a small amount of memory. Use arrays of characters instead.
* This code
Code: [Select]
             else if (char_read == ',')
                  continue;
             else if (char_read == '.')
                  break;
             else
                  break;

makes no sense to me. If the character is anything except a ',' it will break out of the loop, so write
Code: [Select]
if (char_read != ',')
  break;

* Where do you set end_mesg to 1 so that it will update when the current animation is finished? An you should probably initialise it to 0 as well, and reset it when you have used the new string. This variable looks like it is supposed to be a handshake signal between the main loop and the string reading code, but it is incorrectly implemented.

Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Ysayyed

Sorry to say but I am not perfect in coding, can you please help me in just two things with following example of message from sd in MD_MAX72XX library;
First is how to set two zones & two fonts for different zones in this library as we set in MD_Parola.h,
Second how to set extent of zones e.g. (ZoneLower, 0, 7) etc.

I have tried lots of time to set zone and font in this example but only one zone & font i was hardly able to set.

Code: [Select]

// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// Text to be displayed is stored n an SD card. Each line is scrolled
// continuously on the display and run off before the next one is shown.
// At end of file the display loops back to the first line.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
//
// SD library used is SDFat found at https://github.com/greiman/SdFat
// Note that there is a high chance that pin definitions will clash between the SPI for
// MD_MAX72xx and the SD card. Beware!

#include <MD_MAX72xx.h>
#include <SPI.h>
#include <SdFat.h>

#define USE_POT_CONTROL 0

#define PRINT_CALLBACK  0
#define DEBUG 0

#if DEBUG
#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }
#define PRINTS(s)   Serial.print(F(s))
#else
#define PRINT(s, v)
#define PRINTS(s)
#endif

// ** MD_MAX72xx hardware definitions
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define CLK_PIN   6  // or SCK
#define DATA_PIN  7  // or MOSI
#define CS_PIN    8  // or SS or LD

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8

MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// ** SDFat hardware definitions
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
// MOSI - pin 11
// MISO - pin 12
// CLK - pin 13
// CS - pin 10
const char fName[] = "MESSAGE.TXT";
const uint8_t chipSelect = 10;
SdFat sd;
SdFile myFile;

// Scrolling parameters
#if USE_POT_CONTROL
#define SPEED_IN  A5
#else
#define SCROLL_DELAY  75  // in milliseconds
#endif // USE_POT_CONTROL

#define CHAR_SPACING  1 // pixels between characters

// Global data
uint16_t  scrollDelay;  // in milliseconds

int readFile(void)
// Return the next character from the file or a -1 if eof.
// End of line is marked by a '\n' returned to the caller, '\r' is skipped.
{
  int c = '\0';

  if (!myFile.isOpen())
  {
    PRINT("\nOpening ", fName);
    // open the file for read
    if (!myFile.open(fName, O_READ))
      sd.errorHalt("Cannot open file for read");
    PRINTS("- open\n");
  }

  do
    c = myFile.read();
  while (c == '\r');

  if (c == -1) // end of file or error
  {
    PRINTS("\nRewind\n");
    myFile.rewind();
  }

  return(c);
}

void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col)
// Callback function for data that is being scrolled off the display
{
#if PRINT_CALLBACK
  Serial.print("\n cb ");
  Serial.print(dev);
  Serial.print(' ');
  Serial.print(t);
  Serial.print(' ');
  Serial.println(col);
#endif
}

uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
// Callback function for data that is required for scrolling into the display
{
  static uint8_t  state = 0;
  static uint8_t  curLen, showLen;
  static uint8_t  cBuf[8];
  int c;
  uint8_t colData = 0;

  // finite state machine to control what we do on the callback
  switch(state)
  {
    case 0: // Load the next character from the font table
      // if we reached end of message, reset the message pointer
      c = readFile();
      if ((c == -1) || (c == '\n')) // end of file/error or end of line
      {
        state = 2;
        break;
      }

      PRINT("", (char)c);
      showLen = mx.getChar(c, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
      curLen = 0;
      state++;
      // !! deliberately fall through to next state to start displaying

    case 1: // display the next part of the character
      colData = cBuf[curLen++];
      if (curLen == showLen)
      {
        showLen = CHAR_SPACING;
        curLen = 0;
        state = 3;
      }
      break;

    case 2: // scroll off the whole display
      PRINTS("\n-> CLEAR\n");
      showLen = mx.getColumnCount();
      curLen = 0;
      state = 3;
      break;

    case 3: // display inter-character spacing (blank column)
      colData = 0;
      curLen++;
      if (curLen == showLen)
        state = 0;
      break;

    default:
      state = 0;
  }

  return(colData);
}

 void scrollText(void)
{
  static uint32_t prevTime = 0;

  // Is it time to scroll the text?
  if (millis()-prevTime >= scrollDelay)
  {
    mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data
    prevTime = millis(); // starting point for next time
  }
}

uint16_t getScrollDelay(void)
{
#if USE_POT_CONTROL
  uint16_t t;

  t = analogRead(SPEED_IN);
  t = map(t, 0, 1023, 25, 250);

  return(t);
#else
  return(SCROLL_DELAY);
#endif
}

void setup()
{
#if DEBUG
  Serial.begin(57600);
#endif

  // Initialize SdFat or print a detailed error message and halt
  // Use half speed like the native library, change to SPI_FULL_SPEED for more performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED))
    sd.initErrorHalt();

  // Initialize MD_MAX72xx library with callbacks
  mx.begin();
  mx.setShiftDataInCallback(scrollDataSource);
  mx.setShiftDataOutCallback(scrollDataSink);

  // if we are using POT control, get that going too
#if USE_POT_CONTROL
  pinMode(SPEED_IN, INPUT);
#else
  scrollDelay = SCROLL_DELAY;
#endif
}

void loop()
{
  scrollDelay = getScrollDelay();
  scrollText();
}


marco_c

Zones and zone management are not available in the MD_MAX72xx library. These are implemented in the Parola library. The Parola library has many examples that use multiple zones/fonts so please look at those and read the  documentation for clarification of other options.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

crfx

Hello,
i have made my own LED matrix display with MAX7219 and want to use Parola for animations and Text. My Problem is now that no of the 4 Hardware types seems to fit my Display. Its wired like here: https://majicdesigns.github.io/MD_MAX72XX/Circuit_Schematic.jpg
But if i use PAROLA_HW, everything is tilted by 90 degrees, like with all hardware types except GENERIC_HW, but with generic the text is mirrored. I only would have to reverse the rows, and read something about the row mapping here: https://github.com/MajicDesigns/MD_MAX72XX/blob/master/src/MD_MAX72xx_lib.h

but how do i use this in my or in the example sketch to reverse the mapping of the rows?

marco_c

1. The data in side should be on the right, not the left the way most people naturally put it. This is really important.
2. You can set up your own profile. Run the HW_Mapping example for MD_MAX72xx and follow the instructions. It will suggest the profile to use.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

crfx

yes my data in side is on the right side

I already tried to use the hw mapper, but nothing happens on the matrix and the serial monitor only prints some lines of random stuff like 4f,⸮)\)J⸮0Щ⸮i⸮`oK⸮%⸮:⸮ƎZcJ⸮XA;O⸮N9AH⸮⸮yn⸮Raʫ⸮G⸮⸮h⸮

The clk, din and cs pins are wired correctly, do i have to change something else to make it work?

marco_c

Try setting the serial monitor bits per second to the same value as in the sketch.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

crfx

Thank you very much that maked the mapper work :)

but the result was

HW_DIG_ROWS   0
HW_REV_COLS   1
HW_REV_ROWS   1

Your hardware matches the setting for none of the preconfigured module types.
You should try rotating the matrix by 180 degrees and re-running this utility.

If that still fails to provide a solution - congratulations! You have discovered
a new type of hardware module! Please contact the author of the libraries so that
these can be included in the next official release.

so I guess i have to rearrange the matrices for my display until it fits one of the 4 existing hardware types :|

marco_c

No, you can set up your own profile. I just can't guarantee that it will work as I have not tested it.

Pick one of the existing types that you will edit. I assume here it will be GENERIC.

In MD_MAX72xx.cpp library file edit the setModuleParameters() method for GENERIC. I would duplicate the case for GENERIC it and comment one of them out so you can go back to 'standard' if needed. The _hw* variable are named the same as the #defines from hwmapper. Where hwmapper says 0, set false, 1 set true.

Save the file it and running one of the example sketches with module type set to GENERIC.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

crfx

Ok i tried that, but it looks like it uses only the first column of the matrix then

malekhosseini

Hi marco
MD_parola is a great work. I used it and enjoyed. please guide me how can I cancel a running animation immediately.

malekhosseini

marco_c

displayReset() or just start the next animation.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Ryme_Extrinseca

Hello,

May I ask what is happening in this section of code in the Parola_CustomChars.ino? . . .


Code: [Select]
uint8_t degC[] = { 6, 3, 3, 56, 68, 68, 68 }; // Deg C
uint8_t degF[] = { 6, 3, 3, 124, 20, 20, 4 }; // Deg F


Thank you for your guidance.

M.

marco_c

These lines define the bitmap for a character. Same format as the font file.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

Go Up