Push buttons and I2C LCD Display

I'm currently trying to control my Daventach I2C LCD05 screen with 4 push buttons. I have my arduino and screen connected using 5v,ground and A4 and A5. My buttons are all grounded together and are in Digital ports 8,9,10 and 11 at the minute(Unless this needs to change). so far i have my screen working and displaying pages by using delays however, I now want to be able to use two buttons to higher or lower a value on the screen and when i hit select it carries on to to the next screen. I'm having to use wire.h for everything because i cant get liquid crystal to work with my display so any help would be greatly appreciated. I'm stuck and cant get any further I'm just going round in circles.

Thanks Luke

Hi, Can you post your code and a circuit diagram so we can help you with your project?

Tom.. :)

#include <Wire.h>

#define LCD05 0x63 // LCD05 address

char stringBuf[20];
byte buffer[4];

void setup()
{
delay(100); // Delay to wait for everything to power up

Wire.begin();

buffer[0] = 0; // Clear the screen
buffer[1] = 12;
buffer[2] = 19;
buffer[3] = 31;
buffer[4] = 10;

Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

}

void loop()
{
//---------------------------------------------------------------------------------------------------- Title page
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 2;
buffer[4] = 1;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message = " -={TORSION RIG}=-"; // The message to be put on the screen
int len = message.length() + 1; // Length of the message
message.toCharArray(stringBuf, len); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len);
Wire.endTransmission();
delay (5000);
//---------------------------------------------------------------------------------------------------- Clear Screen
Wire.begin();
buffer[1] = 12;
Wire.beginTransmission(LCD05);
Wire.write(buffer,2);
Wire.endTransmission();
delay (500);
//---------------------------------------------------------------------------------------------------- Second page title (Select force)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 2;
buffer[4] = 3;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message1 = " {SELECT FORCE}"; // The message to be put on the screen
int len1 = message1.length() + 1; // Length of the message
message1.toCharArray(stringBuf, len1); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len1);
Wire.endTransmission();
//-------------------------------------------------------------------------------------------------- Second Page (newtons)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 4;
buffer[4] = 2;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message2 = " (NEWTONS):"; // The message to be put on the screen
int len2 = message2.length() + 1; // Length of the message
message2.toCharArray(stringBuf, len2); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len2);
Wire.endTransmission();
//------------------------------------------------------------------------------------------------ Second Page (Select in N)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 4;
buffer[4] = 14;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message3 = " 1000N"; // The message to be put on the screen
int len3 = message3.length() + 1; // Length of the message
message3.toCharArray(stringBuf, len3); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len3);
Wire.endTransmission();
delay (5000);
//-------------------------------------------------------------------------------------------------------- Clear Screen
Wire.begin();
buffer[1] = 12;
Wire.beginTransmission(LCD05);
Wire.write(buffer,2);
Wire.endTransmission();
delay (500);
//-------------------------------------------------------------------------------------------------------- Third Page (Title)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 2;
buffer[4] = 2;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message4 = " {SELECT NO CYCLES}"; // The message to be put on the screen
int len4 = message4.length() + 1; // Length of the message
message4.toCharArray(stringBuf, len4); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len4);
Wire.endTransmission();
//------------------------------------------------------------------------------------------------------- Third Page (Both Ways)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 4;
buffer[4] = 3;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message5 = " (Each Way):"; // The message to be put on the screen
int len5 = message5.length() + 1; // Length of the message
message5.toCharArray(stringBuf, len5); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len5);
Wire.endTransmission();
//-------------------------------------------------------------------------------------------------------- Third Page (Number of cycles each way)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 4;
buffer[4] = 17;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message6 = " 5"; // The message to be put on the screen
int len6 = message6.length() + 1; // Length of the message
message6.toCharArray(stringBuf, len6); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len6);
Wire.endTransmission();
delay (5000);
//-------------------------------------------------------------------------------------------------------- Clear Screen
Wire.begin();
buffer[1] = 12;
Wire.beginTransmission(LCD05);
Wire.write(buffer,2);
Wire.endTransmission();
delay (500);
//-------------------------------------------------------------------------------------------------------- Fourth Page (Title)
Wire.begin();
buffer[1] = 19;
buffer[2] = 3;
buffer[3] = 2;
buffer[4] = 4;
Wire.beginTransmission(LCD05);
Wire.write(buffer,5);
Wire.endTransmission();

String message7 = " {IN PROGRESS}"; // The message to be put on the screen
int len7 = message7.length() + 1; // Length of the message
message7.toCharArray(stringBuf, len7); // Convert the message to a car array
stringBuf[0] = 0; // First byte of message to 0 (LCD05 command register)
Wire.beginTransmission(LCD05);
Wire.write(stringBuf, len7);
Wire.endTransmission();
//-------------------------------------------------------------------------------------------------------- Clear screen and back to top of loop

delay (5000);
Wire.begin();
buffer[1] = 12;
Wire.beginTransmission(LCD05);
Wire.write(buffer,2);
Wire.endTransmission();
delay (1000);
}

This is how I’ve setup the buttons: Ep. 59 - Arduino LCD Display Menu System Tutorial, Scrolling Menu, Changeable Variables for Projects - YouTube

and this is how ive wired up my lcd: How to Connect an I2C Lcd Display to an Arduino Uno Tutorial - YouTube

Hi,

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom... :)

#include <Wire.h>

#define LCD05  0x63                   // LCD05 address

char stringBuf[20];
byte buffer[4];

void setup()
{
  delay(100);                          // Delay to wait for everything to power up

  Wire.begin();
 
  buffer[0] = 0;                       // Clear the screen
  buffer[1] = 12;
  buffer[2] = 19;
  buffer[3] = 31;
  buffer[4] = 10;
 
 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();

}

void loop()
{   
//----------------------------------------------------------------------------------------------------  Title page
   Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 2;
  buffer[4] = 1; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
   
 String message = "  -={TORSION RIG}=-";      // The message to be put on the screen
  int len = message.length() + 1;       // Length of the message
  message.toCharArray(stringBuf, len);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len);
  Wire.endTransmission();
  delay (5000);
  //----------------------------------------------------------------------------------------------------  Clear Screen
 Wire.begin();
  buffer[1] = 12; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,2);
  Wire.endTransmission();
    delay (500);
  //----------------------------------------------------------------------------------------------------  Second page title (Select force)
   Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 2;
  buffer[4] = 3; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
   
 String message1 = "  {SELECT FORCE}";      // The message to be put on the screen
  int len1 = message1.length() + 1;       // Length of the message
  message1.toCharArray(stringBuf, len1);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len1);
  Wire.endTransmission();
  //--------------------------------------------------------------------------------------------------  Second Page (newtons)
  Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 4;
  buffer[4] = 2; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message2 = " (NEWTONS):";      // The message to be put on the screen
  int len2 = message2.length() + 1;       // Length of the message
  message2.toCharArray(stringBuf, len2);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len2);
  Wire.endTransmission();
  //------------------------------------------------------------------------------------------------  Second Page (Select in N)
  Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 4;
  buffer[4] = 14; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message3 = " 1000N";      // The message to be put on the screen
  int len3 = message3.length() + 1;       // Length of the message
  message3.toCharArray(stringBuf, len3);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len3);
  Wire.endTransmission();
  delay (5000);
 //--------------------------------------------------------------------------------------------------------  Clear Screen
   Wire.begin();
  buffer[1] = 12; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,2);
  Wire.endTransmission();
    delay (500);
 //--------------------------------------------------------------------------------------------------------  Third Page (Title)
  Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 2;
  buffer[4] = 2; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message4 = " {SELECT NO CYCLES}";      // The message to be put on the screen
  int len4 = message4.length() + 1;       // Length of the message
  message4.toCharArray(stringBuf, len4);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len4);
  Wire.endTransmission();
 //-------------------------------------------------------------------------------------------------------  Third Page (Both Ways)
    Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 4;
  buffer[4] = 3; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message5 = " (Each Way):";      // The message to be put on the screen
  int len5 = message5.length() + 1;       // Length of the message
  message5.toCharArray(stringBuf, len5);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len5);
  Wire.endTransmission();
 //--------------------------------------------------------------------------------------------------------  Third Page (Number of cycles each way)
     Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 4;
  buffer[4] = 17; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message6 = " 5";      // The message to be put on the screen
  int len6 = message6.length() + 1;       // Length of the message
  message6.toCharArray(stringBuf, len6);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len6);
  Wire.endTransmission();
  delay (5000);
 //--------------------------------------------------------------------------------------------------------  Clear Screen
   Wire.begin();
  buffer[1] = 12; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,2);
  Wire.endTransmission();
    delay (500);
 //--------------------------------------------------------------------------------------------------------  Fourth Page (Title)
  Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 2;
  buffer[4] = 4; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
  String message7 = " {IN PROGRESS}";      // The message to be put on the screen
  int len7 = message7.length() + 1;       // Length of the message
  message7.toCharArray(stringBuf, len7);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len7);
  Wire.endTransmission();
 //--------------------------------------------------------------------------------------------------------  Clear screen and back to top of loop

   delay (5000);
  Wire.begin();
  buffer[1] = 12; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,2);
  Wire.endTransmission();
    delay (1000);
}

Circuit:

OP’s image:

|500x281

HUM

byte buffer[4]; . . . buffer[4] = 10; . . . Wire.write(buffer,5);

Sorry but I don't understand what you mean. I have all of that code you've just stated.

byte buffer[4]; The above line declares an array of 4 elements. You would have buffer[0], buffer[1], buffer[2] and buffer[3]

buffer[4] = 10; You are now accessing buffer[4] which is not defined. :(

Wire.write(buffer,5); You are now sending 5 elements :(

For example: int myArray[10]={9, 3, 2, 4, 3, 2, 7, 8, 9, 11}; // myArray[9] contains 11 // myArray[10] is invalid and contains random information (other memory address)

Some comments

Where are your pull-up resistors? Currently, when a button is not pressed, it floats and can be high or low when you read it. Use pinMode(somePin, INPUT_PULLUP) for your button pins or use external resistors.

You don't need to use Wire.begin() all the time; once in setup() should be sufficient.

OK, you now know how to post code. Please go back and modify post #2 to correct it.