En el siguiente tutorial vamos a trabajar con un display formado por una matriz de leds, concretamente el DLO7135 de Siemens.
He dividido el tutorial en dos partes para que no quede muy extenso. Puedes ver la segunda parte aquí.
El DLO7135 es un display inteligente, formado por una matriz de leds de 5x7.
Lo de inteligente viene porque el display tiene integrado un generador de caracteres, programado para mostrar los 96 caracteres ASCII en función del código binario que se envíe. Ver datasheet para más información.
En función de los datos que enviemos por los pines D0 a D6 la matriz mostrará el caracter ASCII correspondiente.
/*
Proyecto 37 - Siemens DLO7135 5x7 Dot Matrix Intelligent Display
Based on the original sketch by Bajazzo http://forum.arduino.cc/index.php?topic=259086.0
Modified by Angel M. https://sites.google.com/site/angmuz/home
Muestra el texto "Arduino"
*/
int D0=9;
int D1=8;
int D2=7;
int D3=6;
int D4=5;
int D5=4;
int D6=3;
int CE=13;
int WR=12;
int BL0=10;
int BL1=11;
void setup()
{
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
pinMode(D6,OUTPUT);
pinMode(CE,OUTPUT);
pinMode(WR,OUTPUT);
pinMode(BL0,OUTPUT);
pinMode(BL1,OUTPUT);
digitalWrite(BL0,LOW);
digitalWrite(BL1,HIGH); // Half Brightness
}
void loop()
{
digitalWrite(CE,LOW); // Chip Enable
digitalWrite(WR,LOW); // Write Enable
// "A"
digitalWrite(D0,HIGH);
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
digitalWrite(D4,LOW);
digitalWrite(D5,LOW);
digitalWrite(D6,HIGH);
delay (250);
// "r"
digitalWrite(D0,LOW);
digitalWrite(D1,HIGH);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
digitalWrite(D4,HIGH);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
// "d"
digitalWrite(D0,LOW);
digitalWrite(D1,LOW);
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
// "u"
digitalWrite(D0,LOW);
digitalWrite(D1,HIGH);
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
// "i"
digitalWrite(D0,HIGH);
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
// "n"
digitalWrite(D0,LOW);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
// "0"
digitalWrite(D0,HIGH);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
digitalWrite(D4,LOW);
digitalWrite(D5,HIGH);
digitalWrite(D6,HIGH);
delay (250);
digitalWrite(CE,HIGH);
delay (1000);
digitalWrite(CE,LOW);
delay (1500);
}
Como se puede apreciar en el esquema anterior, la conexión directa del display con Arduino necesita de muchas salidas digitales.
En el siguiente esquema vamos a utilizar un 74HC595. Este circuito integrado es un Registro de Desplazamiento o Shift Register y sirve para controlar ocho salidas digitales a la vez con unos poco pines del Arduino, mediante la conversión serie-paralelo de 8 bits.
Tanto el esquema como el sketch que lo acompaña están basados en el tutorial Serial to Parallel Shifting-Out with a 74HC595
El siguiente sketch muestra los 96 caracteres ASCII programados en el display.
/*
Proyecto 37
Siemens DLO-7135 5x7 Dot Matrix Intelligent Display
Show 96 ASCII Characters
Example with 74HC595N Shift Register
Based on the original sketch by Carlyn Maw,Tom Igoe, David A. Mellis
https://www.arduino.cc/en/Tutorial/ShiftOut
Modified by Angel M.
https://sites.google.com/site/angmuz/home
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 8;
// To set the Brightness via Arduino
int BL0 = 12;
int BL1 = 13;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(BL0, OUTPUT);
pinMode(BL1, OUTPUT);
//Serial.begin(9600);
//Serial.println("start");
// Full Brightness
digitalWrite(BL0,HIGH);
digitalWrite(BL1,HIGH);
}
void loop() {
// El rango de caracteres ASCII va desde 32 hasta 127 en decimal.
// Mas informacion en el Datasheet DLO-7135
for (int numberToDisplay = 32; numberToDisplay < 128; numberToDisplay++) {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
//Serial.println(numberToDisplay);
delay(500);
}
}
En el siguiente ejemplo veremos como mostrar texto. Para ello consultamos en el datasheet el código hexadecimal de los caracteres ASCII que deseamos sacar por el display.
/*
Proyecto 37
Siemens DLO-7135 5x7 Dot Matrix Intelligent Display
Displays "Hello World" in a Single Matrix
Example with 74HC595N Shift Register
Based on the original sketch by Carlyn Maw and Tom Igoe
https://www.arduino.cc/en/Tutorial/ShiftOut
Modified by Angel M.
https://sites.google.com/site/angmuz/home
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 8;
//holders for infromation you're going to pass to shifting function
byte data;
byte dataArray[11];
// To set the Brightness via Arduino
int BL0 = 12;
int BL1 = 13;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(BL0, OUTPUT);
pinMode(BL1, OUTPUT);
// Full Brightness
digitalWrite(BL0,HIGH);
digitalWrite(BL1,HIGH);
//Start Serial for debuging purposes
Serial.begin(9600);
dataArray[0] = 0x48; // H
dataArray[1] = 0x45; // E
dataArray[2] = 0x4C; // L
dataArray[3] = 0x4C; // L
dataArray[4] = 0x4F; // O
dataArray[5] = 0x57; // W
dataArray[6] = 0x4F; // O
dataArray[7] = 0x52; // R
dataArray[8] = 0x4C; // L
dataArray[9] = 0x44; // D
}
void loop() {
for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
data = dataArray[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(500);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
A continuación vamos a añadir un segundo display con el correspondiente registro 74HC595. Ahora tenemos el doble de salidas digitales, manteniendo las mismas señales de control.
En el siguiente ejemplo los dos displays muestran 96 caracteres ASCII.
/*
Proyecto 37
Siemens DLO-7135 5x7 Dot Matrix Intelligent Display
Show 96 ASCII Characters in Two Matrix
Example with two 74HC595N Shift Registers
Based on the original sketch by Carlyn Maw,Tom Igoe
https://www.arduino.cc/en/Tutorial/ShftOut21
Modified by Angel M.
https://sites.google.com/site/angmuz/home
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 8;
// To set the Brightness via Arduino
int BL0 = 12;
int BL1 = 13;
void setup() {
//Start Serial for debuging purposes
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(BL0, OUTPUT);
pinMode(BL1, OUTPUT);
// Full Brightness
digitalWrite(BL0,HIGH);
digitalWrite(BL1,HIGH);
}
void loop() {
//count up routine
for (int j = 32; j < 127; j++) {
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//count up on GREEN LEDs
shiftOut(dataPin, clockPin, j);
//count down on RED LEDs
shiftOut(dataPin, clockPin, 255-j);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(1000);
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
En el siguiente ejemplo, cada uno de los displays muestra un texto diferente.
/*
Proyecto 37
Siemens DLO-7135 5x7 Dot Matrix Intelligent Display
Displays "Hello World" in Matrix nº 1
Displays "IRE RAYOS X" in Matrix nº 2
Example with Two 74HC595N Shift Registers
Based on the original sketch by Carlyn Maw and Tom Igoe
https://www.arduino.cc/en/Tutorial/ShftOut23
Modified by Angel M.
https://sites.google.com/site/angmuz/home
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 8;
//holders for infromation you're going to pass to shifting function
byte dataRED;
byte dataGREEN;
byte dataArrayRED[10];
byte dataArrayGREEN[10];
// To set the Brightness via Arduino
int BL0 = 12;
int BL1 = 13;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(BL0, OUTPUT);
pinMode(BL1, OUTPUT);
// Full Brightness
digitalWrite(BL0,HIGH);
digitalWrite(BL1,HIGH);
//Start Serial for debuging purposes
Serial.begin(9600);
dataArrayRED[0] = 0x48; // H
dataArrayRED[1] = 0x45; // E
dataArrayRED[2] = 0x4C; // L
dataArrayRED[3] = 0x4C; // L
dataArrayRED[4] = 0x4F; // O
dataArrayRED[5] = 0x57; // W
dataArrayRED[6] = 0x4F; // O
dataArrayRED[7] = 0x52; // R
dataArrayRED[8] = 0x4C; // L
dataArrayRED[9] = 0x44; // D
dataArrayGREEN[0] = 0x49; // I
dataArrayGREEN[1] = 0x52; // R
dataArrayGREEN[2] = 0x45; // E
dataArrayGREEN[3] = 0x52; // R
dataArrayGREEN[4] = 0x41; // A
dataArrayGREEN[5] = 0x59; // Y
dataArrayGREEN[6] = 0x4F; // O
dataArrayGREEN[7] = 0x53; // S
dataArrayGREEN[8] = 0x20; // BLANK
dataArrayGREEN[9] = 0x58; // X
}
void loop() {
for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
dataRED = dataArrayRED[j];
dataGREEN = dataArrayGREEN[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataGREEN);
shiftOut(dataPin, clockPin, dataRED);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(500);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
Añadimos un tercer display.
En el siguiente sketch cada display muestra un mensaje diferente. El texto que muestra cada display depende del orden en que pongamos las siguientes líneas de código en el sketch.
//move 'em out
shiftOut(dataPin, clockPin, dataBLUE); // Display 3
shiftOut(dataPin, clockPin, dataGREEN); // Display 2
shiftOut(dataPin, clockPin, dataRED); // Display 1
A continuación el sketch
/*
Proyecto 37
Siemens DLO-7135 5x7 Dot Matrix Intelligent Display
Displays "HelloWorld" in Matrix nº 1
Displays "IRERAYOS X" in Matrix nº 2
Displays "HOLA MUNDO" in Matrix nº 3
Example with Three 74HC595N Shift Registers
Based on the original sketch by Carlyn Maw and Tom Igoe
https://www.arduino.cc/en/Tutorial/ShftOut23
Modified by Angel M.
https://sites.google.com/site/angmuz/home
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 7;
////Pin connected to DS of 74HC595
int dataPin = 8;
//holders for infromation you're going to pass to shifting function
byte dataRED;
byte dataGREEN;
byte dataBLUE;
byte dataArrayRED[10];
byte dataArrayGREEN[10];
byte dataArrayBLUE[10];
// To set the Brightness via Arduino
int BL0 = 12;
int BL1 = 13;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(BL0, OUTPUT);
pinMode(BL1, OUTPUT);
// Full Brightness
digitalWrite(BL0,HIGH);
digitalWrite(BL1,HIGH);
//Start Serial for debuging purposes
Serial.begin(9600);
dataArrayRED[0] = 0x48; // H
dataArrayRED[1] = 0x45; // E
dataArrayRED[2] = 0x4C; // L
dataArrayRED[3] = 0x4C; // L
dataArrayRED[4] = 0x4F; // O
dataArrayRED[5] = 0x57; // W
dataArrayRED[6] = 0x4F; // O
dataArrayRED[7] = 0x52; // R
dataArrayRED[8] = 0x4C; // L
dataArrayRED[9] = 0x44; // D
dataArrayGREEN[0] = 0x49; // I
dataArrayGREEN[1] = 0x52; // R
dataArrayGREEN[2] = 0x45; // E
dataArrayGREEN[3] = 0x52; // R
dataArrayGREEN[4] = 0x41; // A
dataArrayGREEN[5] = 0x59; // Y
dataArrayGREEN[6] = 0x4F; // O
dataArrayGREEN[7] = 0x53; // S
dataArrayGREEN[8] = 0x20; // BLANK
dataArrayGREEN[9] = 0x58; // X
dataArrayBLUE[0] = 0x48; // H
dataArrayBLUE[1] = 0x4F; // O
dataArrayBLUE[2] = 0x4C; // L
dataArrayBLUE[3] = 0x41; // A
dataArrayBLUE[4] = 0x20; // BLANK
dataArrayBLUE[5] = 0x4D; // M
dataArrayBLUE[6] = 0x55; // U
dataArrayBLUE[7] = 0x4E; // N
dataArrayBLUE[8] = 0x44; // D
dataArrayBLUE[9] = 0x4F; // O
}
void loop() {
for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
dataRED = dataArrayRED[j];
dataGREEN = dataArrayGREEN[j];
dataBLUE = dataArrayBLUE[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataBLUE); // Display 3
shiftOut(dataPin, clockPin, dataGREEN); // Display 2
shiftOut(dataPin, clockPin, dataRED); // Display 1
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(500);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
Arduino Tutorials: Serial to Parallel Shifting-Out with a 74HC595
Descarga los sketch y esquemas en un .zip aquí abajo.