Output:
Code:
/*
* LCDIRDecoder.pde: Freeduino/Arduino + cheaphousetek LCDKeypad Shield + IR Reveiver Breakout
* Ken Shirriff's IRremote.h page
* Original from Cooper Maa
* Modified on Jan. 31, 2013 by Befun Hung to fit pins of cheaphousetek LCD Keypad Shield
*/
#include <LiquidCrystal.h> // include LiquidCrystal library
#include <IRremote.h> // include IRRemote library
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // modified to fit cheaphousetek LcdKeypad Shield
const int irReceiverPin = 2; // IR Breakout Output Pin: Digital 2
IRrecv irrecv(irReceiverPin); // define IRrecv object to receive IR singal
decode_results results; // decoded result is stored to variable rusult of struct decode_results
void setup() {
lcd.begin(16, 2); // set numbers of rows and columns of LCD
lcd.print("IR Decoder"); // print "IR Decoder" message on LCD
irrecv.blink13(true); // blinking pin 13 lcd on receiving IR singal
irrecv.enableIRIn(); // start IR decode
}
// display IR protocol
void showIRProtocol(decode_results *results)
{
// judge IR protocol
switch(results->decode_type) {
case NEC:
lcd.print("NEC");
break;
case SONY:
lcd.print("SONY");
break;
case RC5:
lcd.print("RC5");
break;
case RC6:
lcd.print("RC6");
break;
default:
lcd.print("Unknown");
}
// print IR code on LCD
lcd.print(" ");
lcd.print(results->value, HEX); // IR code
lcd.print(" (");
lcd.print(results->bits); // bytes of IR code
lcd.print(")");
}
void loop() {
// set cursor to column 0, line 1
// Note: line 1 is the second row,line 0 is the first row
lcd.setCursor(0, 1);
if (irrecv.decode(&results)) { // successful decode, receiving a set of IR singal
showIRProtocol(&results); // display IR protocol
irrecv.resume(); // continue to receive the next IR singal
}
}
Showing posts with label LCD Keypad Shield. Show all posts
Showing posts with label LCD Keypad Shield. Show all posts
2013/01/31
2012/07/07
Freeduino/Arduino + Datalogger Shield + LCD Keypad Shield + Sensors Connecting To A1, A2 And A3
Dataloggers can be easily used to record sensor readings from analog inputs. With following sketch, anyone can easily record data read from analog input by just stacking Freeduino/Arduino, Datalogger Shield and LCD Keypad Shield and connecting analog ins from A1 to A3.
The data read is raw data, you have to adjust the sketch to do the conversion according the sensor specification. For example, LM35 sensor need to calculate the value of (raw data * 500 / 1023) .
With the data file, you can use data visualization software , such as Gnu Plot, to display data in graph.
Pins Used
cheaphousetek Datalogger Shield ---
RTC: A4 and A5
mSD: D10, D11, D12 and D13
cheaphousetek LCD Keypad Shield ---
LCD: D8, D9, D4, D5, D6 and D7
Keypad: A0
Sensors(LM35): A1, A2 and A3
Output Of LCD Keypad Shield
Contents Of Output File
Sketch
// File name: DataloggerFileNameMMDDHHMMLCD.pde
// The sketch works on Arduino IDE 0022
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
File file; // test file
const uint8_t SD_CS = 10; // SD chip select
RTC_DS1307 RTC; // define the Real Time Clock object
String file_name = "", dataString; // file name should not prefix with "prefix_word"
char fn[] = "MMDDHHMM.txt";
int i=0;
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
Wire.begin();
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
};
lcd.begin(16, 2);
// set date time callback function
SdFile::dateTimeCallback(dateTime);
// following line sets the RTC to the date & time this sketch was compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();
if (now.month() < 10) {
file_name = String(file_name + '0' + String(now.month(), DEC));
}
else {
file_name = String(file_name +String(now.month(), DEC));
}
if (now.day() < 10) {
file_name = String(file_name + '0' + String(now.day(), DEC));
}
else {
file_name = String(file_name +String(now.day(), DEC));
}
if (now.hour() < 10) {
file_name = String(file_name + '0' + String(now.hour(), DEC));
}
else {
file_name = String(file_name +String(now.hour(), DEC));
}
if (now.minute() < 10) {
file_name = String(file_name + '0' + String(now.minute(), DEC));
}
else {
file_name = String(file_name +String(now.minute(), DEC));
}
file_name = String(file_name + ".txt");
// Serial.println(file_name);
// Serial.println(file_name.length());
for (i=0;i<=file_name.length();i++) {
fn[i] = file_name.charAt(i);
// Serial.print(file_name.charAt(i));
}
// Serial.println(fn);
if (!SD.begin(SD_CS)) {
Serial.println("SD failed");
while(1);
}
Serial.print("File Name: ");
Serial.println(fn);
//file = SD.open(fn, FILE_WRITE);
//file.close();
// Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {
DateTime now = RTC.now();
String data_string = "";
data_string = String(now.year(), DEC);
data_string += "/";
if (now.month() < 10) {
data_string = String(data_string + '0' + String(now.month(), DEC));
}
else {
data_string = String(data_string +String(now.month(), DEC));
}
data_string += "/";
if (now.day() < 10) {
data_string = String(data_string + '0' + String(now.day(), DEC));
}
else {
data_string = String(data_string +String(now.day(), DEC));
}
data_string += " ";
if (now.hour() < 10) {
data_string = String(data_string + '0' + String(now.hour(), DEC));
}
else {
data_string = String(data_string +String(now.hour(), DEC));
}
data_string += ":";
if (now.minute() < 10) {
data_string = String(data_string + '0' + String(now.minute(), DEC));
}
else {
data_string = String(data_string +String(now.minute(), DEC));
}
data_string += ":";
if (now.second() < 10) {
data_string = String(data_string + '0' + String(now.second(), DEC));
}
else {
data_string = String(data_string +String(now.second(), DEC));
}
data_string += ",";
//read sensor value from A1-A3 and append to the string
delay(195);
for (int analogPin = 1; analogPin <4; analogPin++)
{
delay(200);
int sensor = analogRead(analogPin);
data_string += String(sensor);
if (analogPin < 3) {
data_string += ",";
}
}
file = SD.open(fn, FILE_WRITE);
if (file) {
file.println(data_string);
file.close();
Serial.println(data_string);
}
else {
Serial.print("error opening ");
Serial.println(fn);
}
lcd.clear();
lcd.setCursor(0,0);
dataString = String(data_string);
lcd.print(dataString.substring(5, 19));
lcd.setCursor(0,1);
lcd.print(dataString.substring(20));
//Serial.println(data_string);
// delay(195);
}
The data read is raw data, you have to adjust the sketch to do the conversion according the sensor specification. For example, LM35 sensor need to calculate the value of (raw data * 500 / 1023) .
With the data file, you can use data visualization software , such as Gnu Plot, to display data in graph.
Pins Used
cheaphousetek Datalogger Shield ---
RTC: A4 and A5
mSD: D10, D11, D12 and D13
cheaphousetek LCD Keypad Shield ---
LCD: D8, D9, D4, D5, D6 and D7
Keypad: A0
Sensors(LM35): A1, A2 and A3
Output Of LCD Keypad Shield
Contents Of Output File
Sketch
// File name: DataloggerFileNameMMDDHHMMLCD.pde
// The sketch works on Arduino IDE 0022
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
File file; // test file
const uint8_t SD_CS = 10; // SD chip select
RTC_DS1307 RTC; // define the Real Time Clock object
String file_name = "", dataString; // file name should not prefix with "prefix_word"
char fn[] = "MMDDHHMM.txt";
int i=0;
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
Wire.begin();
if (!RTC.begin()) {
Serial.println("RTC failed");
while(1);
};
lcd.begin(16, 2);
// set date time callback function
SdFile::dateTimeCallback(dateTime);
// following line sets the RTC to the date & time this sketch was compiled
// RTC.adjust(DateTime(__DATE__, __TIME__));
DateTime now = RTC.now();
if (now.month() < 10) {
file_name = String(file_name + '0' + String(now.month(), DEC));
}
else {
file_name = String(file_name +String(now.month(), DEC));
}
if (now.day() < 10) {
file_name = String(file_name + '0' + String(now.day(), DEC));
}
else {
file_name = String(file_name +String(now.day(), DEC));
}
if (now.hour() < 10) {
file_name = String(file_name + '0' + String(now.hour(), DEC));
}
else {
file_name = String(file_name +String(now.hour(), DEC));
}
if (now.minute() < 10) {
file_name = String(file_name + '0' + String(now.minute(), DEC));
}
else {
file_name = String(file_name +String(now.minute(), DEC));
}
file_name = String(file_name + ".txt");
// Serial.println(file_name);
// Serial.println(file_name.length());
for (i=0;i<=file_name.length();i++) {
fn[i] = file_name.charAt(i);
// Serial.print(file_name.charAt(i));
}
// Serial.println(fn);
if (!SD.begin(SD_CS)) {
Serial.println("SD failed");
while(1);
}
Serial.print("File Name: ");
Serial.println(fn);
//file = SD.open(fn, FILE_WRITE);
//file.close();
// Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {
DateTime now = RTC.now();
String data_string = "";
data_string = String(now.year(), DEC);
data_string += "/";
if (now.month() < 10) {
data_string = String(data_string + '0' + String(now.month(), DEC));
}
else {
data_string = String(data_string +String(now.month(), DEC));
}
data_string += "/";
if (now.day() < 10) {
data_string = String(data_string + '0' + String(now.day(), DEC));
}
else {
data_string = String(data_string +String(now.day(), DEC));
}
data_string += " ";
if (now.hour() < 10) {
data_string = String(data_string + '0' + String(now.hour(), DEC));
}
else {
data_string = String(data_string +String(now.hour(), DEC));
}
data_string += ":";
if (now.minute() < 10) {
data_string = String(data_string + '0' + String(now.minute(), DEC));
}
else {
data_string = String(data_string +String(now.minute(), DEC));
}
data_string += ":";
if (now.second() < 10) {
data_string = String(data_string + '0' + String(now.second(), DEC));
}
else {
data_string = String(data_string +String(now.second(), DEC));
}
data_string += ",";
//read sensor value from A1-A3 and append to the string
delay(195);
for (int analogPin = 1; analogPin <4; analogPin++)
{
delay(200);
int sensor = analogRead(analogPin);
data_string += String(sensor);
if (analogPin < 3) {
data_string += ",";
}
}
file = SD.open(fn, FILE_WRITE);
if (file) {
file.println(data_string);
file.close();
Serial.println(data_string);
}
else {
Serial.print("error opening ");
Serial.println(fn);
}
lcd.clear();
lcd.setCursor(0,0);
dataString = String(data_string);
lcd.print(dataString.substring(5, 19));
lcd.setCursor(0,1);
lcd.print(dataString.substring(20));
//Serial.println(data_string);
// delay(195);
}
Labels:
Arduino,
cheaphousetek,
Data logger,
Data Logger Shield,
Datalogger,
Datalogger Shield,
Freeduino,
Keypad,
LCD,
LCD Keypad Shield,
LM35,
Real Time Clock,
RTC,
Sensor,
Temperature,
temperature sensor
2012/05/22
Sketch for Testing Freeduino/Arduino LCD Keypad Shield
Pins Used
D8, D9, D4, D5, D6, D7, A0
Serial Monitor Output
Sketch
/*
ASCII table
Prints out byte values in all possible formats:
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
The circuit: No external hardware needed.
created 2006
by Nicholas Zambetti
modified 18 Jan 2009
by Tom Igoe
modified by Befun Hung on Sunday, 20 May 2012
file name: LCDKeypadShieldTestKeyNone.pde
for use in testing 16x2 LCD module
added codes from acw@home (HKEPC Hardware) to test Keypad on Monday, 21 May 2012
added codes for debouncing and key touching on Tuesday, 22 May 2012
This example code is in the public domain.
The sketch works on Arduino IDE 0022
<http://www.zambetti.com>
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// analog PIN A0
#define KEY_PIN 0
#define KEY_NONE 1020
int key;
int last_key = -1; //save the last key pressed
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
last_key = KEY_NONE;
lcd.clear();
// prints title with ending line break
// Serial.println("ASCII Table ~ Character Map");
}
// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';
void loop()
{
// prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!'
// lcd.clear();
for (int i=0;i<16;i++)
{
Serial.print(thisByte, BYTE);
lcd.setCursor(i, 0);
lcd.print(char(thisByte));
lcd.setCursor(i, 1);
lcd.print(char(thisByte));
delay(50);
}
Serial.println();
// Serial.print(", dec: ");
// prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and Serial.println(),
// so no modifier is needed:
// Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
//this also works if you uncomment it:
// Serial.print(thisByte, DEC);
// Serial.print(", hex: ");
// prints value as string in hexadecimal (base 16):
// Serial.print(thisByte, HEX);
// Serial.print(", oct: ");
// prints value as string in octal (base 8);
// Serial.print(thisByte, OCT);
// Serial.print(", bin: ");
// prints value as string in binary (base 2)
// also prints ending line break:
// Serial.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop:
if(thisByte == 126) { // you could also use if (thisByte == '~') {
lcd.clear();
// This loop loops forever and does nothing
while(true) {
key = analogRead(KEY_PIN);
delay(200); // for debouncing
if (key <= KEY_NONE && key != last_key) {
lcd.setCursor(0,1);
lcd.print(key);
lcd.print(" ");
Serial.println(key);
last_key = key;
}
continue;
}
}
// go on to the next character
thisByte++;
delay(100);
}
D8, D9, D4, D5, D6, D7, A0
Serial Monitor Output
Sketch
/*
ASCII table
Prints out byte values in all possible formats:
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
The circuit: No external hardware needed.
created 2006
by Nicholas Zambetti
modified 18 Jan 2009
by Tom Igoe
modified by Befun Hung on Sunday, 20 May 2012
file name: LCDKeypadShieldTestKeyNone.pde
for use in testing 16x2 LCD module
added codes from acw@home (HKEPC Hardware) to test Keypad on Monday, 21 May 2012
added codes for debouncing and key touching on Tuesday, 22 May 2012
This example code is in the public domain.
The sketch works on Arduino IDE 0022
<http://www.zambetti.com>
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// analog PIN A0
#define KEY_PIN 0
#define KEY_NONE 1020
int key;
int last_key = -1; //save the last key pressed
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
last_key = KEY_NONE;
lcd.clear();
// prints title with ending line break
// Serial.println("ASCII Table ~ Character Map");
}
// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';
void loop()
{
// prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!'
// lcd.clear();
for (int i=0;i<16;i++)
{
Serial.print(thisByte, BYTE);
lcd.setCursor(i, 0);
lcd.print(char(thisByte));
lcd.setCursor(i, 1);
lcd.print(char(thisByte));
delay(50);
}
Serial.println();
// Serial.print(", dec: ");
// prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and Serial.println(),
// so no modifier is needed:
// Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
//this also works if you uncomment it:
// Serial.print(thisByte, DEC);
// Serial.print(", hex: ");
// prints value as string in hexadecimal (base 16):
// Serial.print(thisByte, HEX);
// Serial.print(", oct: ");
// prints value as string in octal (base 8);
// Serial.print(thisByte, OCT);
// Serial.print(", bin: ");
// prints value as string in binary (base 2)
// also prints ending line break:
// Serial.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop:
if(thisByte == 126) { // you could also use if (thisByte == '~') {
lcd.clear();
// This loop loops forever and does nothing
while(true) {
key = analogRead(KEY_PIN);
delay(200); // for debouncing
if (key <= KEY_NONE && key != last_key) {
lcd.setCursor(0,1);
lcd.print(key);
lcd.print(" ");
Serial.println(key);
last_key = key;
}
continue;
}
}
// go on to the next character
thisByte++;
delay(100);
}
Labels:
Arduino,
Arduino LCD Keypad Shield,
Freeduino,
Freeduino LCD Keypad Shield,
Keypad,
LCD,
LCD Keypad Shield,
LCD Shield,
Shield,
Test,
Test LCD Keypad Shield
Subscribe to:
Posts (Atom)


