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
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,


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.

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


Thanks for having a look at this for me.


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_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;

  Interrupt handler for Timer1 (TimerOne) driven DMD refresh scanning, this gets
  called at the period set in Timer1.initialize();
void ScanDMD()


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];

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


void connectMe (){

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
  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");

void setup() {
  // start the serial library:
  // 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:
   //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)
   // Connect to site

void loop(){

// if the server's disconnected, stop the client:
  if (!client.connected()) {

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

    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];
             totalEmailsLong = strtol(totalEmailsCharArray, NULL, 10);
             // Update the display
             if (lastTotal < totalEmailsLong) {
             // Clear everything
             stars = 0; 
             c = 'a';
             totalEmails = "";
             if (client.connected()){

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

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
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.

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 ... nterrupts/

It could be handy

User avatar
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:

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