Force Feedback with LCD Screen

Written by:

In today's Instructable, we'll be going over how to monitor the current of an actuator, and adjust the values using an LCD screen. This Instructable is a continuation to the Monitoring the Load Feedback of an Actuator Instructable. We'll be adding in the LCD screen so you can see how much current the actuator is pulling, as well as set the current limits.

First, we'll go over the LCD buttons and how they integrate with the Arduino, and then go on to see how we can write and set values to the LCD screen so we can see what the program is doing.

For this project, you will need:

- 1x MegaMoto

- 1x Arduino Uno

- 1x Linear Actuator

- 1x LCD Screen

- 1x 12V Power Supply

Let's get started!

Step 1: LCD Screen Buttons

The LCD screen has six buttons on it, five that are available for use. We'll be using four of them for our project. The buttons are Up, Down, Left, Right, Select, and Reset. The Reset button resets the entire Arduino. We'll use the four directional buttons. Up and Down will set the current limit, Left and Right will move the actuator.

The LCD screen puts all five buttons through a Digital to Analog Converter so that they only take up one pin. The flip side to this is that you need to calibrate your buttons.

The easiest way to do so is to use the Arduino AnalogReadSerial example, and see what value you get for each button press. Most LCD screens use pin A0 for the buttons. Be sure to change the delay value in AnalogReadSerial so that you can actually see what values appear in the serial monitor. There are six readings that you need to get, the five readings of the buttons, plus the reading that you get when no buttons are pressed.

Once you have the readings of the buttons, you can use the code here to ensure that they are all working. One more value that is used is the threshold. The threshold is to ensure that when you press the button, it will actually register. Since the button presses go through an DAC, they may be slightly different each press. You use the threshold value to give a +/- addition so that the button presses can fall within a range, rather then one exact value. Usually, a small threshold like 2 or 3 is enough for a single board, but if you want to make a program that will work with many different LCD boards (for example, you're making 10 copies of your project) then you would use a larger threshold to account for the slight differences in the boards.

Extra comments have been added to the code so you can see what everything is for. Once you've tested the code and gotten all your button values, we can move on to the next program.

//Sample using LiquidCrystal library#include <LiquidCrystal.h>/*******************************************************This program will test the LCD panel and the buttonsMark Bramwell, July 2010********************************************************// select the pins used on the LCD panelLiquidCrystal lcd(8, 9, 4, 5, 6, 7); //rs, enable, d4,d5,d6,d7// define some values used by the panel and buttonsint lcd_key     = 0;//which button was pressedint adc_key_in  = 0;//what was the input of the DAC#define btnRIGHT  0#define btnUP     1#define btnDOWN   2#define btnLEFT   3#define btnSELECT 4#define btnNONE   5 //set button return valuesconst int btnup = 130;const int btndown = 306;const int btnleft = 479;const int btnright = 0;const int select = 720;const int none = 127; //Put your button values hereconst int threshold = 2; //Put threshold value hereint read_LCD_buttons(){ adc_key_in = analogRead(A0);      // read the value from the sensor if (adc_key_in > none - threshold && adc_key_in < none + threshold)   return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely resultif (adc_key_in > btnup - threshold && adc_key_in < btnup + threshold)   return btnUP;if (adc_key_in > btndown - threshold && adc_key_in < btndown + threshold)   return btnDOWN;if (adc_key_in > btnleft - threshold && adc_key_in < btnleft + threshold)   return btnLEFT;if (adc_key_in > btnright - threshold && adc_key_in < btnright + threshold)   return btnRIGHT;if (adc_key_in > select - threshold && adc_key_in < select + threshold)   return btnSELECT;//if else statements could be used, but since each statement uses return, you don't lose speed for using all if's return btnNONE;  // when all others fail, return this...}//end read_LCD_Buttonsvoid setup(){ lcd.begin(16, 2);              // start the library lcd.setCursor(0,0); // Set cursor to upper left corner lcd.print("Push the buttons"); // print a simple message}//end setup void loop(){ lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over lcd.print(millis()/1000);      // display seconds elapsed since power-up lcd.setCursor(0,1);            // move to the begining of the second line lcd_key = read_LCD_buttons();  // read the buttons switch (lcd_key)               // depending on which button was pushed, we perform an action {   case btnRIGHT:     {     lcd.print("RIGHT ");     break;     }   case btnLEFT:     {     lcd.print("LEFT   ");     break;     }   case btnUP:     {     lcd.print("UP    ");     break;     }   case btnDOWN:     {     lcd.print("DOWN  ");     break;     }   case btnSELECT:     {     lcd.print("SELECT");     break;     }     case btnNONE:     {     lcd.print("NONE  ");     break;     } }//end switch}//end loop


Leave a Reply