Refresh Issue with EtherTen and DMD

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
Nat6
Posts: 4
Joined: Tue Feb 28, 2012 12:35 pm

Refresh Issue with EtherTen and DMD

Post by Nat6 » Tue Mar 13, 2012 3:51 am

Hi, this is probably a newbie issue but I haven't found any reference to help my issue elsewhere.

I'm using my EtherTen to hit a web server and return a number.

I am then displaying that number on the Freetronics DMD as a string (2 x 1 configuration).

All is working fine apart from the fact that when I am looping and reading the buffer that contains the returned string from the website, the DMD goes crazy and flashes random lights.

Anyone know how to avoid this?

Thanks in advance,

Nat.

tsneddon
Posts: 1
Joined: Mon Mar 19, 2012 12:34 pm

Re: Refresh Issue with EtherTen and DMD

Post by tsneddon » Mon Mar 19, 2012 12:47 pm

Hey there, post your code and we'll take a look.

Nat6
Posts: 4
Joined: Tue Feb 28, 2012 12:35 pm

Re: Refresh Issue with EtherTen and DMD

Post by Nat6 » Wed Mar 21, 2012 5:40 am

Hi,

Thanks for having a look at this for me.

Nat.

Code: Select all

/*

 
 */

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


// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(xxx,xxx,xxx,xxx); // xxxxxxxxxxx


#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 1
#define DISPLAYS_BPP 1
#define WHITE 0xFF
#define BLACK 0

String totalEmails;
int stars = 0;
long lastTotal = 1167000;
  

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN, DISPLAYS_BPP);

/*--------------------------------------------------------------------------------------
  Interrupt handler for Timer1 (TimerOne) driven DMD refresh scanning, this gets
  called at the period set in Timer1.initialize();
--------------------------------------------------------------------------------------*/
void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

//----------------------

void displayAndScroll(long totalEmailsLong){
  
  long startLastTotal = lastTotal;
  
for (long i = lastTotal; i <= totalEmailsLong; i = i + 3){
    // convert Int to Draw String
    String lastTotalString = "";
    lastTotalString += lastTotal;
    char lastTotalCharArray[9];
    lastTotalString.toCharArray(lastTotalCharArray,9);

    dmd.drawString(  1,  1, lastTotalCharArray , 7, WHITE,BLACK );
    lastTotal = i;

}
}

//----------------------
void connectMe (){
  
 delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    httpReq();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  } 
  
}

//----------------------
void httpReq(){
      
    // Make a HTTP request:
    client.println("GET /xxxxx/xxxxx.php HTTP/1.0"); // xxxxxxx
    client.println("Connection: keep-alive");
    client.println();
}


//----------------------
void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet0 connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
   Timer1.initialize( 5000/DISPLAYS_BPP );           //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( BLACK );   //true is normal (all pixels off), false is negative (all pixels on)
   dmd.selectFont(Arial_Black_16);
  
   // Connect to site
   connectMe();
}

//----------------------
void loop(){

// if the server's disconnected, stop the client:
  if (!client.connected()) {
    client.stop();
    delay(3000);
     connectMe();
  }

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

    if (stars == 3){                              // Read the number prefixes of 3 stars
      if (c != '*'){
          totalEmails = totalEmails + c;              // Build the number string  
      }
    
    
      if (c == '*') {       // After reading the number - check for * suffix
             
             // Convert variable to appropirate data types
             long totalEmailsLong;
             String totalEmailsString = "";
             totalEmailsString += totalEmails;
             char totalEmailsCharArray[9];
             totalEmailsString.toCharArray(totalEmailsCharArray,9);
             totalEmailsLong = strtol(totalEmailsCharArray, NULL, 10);
             
             // Update the display
             if (lastTotal < totalEmailsLong) {
                displayAndScroll(totalEmailsLong);
             }
      
             // Clear everything
             stars = 0; 
             client.flush();
             c = 'a';
             totalEmails = "";
             delay(30000);
             if (client.connected()){
                httpReq();
             }
     
            
      }          
    }

      if (c == '*') {                                // Increment the ster prefix counter
         stars ++;
         String numStars = String(stars);
      }
   }  
    
}

cjdelphi
Posts: 36
Joined: Mon Mar 19, 2012 10:11 am

Re: Refresh Issue with EtherTen and DMD

Post by cjdelphi » Wed Mar 21, 2012 6:50 am

When it goes crazy, does it spew the same data out and just keeps on spewing until either the wiznet or the atmega chip stops responding and freezes?..

start a sever on port 80 and just hit F5 and refresh F5, keep pressing it hold it down press it quickly, 1 in 60 times or so when i've done it quickly it just floods my screen with garbage and locks up until i have to pull the power out on it...

delay(200); seems to make things worse after calling a stop to the socket, shorter delay less prone it seems, weird one.

User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

Re: Refresh Issue with EtherTen and DMD

Post by Simon » Wed May 16, 2012 11:15 am

OK, I've been doing some work with a DMD and EtherTen recently to build a timing board for my local swim club. This retrieves event information over the ethernet while a marquee is scrolling across the screen.

What I've found is that with small bursts of data read over the ethernet, no interference is visible with the DMD display. But anything over 80 bytes or so causes "corruption" in the display.

Now, I'm a relative newbie to Arduino but what I believe is happening is that the DMD is not being deactivated on the SPI bus when the ethernet transfers are underway, so the data received via the SPI bus corrupts the display.

My solution to this problem is to deactivate the Timer1 interrupt which redraws the DMD display just before I begin a large ethernet transfer, then re-enable it afterwards. This prevents the display being corrupted, but I feel that as a solution it's treating the symptom and not the cause. The more correct fix would be to decouple the DMD from the SPI bus when ethernet data transfers are underway, but this is (at the moment) beyond my experience.

harryman01
Posts: 10
Joined: Tue May 08, 2012 11:33 am

Re: Refresh Issue with EtherTen and DMD

Post by harryman01 » Wed May 16, 2012 11:45 am

You might like to see this

http://www.uchobby.com/index.php/2007/1 ... nterrupts/

It could be handy

User avatar
Simon
Posts: 25
Joined: Wed May 02, 2012 2:40 am

Re: Refresh Issue with EtherTen and DMD

Post by Simon » Wed May 16, 2012 12:27 pm

Thanks for the link. I may be new to Arduino but I was fiddling with interrupts on my TRS-80 in 1983, so that concept's not exactly new :lol:

I really should take the time to read the architectural docs for the ATmega CPUs, then I'd be able to answer my own questions :lol:

Nat6
Posts: 4
Joined: Tue Feb 28, 2012 12:35 pm

Re: Refresh Issue with EtherTen and DMD

Post by Nat6 » Thu May 17, 2012 1:19 am

Great - thanks for that - I'll have a look and see if that makes a difference.

Post Reply