Go Down

Topic: Problems: Control 16x16 LED RGB Matrix (Sparkfun) (Read 2267 times) previous topic - next topic

scrambler

Mar 15, 2010, 12:02 am Last Edit: Mar 15, 2010, 02:05 am by scrambler Reason: 1
1 Arduino Duemilanove
4 LED Matrix Backpack - Serial Interface - Red/Green/Blue (http://www.sparkfun.com/commerce/product_info.php?products_id=760)

I need to connect 4 matrix leds to make it look like a 16x16, but in the example i'm gonna try to run 2 matrix.
The code i've attached has the timings established by the datasheet, it is possible than some 'times' are bigger for avoid problems. the code follows this pattern.

Necesito conectar 4 matrix led para apentar 16x16, pero en el ejemplo intentaré hacer funcionar 2 matrix
EL código que adjunto cumple con los tiempos establecidos por el datasheet, algunos tiempos puede que sean más grandes para no tener problamas, el codigo sigue este patrón.

CHIPSELECT LOW
500ms
Send 64 bytes
CHIPSELECT ON
500 ms
10 ms
CHIPSELECT LOW
500ms
Send 64 bytes
CHIPSELECT ON
500 ms

To work properly the screens, I will send via SPI "% 2" to indicate that there are 2 matrix

Para que funcionen correctamente las pantallas enviaré vía SPI "%2" para indicar que existen 2 matrix


Quote

// Simple program to test using the Arduino with the RGB Matrix
// & Backpack from Sparkfun. Code is a combination of Heather Dewey-Hagborg,
// Arduino Forum user: Little-Scale, and // Daniel Hirschmann. Enjoy!
//
// The Backpack requires 125Khz SPI, which is the slowest rate
// at which the Arduino's hardware SPI bus can communicate at.
//
// We need to send SPI to the backpack in the following steps:
// 1) Activate ChipSelect;
// 2) Wait 500microseconds;
// 3) Transfer 64bytes @ 125KHz (1 byte for each RGB LED in the matrix);
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds
// Repeat however often you like!


#define CHIPSELECT 10//ss
#define CHIPSELECT2 10//ss
#define SPICLOCK  13//sck
#define DATAOUT 11//MOSI / DI
#define DATAIN 12//MISO / DO

//Define the "Normal" Colors
#define BLACK  0
#define RED  0xE0
#define GREEN  0x1C
#define BLUE  0x03
#define ORANGE  RED|GREEN
#define MAGENTA  RED|BLUE
#define TEAL  BLUE|GREEN
#define WHITE (RED|GREEN|BLUE)-0xA0


char spi_transfer(volatile char data)
{
SPDR = data;                    // Start the transmission
while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
{
};
}

void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device


SPCR = B01010001;             //SPI Registers
SPSR = SPSR & B11111110;      //make sure the speed is 125KHz

/*
SPCR bits:
7: SPIEE - enables SPI interrupt when high
6: SPE - enable SPI bus when high
5: DORD - LSB first when high, MSB first when low
4: MSTR - arduino is in master mode when high, slave when low
3: CPOL - data clock idle when high if 1, idle when low if 0
2: CPHA - data on falling edge of clock when high, rising edge when low
1: SPR1 - set speed of SPI bus
0: SPR0 - set speed of SPI bus (00 is fastest @ 4MHz, 11 is slowest @ 250KHz)
*/

clr=SPSR;
clr=SPDR;
delay(10);


 digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack 1
delayMicroseconds(500);
 spi_transfer('%');
 spi_transfer(2);  
 delayMicroseconds(100);
digitalWrite(CHIPSELECT2,HIGH); // disable the ChipSelect on the backpack 2
 delayMicroseconds(500);
}


void loop()
{
 delay(100);
 int index = 0;
 digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack 1
 delayMicroseconds(500);
 for (int i=0;i<8;i++) for (int j=0;j<8;j++)
 {
   spi_transfer(GREEN);
   index++;

 delay(2);
// There are only 8 colours available to the matrix with the
// backpack, so this will present 1 colour per column on the matrix
 }


 digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack 1
 delayMicroseconds(500);
 index = 0; // write the same on bp2 or extend the data array and don't set inde to 0 here
 digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack 2
 delayMicroseconds(500);
 for (int i=0;i<8;i++) for (int j=0;j<8;j++)
 {
   spi_transfer(BLUE);
     index++;

 delay(2);
// There are only 8 colours available to the matrix with the
// backpack, so this will present 1 colour per column on the matrix
 }

 digitalWrite(CHIPSELECT,HIGH);
 delayMicroseconds(500);
}




When you connect plug arduino in, the first upload the code and the screens often works 90% of the time, but the problem is when you push the resset button then the screens, then the screens are in a wrong state and from this moment LEDs do not work properly.
El problema:
Cuando conectas arduino al corriente electrico, la primera carga del codigo i de las pantallas suele funcionar un 90% de las veces pero el problema surge cuando pulsas el botón de reset del arduino, entonces las pantallas están en un estado erroneo y apartir de aquí los leds no se encienden correctamente:




Order & Incorrect order


Does anyone have a solution? this is for project university, thanks.


Best Regards

scrambler


Go Up