Arduino counter system

arduino

#1

Hi, I’m looking for some help on a project I am doing for my major work for design and technology. The project I am doing will need to be able to connect two screens, I currently have an LED and an LCD (I assume it would be best if I get both screens to be LED or LCD? If that might affect the code?) where both screens will show a number, that will be controlled by the use of a remote that will have 3 buttons, one for up, down and reset. I currently have the standard Arduino UNO board and am unsure whether I can fit all the cables on the board itself? I do have a solderless breadboard if that can help with connecting multiple screens? I do not know how to put all the components I have together either as I have never worked with any of this kind of stuff and learning it has been extremely difficult.
I also don’t know how to code the system on the Arduino IDE 1.8.2 and if you guys have any ideas on how to do so, or have any pre written code that would fit well with my design, that would be great!
I appreciate any help, if you prefer to discuss the details on phone or so, please let me know contact details!
Thanks!
:slight_smile:


#2

Yes, if the screens were the same then the coding might be easier. It would also depend on the screens. There are lots of different LED and LCD screens.

The best way I know is to get started and go step by step;

  • use the Arduino IDE to write a sketch to flash the LED on D13 of the Uno, and test that you can make that happen; there are example sketches built in to the IDE to help, but you must also understand them,

  • write a sketch that will read buttons and flash the D13 LED in a pattern; attach the buttons to the Uno via the breadboard and test until it works; you won’t get to use exactly this code in the final product, but it is a critical step to make sure you and your sketch can read buttons,

  • write a sketch that will display a number on the LED screen; attach the LED screen to the Uno via the breadboard and test until it works; you may see a work flow pattern emerging,

  • write a sketch that will display a number on the LCD screen; attach the LCD screen to the Uno via the breadboard and test until it works,

  • try to merge the above two sketches and wiring, and test until numbers can be displayed on both types of screen at once,

  • try to merge the display sketches and the button reading sketch, and test until the screens display numbers in response to the buttons,

  • add the final intent of the product; specific numbers or whatever it is you need; note how you don’t get to do this until you’ve built everything before it.

Each step of the way you’ll need to research, look at how the buttons, LED screen, or LCD screen, are attached; what example sketches are available, and ask questions of people.

I do not know you or the screens well enough yet to predict the problems you’ll encounter; so I’ll wait to hear back. :grin:

To get an idea of the effort required; as a professional I’d budget about half an hour to an hour for each step; possibly up to three hours per screen if they are unusual, and add another six hours if both screens at once use more pins than are available. As a newcomer, you should scale those estimates up.

The above gets you a prototype. Moving into design for manufacturing is a whole 'nuther ballgame.

And have fun, it’s a fast way to learn.


#3

I got started a bit, somehow got the button to work, so I was happy with that, The only problem im facing now is that i cant figure how to connect each of the screens to the board. For the LED screen I have the Matrix display: https://www.freetronics.com.au/products/dmd-dot-matrix-display-32x16-blue#.WSlc32iGPIW and for the LCD I have the: https://www.jaycar.com.au/arduino-compatible-84x48-dot-matrix-lcd-display-module/p/XC4616 and havnt been able to find much information on how to connect them properly or maybe im doing it wrong. For the LCD especially I have been trying to do the example ‘hello world’ code but all it does is light up and not display anything. Im not sure how to connect the LED properly either :frowning: Sorry I took long to reply! been caught up with heaps of exams hope to hear from you soon


#4

G’day,

Your LED screen link has a resources section when you scroll down; this has instructions on connection, and source code libraries for making it operate.

Your LCD screen link has very limited information, but that’s because it is such a well-known display and the documentation is available from many places; for example;

Each of the products is very slightly different, but their insides are very similar. Given that it lights up you have probably got the power connected to it but your other wiring is somehow at fault. Check the other wires carefully, even testing them with a multimeter set on conductivity beep mode. You can get the same result if the sketch isn’t right in some way, so check it carefully against the wiring.

For connecting an LED to Arduino to make it blink, see

Hope that helps.


#5

Sorry its been a while, I have managed to get a working counter system with a 16x2 lcd screen and I was able to make it count up and down with two buttons connected. I tried with the 84x48 lcd that I was originally using but it was too difficult and not much was available when I looked up information on it, I got it to work and everything but didn’t understand how to code it properly with the buttons. Aside from that, I still haven’t managed to get the led screen (16x32 Matrix Display) to work with the counter, as I’m not sure how. I have been able to turn it on when connecting it directly on the arduino with a DMD with some code I found online but I’m also worried I cant fit both screens onto the board at the same time?

This is the code I wrote for the counter:

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);

int inc = 8;
int dec = 9;

int initialstate1;
int finalstate1;

int initialstate2;
int finalstate2;

int count = 0;

void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Counter : ");
lcd.setCursor(0,1);
lcd.print(count);
}

void loop()
{
// Increment Part

finalstate1 = digitalRead(inc);
if(finalstate1 != initialstate1)
{
delay(10);
finalstate1 = digitalRead(inc);
{
if(finalstate1 == HIGH)
{
count++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Counter : ");
lcd.setCursor(0,1);
lcd.print(count);
}
}
initialstate1 = finalstate1;
}

// Decrement Part

finalstate2 = digitalRead(dec);
if(finalstate2 != initialstate2)
{
delay(10);
finalstate2 = digitalRead(dec);
{
if(finalstate2 == HIGH)
{
count–;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Counter : ");
lcd.setCursor(0,1);
lcd.print(count);
}
}
initialstate2 = finalstate2;
}
}

Now I’m not too sure on how to connect the LED Dot Matrix Display 16x32, or how I can possibly connect it with the code as well, I’ll keep trying but if you or anyone else knows how to, that would be really helpful :slight_smile:


#6

Well done, you’ve got to the difficult part.

Next step, as part or my earlier long list of steps, is to figure out how to take the two sketches and merge them.

Look carefully at your prototype now, and find which pins on the Uno are free. Make a list of the pins. Call this the free list. My guess is pins 8, 9, 10, 11, 12, 13, A0, A1, A2, A3, A4, and A5.

Make a list of the in-use pins, and call that the used list. Looking at your sketch, the used list is 2, 3, 4, 5, 6 and 7. Pins 0 and 1 are used by the serial console.

From the DMD sketch, make a list of the pins that program needs. Looking at thesource code for the library, the need list is 6, 7, 8, 9, 10, 11 and 13.

Take the three lists; what you have used, what you have free, and what you need for the DMD, and sit back to try figuring out how to merge them. This is made a bit more difficult by the DMD connector which makes it harder to change which pins the DMD uses.

The conflicting pins are only 6 and 7. I could be wrong about that; you should verify everything above.

Option 1; use pins other than 6 and 7 for the LCD. Find two free pins. The A0 to A5 pins can be used as digital I/O, and the library should be fine with that. Change the sketch to use the two free pins instead of 6 and 7, run the sketch (it will fail to display anything, which is a good cross check), then disconnect from USB and power and change the wiring to match your sketch change, and then power up and see that it works. Iterate until it does.

Option 2; use pins other than 6 and 7 for the DMD. Same process in general, but you will have to replace the DMD connector with wiring, and change the DMD library. Unlike the LCD library, the DMD library doesn’t have an API for choosing pins.

Your interim goal is to have a circuit prototype that you can load with either your modified LCD sketch, or your modified DMD sketch. At this goal, each sketch should make the corresponding display work, and the other display will not work, and will not hinder.

Once you’ve done that, the next big step is merging the two sketches, which is a software engineering or computer programming task.

p.s. tools people use for lists of pins include; paper, paper prints of the Uno pinout, spreadsheet, or comment lines in a sketch.


#7

Hey Thanks for that! I was able to figure how to use analog pins like you said, and in my code put them as 14-19, and it was able to work leaving space for the DMD to fit straight onto the board where it was required (GND,13-6) and then I just moved the pins for the buttons to 2 and 3.


Now its just programming it, I’m not an expert at code :sweat_smile: but ill keep trying, if you have any ideas on how I could code the DMD to display the number that would be great but otherwise i’ll keep trying! Thanks for the help :slight_smile:


#8

Look in the Arduino IDE source file pins_arduino.h on your system and you’ll see A0 is 14, so it is better to use A0 instead of 14, because that way you’ll know what A0 means when you see it again, which won’t always be the case for 14, especially if someone else looks at your code.

So as I said, your interim goal is to have a circuit that you can load with either an LCD sketch or a DMD sketch, and each sketch should make the relevant display work. Are you there yet?

If so, and you’re happy for everyone to see, paste the two sketches here, but please surround each with a line containing three backticks (`), so that in preview it will look like this;

void setup()
{
    lcd.begin(16, 2)
    ....
}

This is to preserve indentation accurately. Professional programmers find badly indented code almost impossible to read.

Then I’ll explain the step by step process for merging the two programs.

Even better if you have a GitHub account and make a repository; I’m a heavy GitHub user, my username there is quozl. If you did this on GitHub then I would lead you through the changes using commits; which lets you see every edit I make. I’m biased, I just love working with git, and have done so for years. It makes it very easy to collaborate with other people. But if you’ve not used git or GitHub before budget an hour or two of watching videos about it.


#9

I have so far only been able to get the LCD screen to work as a counter, I havn’t been able to make a sketch with the DMD separately or with the LCD to work. Here the sketch again with the LCD:

#include <LiquidCrystal.h>
LiquidCrystal lcd(14,15,16,17,18,19);

int inc = 2;
int dec = 3;

int initialstate1;
int finalstate1;

int initialstate2;
int finalstate2;

int count = 0;

#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_Black_16_ISO_8859_1.h"

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

void setup() 
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Counter : ");
  lcd.setCursor(0,1);
  lcd.print(count);
}

void loop()
{
  // Increment Part

  finalstate1 = digitalRead(inc);
  if(finalstate1 != initialstate1)
  {
    delay(10);
    finalstate1 = digitalRead(inc);
    {
      if(finalstate1 == HIGH)
      {
        count++;
        lcd.setCursor(0,0);
        lcd.print("Counter : ");
        lcd.setCursor(0,1);
        lcd.print(count);
      }
    }
    initialstate1 = finalstate1;
  }
  
  // Decrement Part

  finalstate2 = digitalRead(dec);
  if(finalstate2 != initialstate2)
  {
    delay(10);
    finalstate2 = digitalRead(dec);
    {
      if(finalstate2 == HIGH)
      {
        count--;
        lcd.setCursor(0,0);
        lcd.print("Counter : ");
        lcd.setCursor(0,1);
        lcd.print(count);
      }
    }
    initialstate2 = finalstate2;
  }
}

Ill have a look at GitHub as well, Thanks again! :slight_smile:


#10

No worries. Let me know when you get the DMD working. That’s the next thing you should work on; a DMD sketch with nothing else in it, just enough to get the DMD going how you want, with the LCD also wired up but unused by the sketch,