Need a little help DMD and Serial Input

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
LordN1kon
Posts: 7
Joined: Sat Dec 07, 2013 1:53 am

Need a little help DMD and Serial Input

Post by LordN1kon » Sat Dec 07, 2013 1:58 am

Hey Guys,

I started to Play around with DMD and so i want to send a text to the LED most of the time everything works fine but sometimes die Text isn't correct Display (some Digits are lost) but why or what can i do to eliminate that Problem.
I tried different baud rates and at 56700 the resault is the best.

Here my code:

Code: Select all

#include "SPI.h"      
#include "DMD.h" 
#include "TimerOne.h"
#include "Arial_black_16.h"<arial_black_16.h> 
// you can remove the fonts if unused
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 1   
#define DISPLAYS_DOWN 1     
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0
/* change these values if you have more than one DMD connected */
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN, DISPLAYS_BPP);


int clearvar = 0;
char stringa[10];
char current ;
int i = 0;
int c = 0;



void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

void setup()
{
   Timer1.initialize( 5000 );           
/*period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.*/

   Timer1.attachInterrupt( ScanDMD );  
/*attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()*/

   dmd.clearScreen( true );            
/* true is normal (all pixels off), false is negative (all pixels on) */

Serial.begin(57600);

}

void loop() {
  // put your main code here, to run repeatedly: 
  
  
 if (clearvar == 0) {
   dmd.clearScreen( BLACK );
   clearvar = 1;
   }
  
  
   
  i = 0; 

  
 while(Serial.available()){
  
 
  
  current = Serial.read();
  stringa[i] = current;
  i ++;
  c = 1;
  }
  
  Serial.println(stringa);
  
if(c==1){
while(i <=10){
  stringa[i] = ' ';
  i ++;
  }
  c = 0;
}



    dmd.selectFont(SystemFont5x7);
    dmd.drawString(  2, 1, stringa , 5, WHITE,BLACK );
    dmd.drawString(  4, 9, "Alex" , 5, WHITE,BLACK );
  
   
   
  
}
thx

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need a little help DMD and Serial Input

Post by angusgr » Wed Dec 11, 2013 10:16 pm

Hi LordN1kon,

Are the missing characters missing only on the DMD display, or are they also not being echoed back on the serial port?

- Angus

coromonadalix
Posts: 26
Joined: Wed Apr 09, 2014 9:03 pm

Re: Need a little help DMD and Serial Input

Post by coromonadalix » Sun Aug 31, 2014 4:59 pm

hello
Whanting to buil and rs232 arduino DMD interface
upon taking this code and adding some mods

I whant to display standard ascii and numeric characters

i have this as a result

123456789 will show 129
test will show tet
Dist will show Dit
Dist: 5.143m will show Dim
hello123 will show he3

the two first chracters are shown and the last one

The serial monitor dont stop scrolling after sending the command, repeated infinitely ???

what could be the problem ??

Code: Select all


 #include "SPI.h"     
    #include "DMD.h"
    #include "TimerOne.h"
    #include "Arial_black_16.h"<arial_black_16.h>
    #include "SystemFont5x7.h"
    #define DISPLAYS_ACROSS 4   
    #define DISPLAYS_DOWN 1     
    
    DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

    int clearvar = 0;
    char stringa[10];
    char current ;
    int i = 0;
    int c = 0;



    void ScanDMD()
    {
      dmd.scanDisplayBySPI();
    }

    void setup()
    {
       Timer1.initialize( 5000 );           
       Timer1.attachInterrupt( ScanDMD ); 
       dmd.clearScreen( true );           
    
    Serial.begin(115200);

    }

    void loop() {
           
     if (clearvar == 0) {
       dmd.clearScreen( true );
       clearvar = 1;
       }
      
     i = 0;
     
     while(Serial.available()){
        
      current = Serial.read();
      stringa[i] = current;
      i ++;
      c = 1;
      }
     
      Serial.println(stringa);
     
      if(c==1){
      while(i <=10){
      stringa[i] = ' ';
      i ++;
      }
      c = 0;
    }
     
      dmd.selectFont(SystemFont5x7);
      dmd.drawString(  1, 4, stringa , 10, GRAPHICS_NORMAL );    
    }


angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need a little help DMD and Serial Input

Post by angusgr » Mon Sep 01, 2014 1:05 am

Hi coromonadalix,
coromonadalix wrote:

Code: Select all

while(Serial.available()){
       
      current = Serial.read();
      stringa[i] = current;
      i ++;
      c = 1;
      }
There are a few problems with this code -

* It can overflow (if more than 10 characters are sent).
* 'stringa' isn't initialised with zeroes at any point, so it's not terminated.
* Serial.available() only tells you whether characters are available 'right now' - it may fall through with 'false' result even though new characters arrive a millisecond after you check.

I'd suggest replacing this with the Serial.readBytesUntil function in Arduino:
http://arduino.cc/en/Serial/ReadBytesUntil

Something like this (untested code):

Code: Select all

memset(stringa, 0, sizeof(stringa)); // set string contents to zero
Serial.setTimeout(30*1000); // 30 second input timeout 
i = Serial.readBytesUntil('\n', stringa, sizeof(stringa)-1); // Read line of input
// i contains number of characters read 

coromonadalix
Posts: 26
Joined: Wed Apr 09, 2014 9:03 pm

Re: Need a little help DMD and Serial Input

Post by coromonadalix » Mon Sep 01, 2014 6:13 am

new code but the numbers of characters shown are still buggy ??? dont know why it wont show more than 3 characters ???

but the serial terminal is working ok, no infinite looping, but show the same 3 chars problems

123456789 will show 129
test will show tet
Dist will show Dit
Dist: 5.143m will show Dim
hello123 will show he3



#include "SPI.h"
#include "DMD.h"
#include "TimerOne.h"
//#include "Arial_black_16.h"<arial_black_16.h>
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 4
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

int clearvar = 0;
char stringa[20];
int i = 0;

void ScanDMD()
{
dmd.scanDisplayBySPI();
}

void setup()
{
Timer1.initialize( 5000 );
Timer1.attachInterrupt( ScanDMD );
dmd.clearScreen( true );

Serial.begin(115200);

}

void loop() {

if (clearvar == 0) {
dmd.clearScreen( true );
clearvar = 1;
}

i = 0;

while(Serial.available())
{

memset(stringa, 0, sizeof(stringa)); // set string contents to zero
Serial.setTimeout(500); // second input timeout
i = Serial.readBytesUntil('\n', stringa, sizeof(stringa)-1); // Read line of input
// i contains number of characters read
Serial.println(stringa);

dmd.selectFont(SystemFont5x7);
dmd.drawString( 1, 4, stringa , 20, GRAPHICS_NORMAL );
}
}

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

Re: Need a little help DMD and Serial Input

Post by stryker » Mon Sep 01, 2014 7:55 am

Hi,

I took your code and ran it on an Eleven. The serial monitor echoes correctly what I type in

Code: Select all

12345
asdfasdf
as
asd
asdf
1234567890
with no 3 character truncation. The above was copied directly from the terminal window. Is it possible you didn't successfully upload the new code?

Cheers!
Geoff

coromonadalix
Posts: 26
Joined: Wed Apr 09, 2014 9:03 pm

Re: Need a little help DMD and Serial Input

Post by coromonadalix » Mon Sep 01, 2014 12:27 pm

sorry uploaded 3 times,

it worked ok only once with : 123456789 but afterward, the third char problem got back

im running this on a duemilanove


just tried on my mega 2560 doesnt work at all, nothing is shown ???
the mega is wired correctly, it works with other dmd sketchs

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Need a little help DMD and Serial Input

Post by angusgr » Tue Sep 02, 2014 11:54 pm

Try replacing the loop() method with something like this (untested, but something like this should work):

Code: Select all

void loop() {
  // Read line from Serial
  memset(stringa, 0, sizeof(stringa)); // set string contents to zero
  Serial.setTimeout(1000); // second input timeout
  i = Serial.readBytesUntil('\n', stringa, sizeof(stringa)-1); // Read line of input
  if(i > 0) { // Display line if anything was read
    Serial.println(stringa);

    dmd.clearScreen(true);
    dmd.selectFont(SystemFont5x7);
    dmd.drawString( 1, 4, stringa , strlen(stringa), GRAPHICS_NORMAL );
  }
}
Let me know if you'd like me to explain anything typed above.

mickot
Posts: 6
Joined: Sun Mar 23, 2014 12:01 pm

Re: Need a little help DMD and Serial Input

Post by mickot » Wed Sep 03, 2014 9:53 am

Like many people I have built a scoreboard.
It is controlled by an Arduino Yun and because the first version of the library did not support Yun/Leonardo, it sends a serial message to a second Arduino Uno to control the display.
I tested it all running the serial comms at 9600 and it worked with one DMD attached, but once I was driving 4 DMDs I had to drop the serial baud rate to 1200 to successfully get all the characters.
This seems to be the opposite of what is happening here where a higher baud rate is needed. I presume it is because of the interrupt handling for more than 1 display.

The scoreboard has a web interface, custom font and will eventually tweet the score eevrytime it changes

I will write it up at some stage and post it here

-mick

coromonadalix
Posts: 26
Joined: Wed Apr 09, 2014 9:03 pm

Re: Need a little help DMD and Serial Input

Post by coromonadalix » Wed Sep 03, 2014 10:48 am

hello mickot have you heard of a Spi clock divider tweak to have more performance.... i had to do it in an older project the sr04 ultrasonic sensor and dmd to improve things.

This project is an update, the sr04 was imprecise at some point (rounded or cornered objects)

I have to push the baud rate at 115200, because i have a laser range finder who works only at 115200 bauds, i have troubles with the TimerOne library who seems to slow down the loop or jam it, something i didn't see at that point.

I am trying this solution to split the work between 2 arduinos, one for managing the measurements, and other for the displays.

But would be nice to have some kind of an interface with rs232 or i2c .... to drive panels like this

Ill try you code thks

Post Reply