I'm new on the forum and new to Arduino. I do have some electrical experience (Old Ham Radio Operator from back when you built your own stuff) but programming is limited (College 50+ years ago, Fortran IV). I hope I'm not getting the cart too far ahead of the horse as they say.
Ok, now for the project and questions.
I purchased an Elegoo Uno (Small starter kit) and some Max7219 8X8 matrix boards. Four of the 8x8's are ALAMSCN and three are HiLetgo. They are currently in the mail.
The end project is to make a scoreboard using four of the matrix boards and push buttons to increase or decrease the numbers for two teams. Each score will go to 21. One matrix for integers and one for tens, two boards for each team. I want the capability to with the push of a button increment the score by one and if it goes too far ahead because of too many button presses to be able to subtract from the number using another button. IOW two buttons for each score. After much reading I found that I will need a larger power source for the matrix boards than the UNO. In my project I want it to be portable (independent of AC power ie wall wart), so...
I'm thinking of using something like a remote cell phone supply ie 5V 10000 mah to power all units. It is small enough but should supply the power needed. Good idea or not?
I'm thinking that I will be able to run a negative/grd form the supply to both boards, UNO and the set of four Matrix boards. and the V+ to the VCC on the matrix's and to the power jack input on the UNO. Good idea or not?
This will be a project completed with baby steps. I will first work on getting an LED or two to light up on the matric then a number on one matrix, then get the numbers set up to increment using loops and then go on to a second matrix for 0-2, When the two are working, it should not be too difficult to add the other two to the system.
I hope I have been clear enough on this and will be adding to the post when I get the parts and start my adventure. Thank you for your time and any suggestions.
Thanks for your response @oldcurmudgeon . I'm not sure I understand or maybe I wasn't clear with what I was planning. One V+ from the power source would go to the DC Input jack and a negative /grd would also go to that input. That would be regulated to the UNO because of the regulator??
Another V+ lead from the power source would go to the VCC of the 8x8 Matrix with the negative lead going to the Grd terminal on the UNO and the Grd on the 8x8. Then in effect I would have two or a split power source to supply the power to the UNO and the added current needed for the 4 Matrix boards.
Or can the UNO board be powered from the 5V terminal and the Grd without causing a problem with the idea that the power source (Phone external power supply) is regulated enough to feed directly to the +5V terminal? The reason for going to the DC input jack was to go through the regulator on the board to power the UNO and then using the separate leads going directly to the Matrix to supply the additional current that will be required.
@oldcurmudgeon Sorry, I just reread your response and see that I missed the "7". I guess that means that I will need to used the +5V and GRD on the UNO board for input to the UNO, but I think I should still supply the Matrix directly from the power source and not from the UNO. Yes or No??
Yes, you should power the matrix directly from the power source. The Arduino onboard regulator can only handle the processors and a small additional load.
OK, I think I have a pretty good handle on the power source, but now I am at the next stage of planning. Two sets of 8x16 dot matrix LED modules (Max7219 8x8 Matrix joined). So I have two 8x8's and I want to display incremented numbers 0-21.
Would it be better to code them so they print 00, 01, 02.....21 or 0, 1, 2, 3.......21? I am thinking that I will be able to increment with a variable ie S++ or similar in a loop that will increment with the push of a button. I want the single digits to diplay only on the right 8x8 and the double digits to have the tens place on the left 8x8 and the ones place on the right 8x8.
Next I am assuming that I will be able to address the other two 8x8's separately using another button and I/O instructions. IOW a second set of two 8x8's independent of the first.
As stated in the beginning of this thread it is a scoreboard for two teams with scores going from 0-21. I haven't written any code yet or tried anything, but have been formulating the process in my head for "if" statements, etc. My plan is to first get one 8x8 incrementing 0-9 with a button push and then going to two for the 0-21. If I get one set going, then it will be work on the second.
You need to figure out how you want to configure the displays. Daisy chaining them uses fewer pins, but adds a little complexity to the code.
You will want to use a library to interface to the display. There are several - I would say take a look at MD_MAX72XX. It is a bit more complex than some of the others, but it will handle several types of displays (there are multiple ways the matrix and the max7219 can be connected on the PC board). It has examples and tests for the possibilities. It can be downloaded with the library manager and More Info will get you to the documentation.
Another thing to look for is a button library. Buttons are a horrible thing to use because of the contact bounce. I don't have a recommendation - I try to avoid buttons. If I have to use one I do my own minimal debounce.
Thanks, I plan to Daisy Chain two 8x8 for one team score and another two 8x8 for the other team score.
I have been looking at the MD_MAX72XX sketches, so I guess I am on the right track. Ha! In fact, I have installed MD_MAX72XX and MD_Parola to examine for use.
I had not realized all of the documentation available with the sketches until I went back and took another look. Thanks for letting me know about the extra information.
I have been reading about how button bounce can be a problem and scanned over some solutions. I really don't know another way to advance the scores without using buttons, so unless I can come up with something else, I guess solving the button bounce issue will be in my future. Ha!
Continuing with this project I have achieved a little more progress. I started with one Max7219 8x8 matrix and have accomplished getting numbers to scroll with a 2 second delay, however I am only incrementing from "1" up and I would like to have "0" displayed first. How can I do this? I will eventually want to have it increment as stated before by a button push, but that is in the future. One step at a time. Ha!
My code is attached. TIA
//First step using one 8x8 Max7219 for scoreboard. Now trying to increment using variable.
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Uncomment according to your hardware type
// #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 1
#define CS_PIN 10
// Create a new instance of the MD_Parola class with hardware SPI connection
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
// Intialize the object
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15)
myDisplay.setIntensity(8);
// Clear the display
myDisplay.displayClear();
}
int a = 0;
void loop() {
a += 1;
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(a);
delay(2000);
}
You will probably have to convert to character string and prepend the 0 if the number is less than 9. I don't see that the simple print() has a way to specify leading zeros.
I think that I wasn't as clear as I should have been.
I am looking to increment the numbers from 0 - 21. As my code is written now it is only displaying 1- 100+. No 0 at the start. I want 0, 1, 2, 3, 4, .....
From your answer I think you thought I wanted to print 01, 02, 03, 04..... If I am wrong with what you answered, please let me know. To be honest, I'm not sure of the term prepend, but I assumed it means to put a zero in front of the 1-9.
Thanks, I tried changing my code with your suggestion, however I am just getting "10" on the display. No loop or other numbers. What might I be doing wrong?
Thanks again, I figured out what was wrong. The code was missing the second closing squigly bracket to close the statement. Inserted it after the delay(2000); and it worked fine.
Now my next quest is to get the loop to only increment with the push of a button.
Here is the Sketch and Schematic I am working with. I am trying to figure out how to increment the numbers by one on a button push. Pull_up setup. When the sketch is started, a "0" is displayed until the button is pushed for a short time. Then the LED lights (an indication that the button is working) and then after a delay the numbers start incrementing without stopping and the LED stays on until "21" is displayed and them it goes off.
To a newbie like me, it seems as if once the buttonPin goes LOW and triggers the loop to start but it never detects the HIGH state of the button until the loop runs completely through to "21". My questions are:
Am I on the right track using IF, Else if statements to control the loop?
If not, can someone point me in the right direction? Do I need to forget the loop and try to work on individual code for each number?
Is there a way to use the "Continue" to get past the loop?
It was brought to my attention that the switch could be wired incorrectly, however in actuallity the switch is wired correctly the schematic is wrong. Pin12 (Button state pin) is actually wired between the 10K resistor and the Button Switch. Sorry
The schematic I previously posted is wrong. The Pin12 is connected between the 10K resistor and the switch.
Sorry, I forgot the proper way to post the code on the forum. Thanks Paul, I do see why it is doing what it is. The "0" prints as it should on start up as it reads the Else if and prints scoreA as "0" Then when the button is pressed, it reads the IF and goes into the increment loop and completes it to "21" before it checks the button state again. I will have to give this some more thought on how to increment only one number at a time with a button push.
Again, Thanks @Paul_B for enlightening me on the loops. I had previously briefly looked at the reference you just gave me, but I will spend more time looking at it this time. Ha!
Here is the code I had previously loaded:
//O-21 incrementing for scoreboard on two 8x8 for now.
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Uncomment according to your hardware type
// #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 2
#define CS_PIN 10
// Create a new instance of the MD_Parola class with hardware SPI connection
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int scoreA;
int buttonPin = 12;
int ledPin = 8;
int buttonRead;
int dt = 2000;
void setup() {
// Intialize the object
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15) 0 dim - 15 bright
myDisplay.setIntensity(0);
// Clear the display
myDisplay.displayClear();
//initialize LED pin as an output:
pinMode(ledPin, OUTPUT);
//initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
buttonRead = digitalRead(buttonPin);
//read the state of the pushbutton value:
//check if the bushbutton is pressed. If it is, the button state is LOW:
if (buttonRead == LOW)
{
delay(100);
for (scoreA = 0; scoreA < 21; scoreA++) {
digitalWrite(ledPin, HIGH); //Added to see button state
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(scoreA);
delay(dt);
}
}
else if (buttonRead == HIGH)
delay(100);
{
digitalWrite(ledPin, LOW); //Added to see button state
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(scoreA);
delay(dt);
}
}
Thanks. Maybe I wasn't clear enough in what I wrote on a Pull_up, but I am not using the built in INPUT_PULLUP. I am using a 10K resistor, switch, etc and I don't think it is coded for the INPUT_PULLUP, but I am new.