Missing characters from serial input when using DMD2

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
ad3246
Posts: 5
Joined: Wed Jul 05, 2017 11:38 am

Missing characters from serial input when using DMD2

Post by ad3246 » Tue Feb 19, 2019 2:34 am

Last year, I used 32x16 panels in a 2w x 1h (64x16) configuration with an Arduino Mega for a simple project to display the score at football matches, which worked well.

Now I’ve been working on a more ambitious project! I’m trying to build a sports timing clock in a 5w x 2h configuration (160x32 pixels) using an Arduino Due.

I’ve tested the panels in a 5x2 configuration using the “Game of Life” example sketch and it worked as expected.

However for the real project, I have a separate sports timing device that outputs the running time over an RS232 serial connection. It outputs the time every 1/10sec, so the Arduino is receiving 10 packets of serial data every second. I’ve written a sketch that receives and displays the data correctly over the serial monitor.

Code: Select all


String serialInput;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  while (Serial1.available() > 0) {
  
    byte incomingByte = Serial1.read();
    serialInput.concat(char(incomingByte));
    
    if(incomingByte == 4) {  // 4 is end of packet character
      Serial.println(serialInput);
      serialInput = "";
    }
    
  }
}
However, when I add in the DMD2 code to display the time on the panels, there are missing characters on both the DMD panels and the serial monitor.

Code: Select all

#include <SPI.h>
#include <DMD2.h>
#include <fonts/Arial_32.h>

const int WIDTH = 5;
const int HEIGHT = 2;
const uint8_t *FONT = Arial_32;
SoftDMD dmd(WIDTH,HEIGHT);
DMD_TextBox box(dmd);

String serialInput;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  dmd.setBrightness(100);
  dmd.selectFont(FONT);
  dmd.begin();
}

void loop() {

  while (Serial1.available() > 0) {

    byte incomingByte = Serial1.read();
    serialInput.concat(char(incomingByte));
    
    if(incomingByte == 4) {  // 4 is end of packet character
      dmd.drawString(0,0,serialInput);
      Serial.println(serialInput);
      serialInput = "";
    }

  }

}
If I change the panel configuration to 1x1, I still get missing characters but only approx. 1 missing character every 20 packets. With the 5x2 panel configuration, most packets have 1 missing character, some have 2 or 3 or even 4 missing characters.

I guess the Ardunio isn’t coping with the 5x2 display and reading the serial data, but I’d hoped using the Due would remove any processor issues.

I've read other forum topics with some mentioning the clock divider. My understanding is that the Due uses an 84 MHz cpu with a divider of 20 set in the DMD2 library giving 4.2MHz for the panels, which only actually need 256 KHz for 5x2? Maybe my maths or understanding is wrong...

Can my code be structured better to handle both tasks? Any advice appreciated.

Brissieboy
Posts: 172
Joined: Fri Sep 20, 2013 7:25 am

Re: Missing characters from serial input when using DMD2

Post by Brissieboy » Wed Feb 20, 2019 5:09 am

I suspect your sketch is spending too much time in the interrupt updating the DMDs. It will take quite a while to do this with 10 DMDs. Characters will probably be lost during this time.

ad3246
Posts: 5
Joined: Wed Jul 05, 2017 11:38 am

Re: Missing characters from serial input when using DMD2

Post by ad3246 » Thu Feb 21, 2019 12:40 pm

Thanks for your reply.

I've read though some of the first posts on this forum section, and see there are a number of others who have tried DMD projects to display serial input, and have also had issues with missing characters.

I'd hoped that using the faster Arduino Due would have made this viable, but given I still get missing characters with just 1 DMD module, it looks like there is either something fundamentally wrong with my code or maybe the Arduino is just not the right platform for this?

Is there a way I can structure my sketch so that the Arduino can multi-task with both controlling the DMD panels and receiving the serial data?

Or should I be looking at a Raspberry Pi for a project like this?

Brissieboy
Posts: 172
Joined: Fri Sep 20, 2013 7:25 am

Re: Missing characters from serial input when using DMD2

Post by Brissieboy » Fri Feb 22, 2019 11:05 pm

Sorry but I can't offer much help here as I have not done much with DMD2. You could try limiting your serial while loop to doing nothing but gathering the input characters and putting them into a buffer and see if that has any effect.

User avatar
stryker
Posts: 281
Joined: Sat Jan 14, 2012 2:44 pm

Re: Missing characters from serial input when using DMD2

Post by stryker » Sat Feb 23, 2019 3:48 am

I had a digital scoreboard which used serial to communicate between controllers, and I did find issues with more panels which was the rationale of breaking it into smaller parts with each section controlled by one board and a master to rule them all. At the time I found 6 was a safe maximum per ATmega328 based controller. I don't recall losing any characters with the inbuilt hardware serial, only SoftwareSerial, but after settling on the 1-6 rule I never plugged in as many DMD panels as you have there.

Sorry I don't have more to offer on this one.
Geoff

ad3246
Posts: 5
Joined: Wed Jul 05, 2017 11:38 am

Re: Missing characters from serial input when using DMD2

Post by ad3246 » Sun Mar 10, 2019 12:01 pm

I made some progress on this...

The timing device I'm using is fixed at 9600bps. Since the sketch was taking a long time in the interrupt to update the DMDs, I thought I could use two Arduinos, one to receive the serial data from the timing device at 9600bps, and then send it to the other Arduino controlling the DMDs at 115200bps. I thought a faster speed would help.

Anyway, the character loss was worse at a faster speed, so I tried reducing the speed to 2400bps, and it actually works!! I'm don't quite understand why though.. but it's run for 30mins with no dropped characters.

I also found a 3 core Arduindo compatiable board (Hitex ShieldBuddy TC275) that I thought might be another solution instead of using two seperate Arudino's, but the Aurix processor on the ShieldBuddy TC275 isn't compatible with the DMD2 library.

Post Reply