Posts | Comments

Planet Arduino

Archive for the ‘text’ Category

Aug
01

Review – adafruit industries Mini 8×8 LED Matrix with I2C backpack

16K33, adafruit, arduino, demonstration, graphic, holtek, i2c, LED, LED matrix, lesson, matrix, mini, review, scrolling, text, tronixstuff, tutorial Comments Off on Review – adafruit industries Mini 8×8 LED Matrix with I2C backpack 

Introduction

In this review we have a look at the mini 8×8 LED matrix with I2C backpack from adafruit industries. It looked like a small yet versatile display unit for a couple of project ideas, so as part of the evaluation we’ll run through it with you here. As you can see below, it’s quite small with a 20mm square matrix:

contents

The matrix and the controller are seperate which gives you the option of ordering different colours of matrix. Using LED matrices can be a pain, however these units use the Holtek 16K33 controller IC (data sheet) which has an I2C interface – much easier than the usual mess of shift registers and I/O pins:

holtek

 Furthermore you can change the I2C address using the solder pads on the PCB, giving you four possible options. And as it’s I2C, you can use it with other microcontrollers with a little detective work. Moving forward, we’ll assemble the display then explain how to use it with an Arduino, and show a few demonstrations.

Assembly

There really isn’t anything major to do, just solder the matrix to the backpack and some header pins if you need them. adafruit include some however I’m using the 90-degree ones for my own use:

solderingpins

The soldering should take about one minute tops, and then you’re done:

finished

Using the matrix

From a hardware perspective you only have four wires – 5V, GND, SDA and SCL. Yes – it’s a 5V part, so all you Raspberry Pi fans will need a level shifter, which you can get from adafruit as well. Anyhow once you’ve got it connected to your Arduino, a couple of libraries are required – the matrix and GFX libraries. Be sure to install them in your sketchbook/libraries folder and not the usual location. When saving the library files, call the first folder Adafruit_LEDBackpack and the second Adafruit_GFX as they don’t arrive in that format.

Now for a quick demonstration, it’s simply one from the included library. The display is very bright, so I had to reduce the exposure on the camera which makes the background a little dark – but you get the idea:

A pair of those fitted to a dummy or doll would be quite interesting, or make good eyes for a 21st century “Metal Mickey”. Well that’s quite interesting, so how do you in fact display things on the matrix? I’ve deconstructed a few examples to show you how it’s done.

No matter what, you need to include the libraries, define the matrix object in the sketch and then start it with the matching I2C address – for example:

// required libraries
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// define matrix object
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

void setup() 
{
  // start the matrix at I2C address - default is 0x70
  matrix.begin(0x70);  // pass in the address
}

To scroll text across the display, modify the following chunk of code:

matrix.setRotation(0);
  matrix.setTextSize(1);
  matrix.setTextWrap(false); // false means nice scroll, true means each character appears, scrolls off, then repeat
  matrix.setTextColor(LED_ON);
  for (int8_t x=0; x>=-96; x--) // 96 is number of characters to display x 8
  {
    matrix.clear();
    matrix.setCursor(x,0);
    matrix.print("Hello, world");
    matrix.writeDisplay();
    delay(100);
  }

First, the setRotation() value is 0~3 and determines which way the text scrolls across the screen. This is useful if you mount the matrix in different positions, as you can still keep the text scrolling in a readable manner. Next, matrix.setTextWrap() – leave this as false,  as true displays each character and then just scrolls it in turn – looking rather odd. Now multiply the number of characters you want to display by 8, and replace the number -96 with negative your value and of course “Hello, world”. Finally follow with rest of the code. There’s a quick demonstration of this code in the sketch and video below:

// required libraries
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// define matrix object
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

void setup() 
{
  // start the matrix at I2C address - default is 0x70
  matrix.begin(0x70);  // pass in the address
}

void loop()
{
  matrix.setRotation(0);
  matrix.setTextSize(1);
  matrix.setTextWrap(false); // false means nice scroll, true means each character appears, scrolls off, then repeat
  matrix.setTextColor(LED_ON);
  for (int8_t x=0; x>=-96; x--) // 96 is number of characters to display x 8
  {
    matrix.clear();
    matrix.setCursor(x,0);
    matrix.print("Hello, world");
    matrix.writeDisplay();
    delay(100);
  }

  delay(500);
  matrix.setRotation(1);  
  matrix.setTextSize(1);
  matrix.setTextWrap(false); // false means nice scroll, true means each character appears, scrolls off, then repeat
  matrix.setTextColor(LED_ON);
  for (int8_t x=0; x>=-96; x--) // 96 is number of characters to display x 8
  {
    matrix.clear();
    matrix.setCursor(x,0);
    matrix.print("Hello, world");
    matrix.writeDisplay();
    delay(100);
  }  

  delay(500);
  matrix.setRotation(2);  
  matrix.setTextSize(1);
  matrix.setTextWrap(false); // false means nice scroll, true means each character appears, scrolls off, then repeat
  matrix.setTextColor(LED_ON);
  for (int8_t x=0; x>=-96; x--) // 96 is number of characters to display x 8
  {
    matrix.clear();
    matrix.setCursor(x,0);
    matrix.print("Hello, world");
    matrix.writeDisplay();
    delay(100);
  }  

  delay(500);
  matrix.setRotation(3);  
  matrix.setTextSize(1);
  matrix.setTextWrap(false); // false means nice scroll, true means each character appears, scrolls off, then repeat
  matrix.setTextColor(LED_ON);
  for (int8_t x=0; x>=-96; x--) // 96 is number of characters to display x 8
  {
    matrix.clear();
    matrix.setCursor(x,0);
    matrix.print("Hello, world");
    matrix.writeDisplay();
    delay(100);
  }  
}

 

Now for some graphics. You can define your own images (!) and store them in an array. Each arrays consists of eight bytes, each representing a row of the matrix. You can use binary to help visualise the results, for example:

static uint8_t PROGMEM
  crosshatch[] =
  { B10101010,
    B01010101,
    B10101010,
    B01010101,
    B10101010,
    B01010101,
    B10101010,
    B01010101 };

and then to display that on the matrix, use the following:

matrix.clear(); // clear the display
matrix.drawBitmap(0, 0, crosshatch, 8, 8, LED_ON); // setup the image to display
matrix.writeDisplay(); // display the image
delay(1000);

… which resulted with:

crosshatch

To control individual pixels, send one or more of the following:

matrix.drawPixel(x, y, LED_ON);

where x and y are the pixel’s coordinates (that fall between zero and seven), followed by:

matrix.writeDisplay();

Here’s a neat example sketch and video of a single pixel “running around the border”:

// required libraries
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// define matrix object
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

int z;

void setup() 
{
  // start the matrix at I2C address - default is 0x70
  matrix.begin(0x70);  // pass in the address
}

void loop()
{
  matrix.clear();      // clear display
  for (z=0; z<8; z++)
  {  
    matrix.drawPixel(z, 0, LED_ON);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(50);
    matrix.drawPixel(z, 0, LED_OFF);  
    matrix.writeDisplay();  // write the changes we just made to the display     
  }  

  for (z=0; z<8; z++)
  {  
    matrix.drawPixel(7, z, LED_ON);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(50);
    matrix.drawPixel(7, z, LED_OFF);  
    matrix.writeDisplay();  // write the changes we just made to the display     
  }  

  for (z=7; z>=0; --z)
  {  
    matrix.drawPixel(z, 7, LED_ON);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(50);
    matrix.drawPixel(z, 7, LED_OFF);  
    matrix.writeDisplay();  // write the changes we just made to the display     
  }  

  for (z=7; z>=0; --z)
  {  
    matrix.drawPixel(0, z, LED_ON);  
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(50);
    matrix.drawPixel(0, z, LED_OFF);  
    matrix.writeDisplay();  // write the changes we just made to the display     
  }  
}

By this point you should be getting the hang of things now, so we’ll finish up with the last three graphic functions at once. To draw a line between x1, y1 and x2, y2 – use:

matrix.drawLine(x1 ,y1 , x2, y2, LED_ON);

To draw a rectangle with corners at x1, y2, x2, y2 – use:

matrix.drawRect(x1, y1, x2, y2, LED_ON);

To draw a filled rectangle with corners at x1, y2, x2, y2 – use:

matrix.fillRect(x1, y1, x2, y2, LED_ON);

And to draw a circle with axis at x,y and a radius of r pixels – use:

matrix.drawCircle(x, y, r, LED_ON);

Now we’ll put those functions into the following sketch and video:

// required libraries
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// define matrix object
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

int y, z;

void setup() 
{
  // start the matrix at I2C address - default is 0x70
  matrix.begin(0x70);  // pass in the address
}

void loop()
{
  // circles
  for (y=0; y<5; y++)
  {
    for (z=0; z<8; z++)
    {
      matrix.clear();
      matrix.drawCircle(3,3, z, LED_ON);
      matrix.writeDisplay();  // write the changes we just made to the display
      delay(100);
    }
  }

  for (y=0; y<=5; y++)
  {
    // rectangles
    matrix.clear();
    matrix.drawRect(0, 0, 4, 4, LED_ON);
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(250);
    matrix.clear();
    matrix.drawRect(4, 0, 4, 4, LED_ON);
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(250);
    matrix.clear();
    matrix.fillRect(4, 4, 7, 7, LED_ON);
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(250);
    matrix.clear();
    matrix.fillRect(0, 4, 4, 7, LED_ON);
    matrix.writeDisplay();  // write the changes we just made to the display
    delay(250);
  }
}

 

If you want to get someone’s attention, you can blink whatever’s on the matrix at various frequencies – and of course turn it off. In the following function, use 0 for off, and 1~3 for different rates:

matrix.blinkRate(x);

Finally, you can also adjust the brightness to one of sixteen levels (0~15) using:

matrix.setBrightness(level); // level: 0~15

That’s enough blinkiness for now. Remember the library is just shielding you from the raw I2C commands, so if you want to create your own functions or use a non-Arduino board – examine the library and the data sheet.

Conclusion

The backpack makes using the matrix an absolute breeze, and the library saves a lot of time and effort – leaving you to get on with creating your ideas into projects. You can get the matrix from adafruit and their distributors.

Full-sized images available on flickr.  And if you made it this far – check out my new book “Arduino Workshop” from No Starch Press.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

[Note - item purchased without notifying the supplier]

The post Review – adafruit industries Mini 8×8 LED Matrix with I2C backpack appeared first on tronixstuff.

Introduction

Time for another instalment in my highly-irregular series of irregular clock projects.  In this we have “Clock Four” – a scrolling text clock. After examining some Freetronics Dot Matrix Displays in the stock, it occurred to me that it would be neat to display the time as it was spoken (or close to it) – and thus this the clock was born. It is a quick project – we give you enough to get going with the hardware and sketch, and then you can take it further to suit your needs.

Hardware

You’ll need three major items – An Arduino Uno-compatible board, a real-time clock circuit or module using either a DS1307 or DS3232 IC, and a Freetronics DMD. You might want an external power supply, but we’ll get to that later on.

The first stage is to fit your real-time clock. If you are unfamiliar with the operation of real-time clock circuits, check out the last section of this tutorial. You can build a RTC circuit onto a protoshield or if you have a Freetronics Eleven, it can all fit in the prototyping space as such:

If you have an RTC module, it will also fit in the same space, then you simply run some wires to the 5V, GND, A4 (for SDA) and A5 (for SCL):

By now I hope you’re thinking “how do you set the time?”. There’s two answers to that question. If you’re using the DS3232 just set it in the sketch (see below) as the accuracy is very good, you only need to upload the sketch with the new time twice a year to cover daylight savings (unless you live in Queensland). Otherwise add a simple user-interface – a couple of buttons could do it, just as we did with Clock Two. Finally you just need to put the hardware on the back of the DMD. There’s plenty of scope to meet your own needs, a simple solution might be to align the control board so you can access the USB socket with ease – and then stick it down with some Sugru:

With regards to powering the clock – you can run ONE DMD from the Arduino, and it runs at a good brightness for indoor use. If you want the DMD to run at full, retina-burning brightness you need to use a separate 5 V 4 A power supply. If you’re using two DMDs – that goes to 8 A, and so on. Simply connect the external power to one DMD’s terminals (connect the second or more DMDs to these terminals):

The Arduino Sketch

You can download the sketch from here. It was written only for Arduino v1.0.1. The sketch has the usual functions to set and retrieve the time from DS1307/3232 real-time clock ICs, and as usual with all our clocks you can enter the time information into the variables in void setup(), then uncomment setDateDs1307(), upload the sketch, re-comment setDateDs1307, then upload the sketch once more. Repeat that process to re-set the time if you didn’t add any hardware-based user interface.

Once the time is retrieved in void loop(), it is passed to the function createTextTime(). This function creates the text string to display by starting with “It’s “, and then determines which words to follow depending on the current time. Finally the function drawText() converts the string holding the text to display into a character variable which can be passed to the DMD.

And here it is in action:

Conclusion

This was a quick project, however I hope you found it either entertaining or useful – and another random type of clock that’s easy to reproduce or modify yourself. We’re already working on another one which is completely different, so stay tuned.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.


Introduction

Time for another instalment in my highly-irregular series of irregular clock projects.  In this we have “Clock Four” – a scrolling text clock. After examining some Freetronics Dot Matrix Displays in the stock, it occurred to me that it would be neat to display the time as it was spoken (or close to it) – and thus this the clock was born. It is a quick project – we give you enough to get going with the hardware and sketch, and then you can take it further to suit your needs.

Hardware

You’ll need three major items – An Arduino Uno-compatible board, a real-time clock circuit or module using either a DS1307 or DS3232 IC, and a Freetronics DMD. You might want an external power supply, but we’ll get to that later on.

The first stage is to fit your real-time clock. If you are unfamiliar with the operation of real-time clock circuits, check out the last section of this tutorial. You can build a RTC circuit onto a protoshield or if you have a Freetronics Eleven, it can all fit in the prototyping space as such:

If you have an RTC module, it will also fit in the same space, then you simply run some wires to the 5V, GND, A4 (for SDA) and A5 (for SCL):

By now I hope you’re thinking “how do you set the time?”. There’s two answers to that question. If you’re using the DS3232 just set it in the sketch (see below) as the accuracy is very good, you only need to upload the sketch with the new time twice a year to cover daylight savings (unless you live in Queensland). Otherwise add a simple user-interface – a couple of buttons could do it, just as we did with Clock Two. Finally you just need to put the hardware on the back of the DMD. There’s plenty of scope to meet your own needs, a simple solution might be to align the control board so you can access the USB socket with ease – and then stick it down with some Sugru:

With regards to powering the clock – you can run ONE DMD from the Arduino, and it runs at a good brightness for indoor use. If you want the DMD to run at full, retina-burning brightness you need to use a separate 5 V 4 A power supply. If you’re using two DMDs – that goes to 8 A, and so on. Simply connect the external power to one DMD’s terminals (connect the second or more DMDs to these terminals):

The Arduino Sketch

You can download the sketch from here. Please use IDE v1.0.1 . The sketch has the usual functions to set and retrieve the time from DS1307/3232 real-time clock ICs, and as usual with all our clocks you can enter the time information into the variables in void setup(), then uncomment setDateDs1307(), upload the sketch, re-comment setDateDs1307, then upload the sketch once more. Repeat that process to re-set the time if you didn’t add any hardware-based user interface.

Once the time is retrieved in void loop(), it is passed to the function createTextTime(). This function creates the text string to display by starting with “It’s “, and then determines which words to follow depending on the current time. Finally the function drawText() converts the string holding the text to display into a character variable which can be passed to the DMD.

And here it is in action:

Conclusion

This was a quick project, however I hope you found it either entertaining or useful – and another random type of clock that’s easy to reproduce or modify yourself. We’re already working on another one which is completely different, so stay tuned.

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The post Project: Clock Four – Scrolling text clock appeared first on tronixstuff.



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook