DMD & etherten message board

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
mjwillia
Posts: 4
Joined: Thu Jun 21, 2012 12:11 am

DMD & etherten message board

Post by mjwillia » Thu Jun 21, 2012 2:16 am

Hi,
I'm completely new to arduino. This is my first project, and I'm trying to make a display board that looks to a php page and scrolls the text on it.

I've gotten half way by very badly ripping bits of code from here and there.
I can get it to connect to my php page and grab the text, even output it via serial. So I know it's there.

But what I'm having trouble with is displaying the variable on the dmd with the dmd.drawMarquee command.

I can get it to display a set message, but when I try to use the variable it says "error: 'displaytext' was not declared in this scope"

I know that I just don't understand enough about this language, and I've read many codes that do a similar thing, but can't get my head around it.

Please help...

Code: Select all

#include <SPI.h>
#include <Ethernet.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(27,124,113,129);
EthernetClient client;

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

void setup() {
     //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   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()

   //clear/init the DMD pixels held in RAM
   dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)

  Serial.begin(9600);
   while (!Serial) {
    ;
  }

if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }

  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /~williams/arduino/display.php");
    client.println();
  } 
  else {Serial.println("connection failed");}
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char displaytext = client.read();
    Serial.print(displaytext);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

   dmd.clearScreen( true );
   dmd.selectFont(Arial_Black_16);
   dmd.drawMarquee(displaytext,14,(32*DISPLAYS_ACROSS)-1,0);
   long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }   

delay(60000);
setup();
  }
}

mjwillia
Posts: 4
Joined: Thu Jun 21, 2012 12:11 am

Re: DMD & etherten message board

Post by mjwillia » Thu Jun 21, 2012 5:23 am

Complete start over has given some better results :)

Now it gets data from a php page and displays it. Once, until it connects and downloads again.
Trying to fix that now.

Code: Select all

//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte server[] = { 27,124,113,129 }; //ip Address of the server you will connect to

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String location = "/~williams/arduino/display.php";

// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
////////////////////////////////////////////////////////////////////////

EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

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

void setup(){
  Ethernet.begin(mac);
  Serial.begin(9600);
  
       //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   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()

   //clear/init the DMD pixels held in RAM
   dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  }

void loop(){
  String pageValue = connectAndRead(); //connect to the server and read the output

  Serial.println(pageValue); //print out the findings.
  
  dmd.selectFont(Arial_Black_16);
  char marqueeString[256];
    int myTextLength = pageValue.length();
    pageValue.toCharArray(marqueeString, myTextLength+1);
   
    dmd.drawMarquee(marqueeString,myTextLength,(32*DISPLAYS_ACROSS)-1,0);
    long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  

  delay(5000); //wait 5 seconds before connecting again
}

String connectAndRead(){
  //connect to the server

  Serial.println("connecting...");

  //port 80 is typical of a www page
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.print("GET ");
    client.println(location);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }else{
    return "connection failed";
  }

}

String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part 
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }

}

Aussie_Wombat
Posts: 51
Joined: Tue May 22, 2012 12:52 pm
Location: Adelaide, South Australia

Re: DMD & etherten message board

Post by Aussie_Wombat » Thu Jun 21, 2012 9:19 am

Hi mjwillia,

Are you using an external power supply to power the etherten, or a usb cable?

Sometimes the wiznet chip which controls the ethernet on the etherten, drops the ip if the power level gets to low.. Usually using an external power supply on the etherten will fix this. The dmd, etherten and the ethernet are too much for the usb cable supply from the computer.

Cheers Dennis

mjwillia
Posts: 4
Joined: Thu Jun 21, 2012 12:11 am

Re: DMD & etherten message board

Post by mjwillia » Thu Jun 21, 2012 9:55 am

Hi Dennis,

I'm using a 12v 500ma switchmode supply at the moment.
I just got all this working a few minutes ago!

Now I'm trying to expand it to 2 DMD's but can't get it to go.
Any tricks? The second DMD is just showing some random junk occasionally..

Here's the latest code:

Code: Select all

//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte server[] = { 27,54,85,129 }; //ip Address of the server you will connect to
int update;

//The location to go to on the server
//make sure to keep HTTP/1.0 at the end, this is telling it what type of file it is
String location = "/~autoone/onsite/sms/led_display.php";

// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
////////////////////////////////////////////////////////////////////////

EthernetClient client;

char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

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

void setup(){
  pinMode(2, OUTPUT);
  Ethernet.begin(mac);
  Serial.begin(9600);
  
       //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   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()

   //clear/init the DMD pixels held in RAM
   dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  }

void loop(){
  String pageValue = connectAndRead(); //connect to the server and read the output
  Serial.println(pageValue); //print out the findings.

if ( pageValue != " 0" ) {
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  delay(50);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  delay(50);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  delay(50);
}

if ( pageValue == " 0" ) {
  delay (30000);
  pageValue = " ";
}

  dmd.selectFont(Arial_Black_16);
  char marqueeString[256];
    int myTextLength = pageValue.length();
    pageValue.toCharArray(marqueeString, myTextLength+1);
   
redraw:   
 
    dmd.drawMarquee(marqueeString,myTextLength,(32*DISPLAYS_ACROSS)-1,0);
    long start=millis();
   long timer=start;
   boolean ret=false;
   while(!ret){
     if ((timer+30) < millis()) {
       ret=dmd.stepMarquee(-1,0);
       timer=millis();
     }
   }
  
update = update + 1;
if ( update == 10 ) {
  goto newupdate;
}
goto redraw;

newupdate:
update = 0;

}

String connectAndRead(){
  //connect to the server

  Serial.println("connecting...");

  //port 80 is typical of a www page
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.print("GET ");
    client.println(location);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }else{
    return "connection failed";
  }

}

String readPage(){
  //read the page, and capture & return everything between '<' and '>'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true){

    if (client.available()) {
      char c = client.read();

      if (c == '<' ) { //'<' is our begining character
        startRead = true; //Ready to start reading the part 
      }else if(startRead){

        if(c != '>'){ //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;

        }

      }
    }

  }

}
Edit: Yes... I have a few horrid 'goto' in there. I just couldn't work it out otherwise :/
The digitalWrite on pin 2 is for a beeper when there is new stuff to display
When there is nothing to show (php sends " 0") then output is suppressed for 30 seconds till the next lookup

Aussie_Wombat
Posts: 51
Joined: Tue May 22, 2012 12:52 pm
Location: Adelaide, South Australia

Re: DMD & etherten message board

Post by Aussie_Wombat » Thu Jun 21, 2012 8:37 pm

mjwillia

In your Code you set the dmd panels ...

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

Here you have set it to only one panel..

You need to change the number to ....

#define DISPLAYS_ACROSS 2 // Two panels across..

if you have them side by side...

That could also help ( most likely ). but the extra panel will drain the power from the etherten, and you may get ip dropout.
Now you may need to add power to the dmd panels themselves. Adding a 5V 4A (must be 5V) power supply to the dmd panels at the screw connections at the rear of the panels. Daisy chain the power to each dmd panel. This should help..

Dennis

PS. Checkout this thread...

viewtopic.php?f=26&t=661

Post Reply