Hi!
I'm building a wack-a-mole game with arduino and inorder to keep track of the score I made the decision to use two seven segment displays. These have a forward voltage per segment of 7.2v and draw 10mA of current per segment, so I use highside drivers to supply the displays with the necessary voltage. This seems to work just fine but whenever I upload code to the arduino (or when I reset it or unplug power to it), the max 7219 behaves in a "strange" way. Most of the time the displays flickers and display two 8's (with low brightness) and on rare occasions, the program actually works. It's hard to describe with words, so I created this video:
As you can see, sometimes the screen freezes and i'm unsure of what is causing it. Here is the code the arduino is running in the video. It's just some test counter to see if the circuit works or not.
#include <SPI.h>
#define CSpin 40
void setup() {
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
digitalWrite(CSpin, HIGH);
pinMode(CSpin, OUTPUT);
SPI.begin();
digitalWrite(CSpin, LOW);//come out of shutdown
SPI.transfer(0x0C);
SPI.transfer(0x01);
digitalWrite(CSpin, HIGH);
digitalWrite(CSpin, LOW);//decode 8 digits
SPI.transfer(0x09);
SPI.transfer(0xFF);
digitalWrite(CSpin, HIGH);
for (int i = 1; i < 9; i++) {//set all digits OFF
digitalWrite(CSpin, LOW);
SPI.transfer(i);
SPI.transfer(0x0F);
digitalWrite(CSpin, HIGH);
}
digitalWrite(CSpin, LOW);//intensity MAX
SPI.transfer(0x0A);
SPI.transfer(0x0F);
digitalWrite(CSpin, HIGH);
digitalWrite(CSpin, LOW);//scan limit
SPI.transfer(0x0B);
SPI.transfer(0x01);
digitalWrite(CSpin, HIGH);
SPI.endTransaction ();
}
void loop() {
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
for (byte num = 0; num < 10; num++) {
for (byte i = 1; i < 3; i++) {
digitalWrite(CSpin, LOW);
SPI.transfer(i);
SPI.transfer(num);
digitalWrite(CSpin, HIGH);
delay(1);
}
delay(500);
}
SPI.endTransaction ();
}
The circuit itself is connected as the attached schematic below suggests. However I have not connected the pushbuttons and leds for the buttons to the breadboard as i'm testing the displays right now. I have read other forum threads about max7219s behaving in weird ways, but thus far I have not found a thread where the problem matches what i'm experiencing. Some have suggested putting a 100uF, 10uF and a 0.1uF capacitors across the max7219 Vcc and ground to smooth out ripple in the supply voltage. I have done this, but it makes no difference.
Here are some things I have thought of which are probably unrelated to this (but might be worth mentioning). I accidently applied 12v to pin 52 (SCK) or 51 (MOSI), can't remember which, but it probably caused some damage. But why does the arduino still work if thats the case? I have also noticed that whenever I connect the arduino to usb port (while leaving the rest of the circuit unpowerd), there is 4.5v ~between the Vin pin and ground. The voltage regulator (U4 in the schematic) that is connected to these pins gets hot, which doesn't make sense. Is it pushing current through the output of the voltage regulator that normally powers it?
Any help would be massively appreciated!
Jesper