first, sorry for my bad english :~ I'll hope somebody will understand what I need help for.
I'm newbie in Arduino but not in electronics.
I'm developing project for local swim club (my daughter is a member). It is a training light, it is 25 LED at bottom of swimming pool (every meter is a LED). Swim trainer had to input total swim time and number of pool pass and press a button to start. Swimmer swim and watch LED's at the bottom and try to keep his speed accordingly to LED moving speed.
Led's will be controlled via 4pcs. of HC595 (I hope so)
Delay of led moving will be (input time/number of pass)/25. Number of led on/off's will be 25 x number of pass.
LCD display will be 16x2, keyboard is 3 columns 4 rows - numeric only. What I actually need help for is how to interact keyboard and lcd.
Operator will be noticed on screen to input total time, first minutes (he must write one or two number on keyboard and see it on screen, when input is ok than press * button to move on). Than it must input number of pass (also he must write one or two number on keyboard and see it on screen, when input is ok than press *).
I don't have idea how to do that, is there any library or example how to do that or something similar? I saw lot of devices that have this way of input numbers but never seen any Arduino sketch having such thing.
hi
May be i can help you.
I am using a LCD and matrix key board in some proyects
for LCD i have used lyquidcrystal.h library and for the matrix keyboard Keypad.h
I thing are easy to use whit the samples and information that you find in play ground but if you need more help tell me
i'm using those two libraries. I can write on LCD and read form keyboard. But I need some higer level of interaction. And I'm not experienced to program it on my own
example what operator must do:
a text on LCD is written "Total swimmer time"
After a second "enter minutes"
operator push one or two buttons on keyboard and numbers are displayed on LCD. Arduino waits for * button to continue or # button to erase a wrong entered number.
After that display shows "enter seconds" and same procedure as before. It will be even better if operator can enter minutes and seconds in format MM:SS and arduino can receive that.
How can I program that ?
1 LCD
with the lyquidcrystal library you declare that you are using a lcd variable the name is lcd and the pin conection inside the setup() funtion:
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(41,37,49,47,45,43);
then in the loop funtion you can print like in your serial monitor:
lcd.print("hello, world!");
so if you want one way could be
print something
use millis() for count the minute
print another thing
2 keypad
you read the key in a variable so if you use switch- case (you can read a little in reference,if you are not used with this)
so you define a variable key,where you read the key push
char key = keypad.getKey();
and one switch case that works like a menu
switch (key){
case'*':
your code for go on////continue
return;
case'#':
your code ///// print error and go where you need
return;
default: ///// this is went one key is pressed and it is not necesary,imagine you only need for your code key * and # and someone press number 1
your code//// print invalid stay waiting
return;
}
It is the easiest to program with since you need no library, just do serial.print and serial.read. Both LCD and keypad are connected to the back pack. There are many sample projects for inputting numbers and etc. available.
The lib should also support the 16x2 LCD which accorindgin to the web page also includes the keyboard interface.
Very simple to use, just two resistors to connect the I2C line, and the keyboard connects directly to the LCD controller. No other logic is needed. The instruction sheet is here: http://www.web4robot.com/files/SerialLCDCtrN.pdf
The lib should also support the 16x2 LCD which accorindgin to the web page also includes the keyboard interface.
Very simple to use, just two resistors to connect the I2C line, and the keyboard connects directly to the LCD controller. No other logic is needed. The instruction sheet is here: http://www.web4robot.com/files/SerialLCDCtrN.pdf
Hope this answers your question.
-al-
Do you know how much extra memory the I2C Lcd library is using on your arduino? Do you know the library will be maintained and updated for new arduino versions? Do you think one has to struggle through similar set up process as yo had?
The real quality serial Lcd like mine raises none of the above questions. Only the cheap ones do.
FYI, there are over 3,000 lines of C++ code on my serial lcd, that alone means something.
It is the easiest to program with since you need no library, just do serial.print and serial.read. Both LCD and keypad are connected to the back pack. There are many sample projects for inputting numbers and etc. available.
I think this is right thing for me! I have read most stuff on your blog and this is really good work, not expensive too. It is best that it use only two pins on arduino and no memory. I'll buy it today!
liudr:
Do you know how much extra memory the I2C Lcd library is using on your arduino? Do you know the library will be maintained and updated for new arduino versions? Do you think one has to struggle through similar set up process as yo had?
The real quality serial Lcd like mine raises none of the above questions. Only the cheap ones do.
FYI, there are over 3,000 lines of C++ code on my serial lcd, that alone means something.
Well, you do have a nice solution there. Being a bit new to Arduino, some of your questions I can not fully answer. But I do know the default .print libs use a tremendous amount of time, and in some programs would be unsuitable to be part of the main loop.
I think there are many ways to approach a given problem, glad to see you have one so well thought out
Noting to do with what is in 'my' loop, this is simple the default libs.
try the following:
/*
Testing timing needed for Serial output
RS-232 vs I2C using common libs.
*/
// include the library code:
#include <LCDI2Cw.h>
#include <Wire.h>
#define LOOP_COUNT 100 // Do 100 examples of each output and time the total time needed.
long I2C_TIME;
long SERIAL_TIME;
unsigned char i2cAddress = 0x4C; // LCD module I2C address
// initialize the library with the number of columns and rows
LCDI2Cw lcd(20, 4, i2cAddress);
void setup() {
// Set up the Output ports.
lcd.begin();
Serial.begin(9600);
}
void loop() {
// Do the I2C 1st
I2C_TIME = millis();
for (int i=0; i <= LOOP_COUNT; i++) {
lcd.print(" hello, world! "); // Print a message to the LCD.
lcd.print(i);
lcd.keypad(); // Just check if there is any LCD key pressed.
}
I2C_TIME = millis() - I2C_TIME;
// Now do RS-232 output
SERIAL_TIME = millis();
for (int i=0; i <= LOOP_COUNT; i++) {
Serial.print(" hello, world! "); // Print a message via the RS-232.
Serial.println (i);
Serial.available(); // Just check to see if a serial key is available.
}
SERIAL_TIME = millis() - SERIAL_TIME;
// set the cursor to line 1, column 0
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print("I2C Time = ");
lcd.print(I2C_TIME);
lcd.setCursor(0, 2);
lcd.print("Serial Time = ");
lcd.print(SERIAL_TIME);
Serial.print("I2C Time = ");
Serial.println(I2C_TIME);
Serial.print("Serial Time = ");
Serial.println(SERIAL_TIME);
}
You will see that with default setting the Serial.print function takes almost 7x the time as the I2C functions. (No need to connect an I2C for the above to run, just give it a try).
Now of course one could play with the serial timing - bump it up to 57,600 and close the gap, but then the I2C could also be bumped up from the default 100Khz to Fast-Mode (400Khz). But now we are into the 'modifying' space on both serial attachment methods.
For many application this likely will be a non-issue. But if one is doing any type of process control, the time needed to update the display can be a factor. It all depends on the application. . . .
You mistake I2C speed with LCD data speed. Actual Speed of LCD data lines is much slower than that. The fastest operation takes 37us on LCD. The slower operations take tens of milliseconds. My serial LCD on the other hand has serial port buffer so although serial is not as quick as TWI, the end result is just the opposite. You also get delays with some TWI lcd libraries too.