I recently assembled the Modern Device Bare Bones Board and the LCD Interface, and I have been learning by tweaking and changing and adding to the sample code that Paul provides on his site.
One of the things I tried to do was change the backlighting level mid-program, making it dim to various levels. When I would enable this part of the code, the program would crash at a specific spot -- and then restart from the beginning. If I inserted the backlight code before the crash spot, the backlight code would execute perfectly and it would proceed to the crash spot. If I inserted the backlight code at the end of the program, the program would crash at the same spot (way before it reached the backlight section). If I commented out the backlight section, the code would run just perfectly.
In the code below, the backlight section is at the bottom (commented out) (third post below). The approximate location of the crash is located at the comment // PROGRAM CRASHES HERE!!!!!! (first post, about 2/3 way down)
Any thoughts? If you want to try it, and have the Modern Device Serial LCD Board, connect it to Analog Input point 0 which is being used as Digital Pin 14 for serial out to the LCD board.
#include <SoftwareSerial.h>
/* port of Peter Anderson's LCD117_1.BS2 (Parallax Basic Stamp 2) to Arduino
Paul Badger 2007
original Peter H. Anderson, Baltimore, MD, Oct, '06
Modifications in progress by William P. Cahill, Fort Worth TX
Configured for 20 x 2 display
*/
char N;
int I;
int ByteVar;
int NN;
int Remainder;
int Num_5;
#define rxPin 4 // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :)
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
// mySerial is connected to the TX pin so mySerial.print commands are used
// one could just as well use the software mySerial library to communicate on another pin
void setup(){
pinMode(txPin, OUTPUT);
mySerial.begin(9600); // 9600 baud is chip comm speed
mySerial.print("?G216"); // set display geometry, 2 x 16 characters in this case
delay(100); // pause to allow LCD EEPROM to program
mySerial.print("?Bbf"); // set backlight to 40 hex
delay(100); // pause to allow LCD EEPROM to program
mySerial.print("?s6"); // set tabs to six spaces
delay(1000); // pause to allow LCD EEPROM to program
}
void loop(){
mySerial.print("?D00000000000000000"); // define special characters
delay(300); // delay to allow write to EEPROM
//crashes LCD without delay
mySerial.print("?D11010101010101010");
delay(300);
mySerial.print("?D21818181818181818");
delay(300);
mySerial.print("?D31c1c1c1c1c1c1c1c");
delay(300);
mySerial.print("?D41e1e1e1e1e1e1e1e");
delay(300);
mySerial.print("?D51f1f1f1f1f1f1f1f");
delay(300);
mySerial.print("?D60000000000040E1F");
delay(300);
mySerial.print("?D70000000103070F1F");
delay(300);
mySerial.print("?c0"); // turn cursor off
delay(300);
mySerial.print("?f"); // clear the LCD
delay(1000);
mySerial.print("?f"); // clear the LCD
delay(100);
delay(3000);
mySerial.print("?x00?y0"); // cursor to first character of line 0
mySerial.print("Sample LCD Stuff");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
mySerial.print(" b");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by ");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by B");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bi");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bil");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill ");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill C");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Ca");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Cah");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Cahi");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Cahil");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Cahill");
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
delay(100);
mySerial.print(" by Bill Cahill ");
delay(2000); // Pause to admire
mySerial.print(" Custom Chars:");
mySerial.print(" ?0?1?2?3?4?5?6?7 "); // display special characters
delay(3000);
mySerial.print("?f"); // clear the LCD
mySerial.print("ASCII Character ");
mySerial.print("?x00?y1"); // move cursor to countdown position
mySerial.print(" Table in 5.. ");
delay(1000);
mySerial.print("?x12?y1");
mySerial.print("4");
delay(1000);
mySerial.print("?x12?y1");
mySerial.print("3");
delay(1000);
mySerial.print("?x12?y1");
mySerial.print("2");
delay(1000);
mySerial.print("?x12?y1");
mySerial.print("1");
delay(1000);
mySerial.print("?x00?y0"); // locate cursor to beginning of line 0
// PROGRAM CRASHES HERE!!!!!!
mySerial.print("DEC HEX ASCII"); // print labels
delay(500);
// simple printing demonstation
for (N = 38; N<= 126; N++){ // pick an arbitrary part of ASCII chart - change as you wish
mySerial.print("?x00?y1"); // locate cursor to beginning of line 1
mySerial.print(N, DEC); // display N in decimal format
mySerial.print("?t"); // tab in
mySerial.print(N, HEX); // display N in hexidecimal format
mySerial.print("?t"); // tab in
// glitches on ASCII 63 "?" -- single "?" is a command character
if (N=='?'){
mySerial.print("??"); // print double ??'s - see Phanderson 117 docs
}
else{
mySerial.print(N, BYTE); // display N as an ASCII character
}
mySerial.print(" "); // display N as an ASCII character
delay(200);
}
delay (1000);
mySerial.print("?y0?x00"); // cursor to beginning of line 0
delay(10);
mySerial.print("?l"); // clear line
delay(10);
mySerial.print(" Bar Graph Demo");
delay(10);
mySerial.print("?n"); // cursor to beginning of line 1 + clear line 1
delay(500);
// bar graph demo - increasing bar
for ( N = 0; N <= 80; N++){ // 16 chars * 5 bits each = 80
mySerial.print("?y1?x00"); // cursor to beginning of line 1
delay(10);
Num_5 = N / 5; // calculate solid black tiles
for (I = 1; I <= Num_5; I++){
mySerial.print("?5"); // print custom character 5 - solid block tiles
delay(4);
}
Remainder = N % 5; // % sign is modulo operator - calculates remainder
// now print the remainder
mySerial.print("?"); // first half of the custom character command
mySerial.print(Remainder, DEC); // prints the custom character equal to remainder
delay(5);
}
delay(50);
for ( N = 80; N >= 0; N--){ // decreasing bar - 16 chars * 5 bits each
mySerial.print("?y1?x00"); // cursor to beginning of line 1
delay(10);
Num_5 = N / 5; // calculate solid black tiles
for (I = 1; I <= Num_5; I++){
mySerial.print("?5"); // print custom character 5 - solid block tiles
delay(5);
}
Remainder = N % 5; // % sign is modulo operator - calculates remainder
// now print the remainder
mySerial.print("?"); // first half of the custom character command
mySerial.print(Remainder, DEC); // prints the custom character equal to remainder
delay(5);
}
(see next post for the rest)