Hi!
Where is located DIN and LOAD pin on arduino mega2560 ?
As far as i understand CLK is on 52.
I need to connect arduino to max7219...
If this can be set thrue SW, please share lib that i can use for this purposes.
Regards !
Hi!
Where is located DIN and LOAD pin on arduino mega2560 ?
As far as i understand CLK is on 52.
I need to connect arduino to max7219...
If this can be set thrue SW, please share lib that i can use for this purposes.
Regards !
You are going about this backwards.
You choose a library to use for your LED display.
How about this one:
Jimmy
Your understanding is incorrect.
You can use any pins you want. Don't pick 0, 1, or 13.
Suggest you just use SPI to talk to the 7219.
50 MISO
51 MOSI
52 SCK
53 SS
#include <SPI.h>
#define NOP asm volatile ("nop")
// Thanks Nick Gammon
/*
Arduino MAX7219
SS 10 LOAD 12
MOSI 11 DIN 1
MISO 12 No Connection
SCK 13 CLK 13
Character bit patterns
See: http://gammon.com.au/Arduino/Temperature_Monitor.ino
*\
/*
// .abcdefg
// 76543210
'0' = 0b01111110
'1' = 0b00110000
'2' = 0b01101101
'3' = 0b01111001
'4' = 0b00110011
'5' = 0b01011011
'6' = 0b01011111
'7' = 0b01110000
'8' = 0b01111111
'9' = 0b01111011
// .abcdefg
// 76543210
'-' = 0b00000001
'A' = 0b01110111
'B' = 0b01111111
'b' = 0b00011111
'c' = 0b00001101
'C' = 0b01001110
'D' = 0b01111110
'd' = 0b00111101
'E' = 0b01001111
'F' = 0b01000111
'h' = 0b00010111
'H' = 0b00110111
'i' = 0b00010000
'J' = 0b01111100
'j' = 0b00011000
'L' = 0b00001110
'O' = 0b01111110
'o' = 0b00011101
'P' = 0b01100111
'r' = 0b00000101
'S' = 0b01011011
't' = 0b00001111
'U' = 0b00111110
'u' = 0b00011100
'Y' = 0b00111011
' ' = 0b00000000
'I' = 0b00110000
'!' = 0b11100000
'"' = 0b01000010
''' = 0b01000000
'[' = 0b01001110
']' = 0b01111000
',' = 0b00000100
'.' = 0b10000000
'?' = 0b01100101
'=' = 0b00001001
'_' = 0b00001000
'\' = 0b00010010
'/' = 0b00100100
*/
// --A--
// | |
// F B
// | |
// --G--
// | |
// E C
// | |
// --D--
// (DP)
unsigned long timer1;
byte dp = 0;
unsigned long lastmillis = 0UL;
unsigned long i = 00000000ul;
//unsigned long i= 9999000ul;
//unsigned long nbr = 99999999ul; //(8 digits) largest number before overflow
unsigned long nbr = 9999999ul; //(7 digits) largest number before overflow
//7219 registers
const byte MAX7219_REG_NOOP = 0x0;
// codes 1 to 8 are the digit positions 1 to 8
const byte MAX7219_REG_DECODEMODE = 0x9;
const byte MAX7219_REG_INTENSITY = 0xA;
const byte MAX7219_REG_SCANLIMIT = 0xB;
const byte MAX7219_REG_SHUTDOWN = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
void sendByte (const byte reg, const byte data)
{
digitalWrite (SS, LOW); //enable 7219
SPI.transfer (reg);
SPI.transfer (data);
digitalWrite (SS, HIGH); //disable 7219
} // end of sendByte
void setup ()
{
lastmillis = millis();
SPI.begin ();
// SPI.setBitOrder(MSBFIRST); // MAX7219 requires most signifigant bit first
sendByte (MAX7219_REG_SCANLIMIT, 7); // show 8 digits zero relative
// Change next line to 0xFF if you want all positions to display a number
sendByte (MAX7219_REG_DECODEMODE, 0x7F); // in the MSD use bit patterns not digits
sendByte (MAX7219_REG_DISPLAYTEST, 0); // no display test
sendByte (MAX7219_REG_INTENSITY, 0xA); // character intensity: range: 0 to 15
sendByte (MAX7219_REG_SHUTDOWN, 1); // not in shutdown mode (ie. start it up)
} // end of setup
void number (const unsigned long num)
{
char buf [9]; //buf[0] is MSD, buf[7] is LSD
sprintf (buf, "%8ld", min (max (num, 0), 99999999)); // no leading 0s
// sprintf (buf, "%08ld", min (max (num, 0), 99999999)); // add leading 0s
// send all 8 positions
for (int digit = 0; digit < 8; digit++)
{
byte c = buf [digit]; //get the next character
if (c == ' ' ) // if this is a blank get the code for a blank
{
c = 0xF; // code for a blank
}
else
{
c -= '0'; //change the character to a number
}
//turn on the decimal point to act as a comma if > 999 or 999999
if (digit == 1 & num > 999999 || digit == 4 & num > 999)
{
c |= 0b10000000; // this adds the dp at >999 and >999999
}
//if we have we overflowed the maximum count turn on all the dp to indicate this
if (num >= nbr)
{
c |= 0b10000000; // this adds the dp at oerflow
}
//display the alpha character in the MSD it it's time to
if (digit == 0) //comment out this 'if' section if you want the MSD used as a digit
{ //and set DECODEMODE to 0xFF for all digits used as numbers
// .abcdefg //0x7F for left-hand digit used as a character
// 76543210
c = 0b01001110; //the letter C is printed in the MSD position to indicate "Counter" mode
// this toggles the MSD dp so on a non changing display it shows things are still bing updated
if (dp)
{
// .abcdefg
c |= 0b10000000; //this adds the dp if it is time to turn on the MSD dp
}
}
// lets send the byte to the 7219
sendByte (8 - digit, c); //reverse the digit order on LArryDs PCB and display the string
// sendByte (, c); // use with bubble-licous
}
} // end of number
void loop ()
{
if ( millis() - lastmillis >= 500UL)
{
dp = !dp; //used to toggle the dp in the MSD every 1/2 second
//to show display is still being updated when the count has stopped
lastmillis = millis();
}
noInterrupts(); //disable interrupts so micros() and mills() don't effect things
NOP; //delay 62.5ns NOP is a MACRO, i.e. asm volatile ("nop")
NOP; //delay 62.5ns
NOP; //delay 62.5ns
interrupts(); //enable interrupts
//each NOP gives 62.5ns delay
//Can also do:
// asm("nop\n"
// "nop\n");
if(millis()- timer1 >= 100)
{
timer1 = millis();
i++;
}
number (i);
//number (12345678);
} // end of loop
.
Thnx all for reply.
Maybe it would not be unwise to share part of schematics that will be used for led panel.
Please take a look at left upper corner where are the outputs from load, clk, din.
SPI:
Arnix
Did you look at the library I mentioned? It's all explained. There's even a Arduino Playground article about the 7219.
Jimmy