Switching on DC loads through LCD menu?

Hello.

I am fairly new to arduino, mostly done some examples with led's and easy project like that on my Arduino UNO.
Now i want to challenge myself with a project that i want to combine in a FPV-project that i am doing.

What i want to do:

Use a arduino to display a menu on a LCD where i can choose to power on two different DC loads (12V)

When i first plug in the battery to the "system", i want it to display a simple menu.
Something like this:

    Welcome     
LCD[ON]  Vid[ON]

from this menu i can switch on, two separate 12V loads (a 9" monitor, and a video reciever), using push-buttons.

The loads are 12V and draw something like 100mA up to 1A at the most!

My questions:

*What is the difference between a serial enabled LCD, and a standard (exept for the connections), is it easier to use the serial enabled, or vice versa?

*What should i use for switching my loads? a relay, or can i use something like a MOSFET?
I looked at this: SparkFun Beefcake Relay Control Kit (Ver. 2.0) - KIT-13815 - SparkFun Electronics is this what i need?

*I looked at this Serial Enabled LCD Kit from SparkFun, and it has it own ATMega328 on the back.
Is it possible for me to use this as the main controller, and connect the buttons and relays to this and run everything from this without the need for a separate arduino?

Please point me in the right direction and contribute with your ideas! :slight_smile:

Regards
Christopher

What is the difference between a serial enabled LCD, and a standard (exept for the connections), is it easier to use the serial enabled, or vice versa?

The number of necessary pins on the Arduino. The serial enabled LCDs have a separate processor (often an ATmega or something similar) that converts the serial commands into the parallel instructions the Hitachi chipset understands.

What should i use for switching my loads? a relay, or can i use something like a MOSFET?

What are your loads? Your question is as general as "what car should I buy?".

I looked at this Serial Enabled LCD Kit from SparkFun, and it has it own ATMega328 on the back.
Is it possible for me to use this as the main controller, and connect the buttons and relays to this and run everything from this without the need for a separate arduino?

Yes, this is possible but not very convenient. It's easier to buy an Arduino and use a cheap parallel LCD display because there you have the convenience of the Arduino platform and you can program it without a separate programmer (needed if you wanna reprogram the SparkFun kit).

pylon:

What is the difference between a serial enabled LCD, and a standard (exept for the connections), is it easier to use the serial enabled, or vice versa?

The number of necessary pins on the Arduino. The serial enabled LCDs have a separate processor (often an ATmega or something similar) that converts the serial commands into the parallel instructions the Hitachi chipset understands.

Ok, so thats the difference, like i thought! I'll buy a couple of each and try for myself wich one is more easy to use.

What should i use for switching my loads? a relay, or can i use something like a MOSFET?

What are your loads? Your question is as general as "what car should I buy?".

Sorry if i was too unclear on my description!

The two loads i want to switch are:
One 9" monitor aprox. not more than 1A
One Wireless Video reciever aprox. 100mA

I looked at this Serial Enabled LCD Kit from SparkFun, and it has it own ATMega328 on the back.
Is it possible for me to use this as the main controller, and connect the buttons and relays to this and run everything from this without the need for a separate arduino?

Yes, this is possible but not very convenient. It's easier to buy an Arduino and use a cheap parallel LCD display because there you have the convenience of the Arduino platform and you can program it without a separate programmer (needed if you wanna reprogram the SparkFun kit).

Ok. So not very easy to handle than a ordinary Arduino.. i'll have that in mind!

Thank you for your help so far!
Christopher

The two loads i want to switch are:
One 9" monitor aprox. not more than 1A
One Wireless Video reciever aprox. 100mA

I guess both devices are run by DC current. You can use both, MOSFETs or relays to drive such a load. The MOSFETs have the advantage that they are silent when switching while the relays have the advantage of being cheap. My preference would be the MOSFETs.

pylon:

The two loads i want to switch are:
One 9" monitor aprox. not more than 1A
One Wireless Video reciever aprox. 100mA

I guess both devices are run by DC current. You can use both, MOSFETs or relays to drive such a load. The MOSFETs have the advantage that they are silent when switching while the relays have the advantage of being cheap. My preference would be the MOSFETs.

Yes exactly! DC 12V..
I actually just remembered that i have a bunch of MOSFETS from a project that i didn't do(38pcs actually)! Thanks for the reminder! :wink:

The MOSFETS i have are named f1404Z
datasheet: http://www.irf.com/product-info/datasheets/data/irf1404z.pdf

And if i read the data-sheet correctly, there should not be any problem?

Regards
Christopher

Tried the F1404Z, and everything seems to work! :slight_smile:

At least nothing started to smoke! ]:smiley:

I have started to look into a couple of menu libraries, and i am sort of getting there, not understanding a whole lot, like i was hoping for..! :smiley:

What i DO have is the "loading screen" that i want the system to show when power is applied, but how do i make so that this only shows once when power is applied, and doesn't go "in the loop" so to speak?

And as always!
Thank you in advance!

What i DO have is the "loading screen" that i want the system to show when power is applied, but how do i make so that this only shows once when power is applied, and doesn't go "in the loop" so to speak?

Put it into the setup().

@Pylon
Thank you! so simple, yet i did not discover it myself! :slight_smile:

I may have shifted my project from my first thought about using a menu system, to just displaying "turning on LCD" when that button is pressed, and after, say 1-2 seconds, the display goes back to its "standard view". And likewise for the second button..

This seems like it would be much simpler than using a whole menu system, for the simple task that i want to perform..

So, this is what i have come up with so far:

This code works, and does what i want:

//Code for loading screen made by: mrmeval

//TEST med toggle

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

const int ledlcdPin = A0; //LEDpin i UNO
const int ledvideoPin = A1;
const int buttonlcdPin = 11; //Buttonpin in i UNO
const int buttonvideoPin = 10; //Buttonpin in i UNO

int ledState = HIGH;

int buttonState;
int lastButtonState = LOW;

unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
const unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

byte block[8] =
{
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B00000
};

void setup() {
 // set up the LCD's number of rows and columns:
 lcd.createChar(7,block);
 lcd.begin(16, 2);
 //lcd.setCursor(0,7);
    delay(10);
    
 // scroll 24 positions (string length) to the left
 // to move it offscreen left:
 lcd.clear();
 lcd.print("  MK-Swe GS-V1  Startar");
 for (int positionCounter = 0; positionCounter < 23; positionCounter++) {
   // scroll one position left:
   lcd.scrollDisplayLeft();
   delay(380);
   }
   lcd.home();
   lcd.setCursor(0,1);
   for (int x=0; x < 16 ; x++){
     delay(300);
   lcd.write(7);}
 
 pinMode(ledlcdPin, OUTPUT);
 pinMode(ledvideoPin, OUTPUT);
 pinMode(buttonlcdPin, INPUT); 
 pinMode(buttonvideoPin, INPUT); }

void loop() {

 lcd.setCursor(0,0);
 lcd.print(" GroundStation  ");
 lcd.setCursor(0,1);
 lcd.print("TESTTESTTEST SWE");
 
  int currentButtonState = digitalRead(buttonlcdPin);
  
  if (currentButtonState != lastButtonState) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay &&
  currentButtonState != buttonState) {
    //Nytt värde från knapp
    buttonState = currentButtonState;
    if (buttonState == LOW) //Pressed
    {
      //New state is pressed
      ledState = !ledState;
      digitalWrite(ledlcdPin, ledState);
      lcd.setCursor(0,0);
      lcd.print("     TESTING    ");
      delay(2000);

    }
  }
  
  lastButtonState = currentButtonState;
  
  
}

But when i try to add the same type of code for the second button it doesn't work..

//Code for loading screen made by: mrmeval

//TEST med toggle

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

const int ledlcdPin = A0; //LEDpin i UNO
const int ledvideoPin = A1;
const int buttonlcdPin = 11; //Buttonpin in i UNO
const int buttonvideoPin = 10; //Buttonpin in i UNO

int ledlcdState = HIGH;
int ledvideoState = HIGH;

int buttonlcdState;
int buttonvideoState;
int lastButtonState = LOW;

unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
const unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

byte block[8] =
{
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B11111,
 B00000
};

void setup() {
 // set up the LCD's number of rows and columns:
 lcd.createChar(7,block);
 lcd.begin(16, 2);
 //lcd.setCursor(0,7);
    delay(10);
    
 // scroll 24 positions (string length) to the left
 // to move it offscreen left:
 lcd.clear();
 lcd.print("  MK-Swe GS-V1  Startar");
 for (int positionCounter = 0; positionCounter < 23; positionCounter++) {
   // scroll one position left:
   lcd.scrollDisplayLeft();
   delay(380);
   }
   lcd.home();
   lcd.setCursor(0,1);
   for (int x=0; x < 16 ; x++){
     delay(300);
   lcd.write(7);}
 
 pinMode(ledlcdPin, OUTPUT);
 pinMode(ledvideoPin, OUTPUT);
 pinMode(buttonlcdPin, INPUT); 
 pinMode(buttonvideoPin, INPUT); }

void loop() {

 lcd.setCursor(0,0);
 lcd.print(" GroundStation  ");
 lcd.setCursor(0,1);
 lcd.print("TESTTESTTEST SWE");
 
  int currentButtonlcdState = digitalRead(buttonlcdPin);
  
  if (currentButtonlcdState != lastButtonState) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay &&
  currentButtonlcdState != buttonlcdState) {
    //Nytt värde från knapp
    buttonlcdState = currentButtonlcdState;
    if (buttonlcdState == LOW) //Pressed
    {
      //New state is pressed
      ledlcdState = !ledlcdState;
      digitalWrite(ledlcdPin, ledlcdState);
      lcd.setCursor(0,0);
      lcd.print("     TESTAR     ");
      delay(2000);

    }
  }
  
  lastButtonState = currentButtonlcdState;
  

  int currentButtonvideoState = digitalRead(buttonvideoPin);
  
  if (currentButtonvideoState != lastButtonState) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay &&
  currentButtonvideoState != buttonvideoState) {
    //Nytt värde från knapp
    buttonvideoState = currentButtonvideoState;
    if (buttonvideoState == LOW) //Pressed
    {
      //New state is pressed
      ledvideoState = !ledvideoState;
      digitalWrite(ledvideoPin, ledvideoState);
      lcd.setCursor(0,0);
      lcd.print("     TESTAR2    ");
      delay(2000);

    }
  }
  
  lastButtonState = currentButtonvideoState;
  
  
  
}

As you see, i want to have it like this:

When nothing is pressed display some text.
When button 1 is pressed display "starting/loading LCD" for 2 seconds and toggle on LED1
When button 2 is pressed display "starting/loading Video" for 2 seconds and toggle on LED2

and when either one of the buttons is pressed a second time, toggle that corresponding LED off.

Can someone please explain what i am doing wrong..! :frowning:

  if (currentButtonlcdState != lastButtonState) {

...

  if (currentButtonvideoState != lastButtonState) {

You cannot use the same variable to save the last state of the button for both buttons. Each button must have it's own saved state. The same is true for lastDebounceTime.

Thank you!

That sorted it! but now when that works i have another "problem"..

The first time after startup, i have to press each button once before it toggles the corresponding LED..

Guess it has to do with the Debounce function that records for every first time( ? ).. Is it possible to make the now needed first press to go away?

And is it possible to get different message on the display for when the LED turns on and off?
and where would one put the "off" message?

Thanks in advance!
/Chris

The first time after startup, i have to press each button once before it toggles the corresponding LED..

Initialize the variables correctly.

And is it possible to get different message on the display for when the LED turns on and off?

Sure it is, you have ledState, use it!

Did you just copy the code or do you try to understand what it does?

I try to always write code that i find and want to use, and not use copy/paste, that way i hope it stick better! :blush:

I'm having a bit of a rough time understanding a lot of codes, mostly because, most of what i find (tutorials and here at Arduino) is in my sense, written to/by really good programmers that sees the code as what it is, and is not really easy to understand for someone like me! :slight_smile:

I actually had the same problem through school, never really got in to some subjects, mostly because i never had anyone really explain it too me in a way that made sense to Me..

So i really appreciate that you (and others!) point me in the right direction!

/Chris

Which part of the code didn't you understand? You should ask if you don't understand a concept. We expect that you understand what the basic statements (if, for, while, case, etc.) do, though.