Flip maxmatrix LED 8x8 matrix output

HI,
I would like to flip the output of the maxmatrix.h library by 180degrees.

Currently it scrolls text from right to left with the DIN/VCC ports towards the bottom. I would like the ports at the top since planning to build a wearable. I am using one of the 8x8led boards as in image attached.

#include <MaxMatrix.h>
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>
PROGMEM const unsigned char CH[] = {
  3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
};
int dIn = 7;   // DIN pin of MAX7219 module
int clk = 6;   // CLK pin of MAX7219 module
int cs = 5;    // CS pin of MAX7219 module
int maxInUse = 2;    // Number of MAX7219's connected
MaxMatrix m(dIn, cs, clk, maxInUse);
SoftwareSerial Bluetooth(10, 11);  // RX | TX
byte buffer[10];
char incomebyte;
int scrollSpeed = 100;
char text[100] = "TEST MESSAGE  "; // Initial text message
int brightness = 1;
int count = 0;
char indicator;
void setup() {
  m.init(); // MAX7219 initialization
  m.setIntensity(brightness); // initial led matrix intensity, 0-15
 // Serial.begin(9600);
  Bluetooth.begin(9600); // Default communication rate of the Bluetooth module
  Serial.println("The bluetooth gates are open.\n Connect to HC-05 from any other bluetooth device with 1234 as pairing key!.");
 
}
void loop() {
  // Printing the text
  printStringWithShift(text, scrollSpeed);
  
  if (Bluetooth.available()) {   // Checks whether data is comming from the serial port
    indicator = Bluetooth.read(); 

    // Starts reading the serial port, the first byte from the incoming data
    // If we have pressed the "Send" button from the Android App, clear the previous text
    if (indicator == '1') {
      for (int i = 0; i < 100; i++) {
        text[i] = 0;
        m.clear();
      }
      // Read the whole data/string comming from the phone and put it into text[] array.
      while (Bluetooth.available()) {
        incomebyte = Bluetooth.read();
        text[count] = incomebyte;
        count++;
      }
      count = 0;
    }
    // Adjusting the Scrolling Speed
    else if (indicator == '2') {
      String sS = Bluetooth.readString();
      scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
    }
    // Adjusting the brightness
    else if (indicator == '3') {
      String sB = Bluetooth.readString();
      brightness = sB.toInt();
      m.setIntensity(brightness);
    }
  }
}
void printCharWithShift(char c, int shift_speed) {
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7 * c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + buffer[0], 0);
  for (int i = 0; i < buffer[0] + 1; i++)
  {
    delay(shift_speed);
    m.shiftLeft(false, false);
  }
}
void printStringWithShift(char* s, int shift_speed) {
  while (*s != 0) {
    printCharWithShift(*s, shift_speed);
    s++;
  }
}
void printString(char* s)
{
  int col = 0;
  while (*s != 0)
  {
    if (*s < 32) continue;
    char c = *s - 32;
    memcpy_P(buffer, CH + 7 * c, 7);
    m.writeSprite(col, 0, buffer);
    m.setColumn(col + buffer[0], 0);
    col += buffer[0] + 1;
    s++;
  }
}

If I use the MD_MAX72xx library, I can define which type of led matrix I am using and also transform the text using (TSR/TSL etc) so its displayed correctly, but I am unable to figure out how to add bluetooth app controls. The attached examples in the library don't work and output a blank screen.

Can anyone help either way?

41ByzXf3MLL.jpg

I am unable to figure out how to add bluetooth app controls.

what arduino do you have?

what BT do you have? how is it connected / paired / powered / configured ?

to transform the text, you just need to redraw the characters in the right way

this is A for example:

  4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A

can you see it?

0[color=red]111111[/color]0
000[color=red]1[/color]000[color=red]1[/color]
000[color=red]1[/color]000[color=red]1[/color]
0[color=red]111111[/color]0
00000000

you need to put the 1 and 0 the way you want to display

If I use the MD_MAX72xx library, I can define which type of led matrix I am using and also transform the text using (TSR/TSL etc) so its displayed correctly, but I am unable to figure out how to add bluetooth app controls. The attached examples in the library don't work and output a blank screen.

Which examples don't work?

Daft_punk and Message_serial both don't work. The Led remains blank. I have changed the pin inputs correctly.

The following code does though and displayed the right way!

I would like to add an android app connected to bluetooth (HC05) through which I can send text + change speed/brightness of the led's.

Next would be an 8x8 grid on the android app itself through which I can make custom shapes and send to the library to display on the matrix. I can just tap which leds to light up on the 8x8grid on app and the corresponding led would light up.

#include <MD_MAX72xx.h>
#define     MAX_DEVICES   1 
 
#define     CLK_PIN      6  
#define     DATA_PIN     7  
#define     CS_PIN       5  
 
MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);  
  
#define SCROLL_DELAY     200
 
#define     CHAR_SPACING     1  
#define     BUF_SIZE     75  
char curMessage[BUF_SIZE];  
char newMessage[BUF_SIZE];  
   
uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)  
{  
  static char        *p = curMessage;  
  static uint8_t     state = 0;  
  static uint8_t     curLen, showLen;  
  static uint8_t     cBuf[8];  
  uint8_t colData;  
  
  switch(state)  
  {  
  case 0:  
    showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);  
    curLen = 0;  
    state++;  
    
    if (*p == '\0')  
    {  
      p = curMessage;  
    }  
  case 1:       
    colData = cBuf[curLen++];  
    
    if (curLen == showLen)  
    {  
      showLen = CHAR_SPACING;  
      curLen = 0;  
      state = 2;  
    }  
    
    break;  
  case 2:  
    colData = 0;  
    curLen++;  
 
    if (curLen == showLen)  
     state = 0;  
    
    break;  
    default:  
    state = 0;  
  }  
  return(colData);  
}  
  
void scrollText(void)  
{  
  static uint32_t     prevTime = 0;  
  if (millis()-prevTime >= SCROLL_DELAY)  
  {  
    mx.transform(MD_MAX72XX::TSL);       
    prevTime = millis();  
  }  
}  

void setup()  
{  
  mx.begin();  
  mx.setShiftDataInCallback(scrollDataSource);  
  mx.control(MD_MAX72XX::INTENSITY, 1);
  strcpy(curMessage, "Test MESSAGE");
 
  newMessage[0] = '\0';  
}  
   
void loop()   
{  
  scrollText();  
}

I would like to add an android app connected to bluetooth (HC05) through which I can send text + change speed/brightness of the led's.

Next would be an 8x8 grid on the android app itself through which I can make custom shapes and send to the library to display on the matrix. I can just tap which leds to light up on the 8x8grid on app and the corresponding led would light up.

why don't do start simple - write a program without LEDs or whatever that hooks up your android phone and your arduino and displays some commands sent from the phone in the Serial Console

Once you've got that working you'll be able to start expanding

Daft_punk and Message_serial both don't work.

This is surprising as many others have got these to work. Please make sure that you have the most recent version (libraries link in my signature).

I would like to add an android app connected to bluetooth (HC05) through which I can send text + change speed/brightness of the led's.

Look at the MD_Parola library as it will probably be better for your application. It also has a Bluetooth example for App Inventor 2 that you can use that does pretty much what you are asking for.

J-M-L:
what arduino do you have?

what BT do you have? how is it connected / paired / powered / configured ?
y
to transform the text, you just need to redraw the characters in the right way

this is A for example:

  4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A

can you see it?

0[color=red]111111[/color]0

00010001
00010001
01111110
00000000




you need to put the 1 and 0 the way you want to display

HC05 bluetooth with Arduino Mega 2560. Thanks for the explanation...that leaves the scrolling issue but I'll try one of the built in shift functions.

marco_c:
This is surprising as many others have got these to work. Please make sure that you have the most recent version (libraries link in my signature).
Look at the MD_Parola library as it will probably be better for your application. It also has a Bluetooth example for App Inventor 2 that you can use that does pretty much what you are asking for.

Isn't the Md_parola library more suitable for text animations? I want the 8x8 grid and line display/animations primarily.
I have the latest version of your library. Unable to figure out why the examples don't work whereas the one I posted, using your library does.

Daft_punk has animations and message_serial can be used to build serial monitor as base for bluetooth, if only they would work!

Nonetheless, the BT example for Parola has all the code you need for the Android App and the Arduino. This should be relatively easy to move over to MD_MAX72xx territory.

Unable to figure out why the examples don't work whereas the one I posted, using your library does.

Hard to say. If the hardware setup works for one example, it should work for all examples.

J-M-L:
why don't do start simple - write a program without LEDs or whatever that hooks up your android phone and your arduino and displays some commands sent from the phone in the Serial Console

Once you've got that working you'll be able to start expanding

J-M-L:
why don't do start simple - write a program without LEDs or whatever that hooks up your android phone and your arduino and displays some commands sent from the phone in the Serial Console

Once you've got that working you'll be able to start expanding

I've got it all configured using the Maxmatrix libary. Just need to get it working with your library as yours seems more flexible and powerful.

why don't do start simple - write a program without LEDs or whatever that hooks up your android phone and your Arduino and displays some commands sent from the phone in the Serial Console

I think the point of this from J-M-L is to make sure your BT is configured correctly. If nothing shows on the console, then it is not.

marco_c:
Nonetheless, the BT example for Parola has all the code you need for the Android App and the Arduino. This should be relatively easy to move over to MD_MAX72xx territory.
Hard to say. If the hardware setup works for one example, it should work for all examples.

Hmmm...will try it out.
Can you tell me how I can control individual leds' using an android app? For eg is the following is selected on an 8x8 matrix on the app(0= selected x= not selected), then pressing send should light up corresponding led on the ledmatrix. Unable to figure it out.

xxxxxxxx
xxxxxxxx
x00xx00x
x00xx00x
xxxxxxxx
x00xxx00
xx00000x
xxxxxxxx

You need to work out how to tell the Arduino that you want to do a column or an individual bit of the display (eg, coordinates) and put it on or off. This will be a message. Then you make the message and you send it to the Arduino, which unpacks the message and does what it is supposed to do.

As I have already said, I strongly advise you to look at the Parola example (or another relevant BT example), understand how it works, then use the same type of technique in your own code.

marco_c:
I think the point of this from J-M-L is to make sure your BT is configured correctly. If nothing shows on the console, then it is not.

marco_c:
I think the point of this from J-M-L is to make sure your BT is configured correctly. If nothing shows on the console, then it is not.

yeah...i'll do that. Thanks for the advice J-M-L!

marco_c:
You need to work out how to tell the Arduino that you want to do a column or an individual bit of the display (eg, coordinates) and put it on or off. This will be a message. Then you make the message and you send it to the Arduino, which unpacks the message and does what it is supposed to do.

As I have already said, I strongly advise you to look at the Parola example (or another relevant BT example), understand how it works, then use the same type of technique in your own code.

I will definitely try the parola library!

Can you help me with a code which would individually control the 8 leds in a column or row?
Thanks

Not until you have tried it first and can show us your code. You really need to carefully think about what you want to do, as it involves 2 systems and communications. This is definitely not beginners code.

If you are new, I would suggest using smaller programs to prove concepts to yourself. Start by trying to turn on a LED by sending a message from the Serial Monitor, understand what it takes, etc, then build up your skill set from there.

marco_c:
Not until you have tried it first and can show us your code. You really need to carefully think about what you want to do, as it involves 2 systems and communications. This is definitely not beginners code.

If you are new, I would suggest using smaller programs to prove concepts to yourself. Start by trying to turn on a LED by sending a message from the Serial Monitor, understand what it takes, etc, then build up your skill set from there.

Sure! Will get back incase I get stuck

The Parola library simply doesn't work even with the most basic example. The code uploads but LED matrix is blank.

// Program to demonstrate the MD_Parola library
//
// Simplest program that does something useful - Hello World!
//
// NOTE: MD_MAX72xx library must be installed and configured for the LED
// matrix type being used. Refer documentation included in the MD_MAX72xx
// library or see this link:
// https://majicdesigns.github.io/MD_MAX72XX/page_hardware.html
//

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

// 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 MAX_DEVICES 1
#define CLK_PIN   6
#define DATA_PIN  7
#define CS_PIN    5

// Hardware SPI connection
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

void setup(void)
{
 P.begin();
 P.displayText("Hello", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}

void loop(void)
{
 P.displayAnimate();
}

Working directly with the MD_MAX72xx library works properly as below:

include <MD_MAX72xx.h>
#define     MAX_DEVICES   1 
 
#define     CLK_PIN      6  
#define     DATA_PIN     7  
#define     CS_PIN       5  
 
MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);  
  
#define SCROLL_DELAY     200
 
#define     CHAR_SPACING     1  
#define     BUF_SIZE     75  
char curMessage[BUF_SIZE];  
char newMessage[BUF_SIZE];  
   
uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)  
{  
  static char        *p = curMessage;  
  static uint8_t     state = 0;  
  static uint8_t     curLen, showLen;  
  static uint8_t     cBuf[8];  
  uint8_t colData;  
  
  switch(state)  
  {  
  case 0:  
    showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);  
    curLen = 0;  
    state++;  
    
    if (*p == '\0')  
    {  
      p = curMessage;  
    }  
  case 1:       
    colData = cBuf[curLen++];  
    
    if (curLen == showLen)  
    {  
      showLen = CHAR_SPACING;  
      curLen = 0;  
      state = 2;  
    }  
    
    break;  
  case 2:  
    colData = 0;  
    curLen++;  
 
    if (curLen == showLen)  
     state = 0;  
    
    break;  
    default:  
    state = 0;  
  }  
  return(colData);  
}  
  
void scrollText(void)  
{  
  static uint32_t     prevTime = 0;  
  if (millis()-prevTime >= SCROLL_DELAY)  
  {  
    mx.transform(MD_MAX72XX::TSL);       
    prevTime = millis();  
  }  
}  

void setup()  
{  
  mx.begin();  
  mx.setShiftDataInCallback(scrollDataSource);  
  mx.control(MD_MAX72XX::INTENSITY, 1);
  strcpy(curMessage, "TEST MESSAGE");
 
  newMessage[0] = '\0';  
}  
   
void loop()   
{  
  scrollText();  
}

How can I troubleshoot whats wrong? I've double checked all pins/inputs.

If you are using arbitrary pins you need to use the alternative version of class instantiation that is currently commented out. Same as for the MD_MAx72xx example that you changed.