The LED matrix is used to display information about the bus which last arrived on a bus stop. It is connected to the arduino board on each bus stop. It is used in this prototype for display purposes. It uses SPI communication to send the data from the arduino to the LED matrix. It is a 8X8 matrix and we can set all the 64 bits individually for displaying the bus number.
It can be directly connected to the hardware SPI pins of the arduino but since we were having problems due to the MP3 shield connected on the SPI as well, we had to use software SPI by bit banging the pins to emulate SPI communication. The MP3 shield was sending trash values to the LED matrix due to which it was not functioning properly. But for normal purposes, it might not be necessary unless there are problems like the ones we faced.
Connections with Arduino:
#define DATAOUT 11//MOSI - DI
#define SPICLOCK 13//sck - SCK
#define SLAVESELECT 10//ss - CS
char data [64] =
{
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1
};
void setup()
{
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);//Activate SPI HW, Master Mode, diviser Clock par 16
pinMode(DATAOUT, OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH);
Serial.begin(9600);
}
void loop()
{
transfer(data);
}
char spi_transfer(volatile char data)
{
SPDR = data;
while (!(SPSR & (1<<SPIF)))
{
};
return SPDR;
}
void transfer(char myData[64]) {
digitalWrite(SLAVESELECT, LOW);
for(int i=0; i<64; i++){
spi_transfer(myData[i]);
}
digitalWrite(SLAVESELECT, HIGH);
delayMicroseconds(500);
}
No comments:
Post a Comment