Displaying text in multiple lines

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
multigrade
Posts:7
Joined:Tue Sep 16, 2014 4:33 pm
Displaying text in multiple lines

Post by multigrade » Tue Sep 16, 2014 4:57 pm

Hello,

I'm working on a big DMD screen with 20 modules (working so far). For now I'm testing it with only 8 (4x2) DMD's.
I'm using an Arduino which gets text messages with a maximum of 200 characters. The message should be displayed on the DMD screen afterwards. I need a way to display the text in multiple lines so that the words won't get split. A new line should begin AFTER the last word.
I guess the Arduino has to divide the string at the last white space before the line ends? For example with System5x7 before 21 character. But how can I do that?

I'd really appreciate any help I can get.

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

Re: Displaying text in multiple lines

Post by angusgr » Wed Sep 17, 2014 5:06 am

Hi multigrade,

Exciting project! I think 20 DMDs will be the largest DMD install we've heard of. I'm afraid I can't necessarily guarantee they'll all work from one Arduino, at the very least you may need a Mega to handle the RAM requirements and you may possibly run into problems with refresh rate if they're all daisy chained together. However if 8 work OK you should be able to calculate the implications of scaling it up.

To split strings on the Arduino you'll probably want to get familiar with "C" language string handling, particularly the strtok() and strlen() functions:
http://www.cplusplus.com/reference/cstring/strtok/
http://www.cplusplus.com/reference/cstring/strlen/

Your sketch could use strtok() to split the string one word at a time, then use strlen() on each substring to keep track of the current position on the line and see if the next word will fit before the end of the line.

The other option would be to split the string at the source, and send precalculated lines to the Arduino - if that's possible.

If you're new to Arduino and haven't done much C programming then it might be good to look for someone to collaborate with on a project like this.

Regards,


Angus

multigrade
Posts:7
Joined:Tue Sep 16, 2014 4:33 pm

Re: Displaying text in multiple lines

Post by multigrade » Wed Sep 17, 2014 2:07 pm

Thanks a lot for the hint. I will look into it soon. I'm not totally new to Arduino but new when it comes to complex string handling. I hope I can figure it out by my own.

I use an Arduino Mega (Gboard pro, Mega with GSM) and it's working just fine with 20 DMD's daisy chained - if you only send some static text once in a while. I want to make an instruction of my project when I'm finish - for sure I will share it here too.

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

Re: Displaying text in multiple lines

Post by angusgr » Fri Sep 19, 2014 12:33 am

Good to hear. Please post back and let us know how it works out.

Angus

multigrade
Posts:7
Joined:Tue Sep 16, 2014 4:33 pm

Re: Displaying text in multiple lines

Post by multigrade » Sat Sep 20, 2014 9:08 pm

Here is an example to handle text. After I tried something else (it was not very efficient) I got help from the arduino forum - works perfect:

Code: Select all

char str[] ="Hello World! Here is some text. I need to break it into multiple lines without splitting the words.";
const int wantedLength = 20;

const char * split (const char * s, const int length)
  {
  // if it will fit return whole thing
  if (strlen (s) <= length)
    return s + strlen (s);

  // searching backwards, find the last space
  for (const char * space = &s [length]; space != s; space--)
    if (*space == ' ')
      return space;
    
  // not found? return a whole line
  return &s [length];        
  } // end of split
  
  
void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  const char * p = str;
  
  // keep going until we run out of text
  while (*p)
    {
    // find the position of the space
    const char * endOfLine = split (p, wantedLength);  
    
    // display up to that
    while (p != endOfLine)
      Serial.print (*p++);
      
    // finish that line
    Serial.println ();
    
    // if we hit a space, move on past it
    if (*p == ' ')
      p++;
    }
  }  // end of setup
  
void loop () { }

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

Re: Displaying text in multiple lines

Post by angusgr » Tue Sep 23, 2014 3:16 am

Great to hear, glad you got it working.


Angus

Post Reply