Go Down

Topic: TextStar LCD (Read 2791 times) previous topic - next topic

jamesmc

Hi

i have recently been working with a TextStar serial LCD, see (http://cats-whisker.com/web/node/7).  It is a great little product and makes working with a display very easy for a novice.  Although the Textstar is not the cheapest display you can buy it does have some additional features, such as serial interface, bar graphing, line wrap and 4 buttons.

here is my code if it is of use to anyone, it builds upon Rowan Simms (http://rowansimms.com) textstar tutorial.

James


Code: [Select]
/*
3rd Jan 2011 - experiments with Textstar LCD
objectives
1 - connect to screen and display message - done
2 - draw a static graph - done
3 - draw a dynamic graph - done
4 _ read buttons when pressed - not done
5 - display live data from sensors - not done


with thanks to
 Rowan Simms (http://rowansimms.com) textstar tutorial
 Mikal Hart (http://arduiniana.org) New Soft Serial Libralty

*/
#include <NewSoftSerial.h>  // real serial is being used for debug with arduino gui

NewSoftSerial serial_lcd(10, 9); //rx tx
void serial_lcd_WriteLine(int lineNum);
void serial_lcd_ShowLine(int lineNum);
void serial_lcd_init();
void serial_lcd_Graph(int graphStyle, int graphLength, int graphPercent);

// static data for graph example
   int graphStyle = 98;  // 98 = capped barchart, 66 = open
   int graphLength = 12; // max length 16, allows a description of 4 chars
//  int graphPercent = 42; //value from sensor??
   int fuelPercent = 25;
   int altPercent = 65;


void setup (){
// print to laptop
 Serial.begin(115200);
 Serial.println("Arduino & TextStar LCD example");
 Serial.println("Dynamic Graphs");
 Serial.println("by James McEwan");
 
// print to serial_lcd
serial_lcd.begin(9600);  // textstar happy at this speed
 
   serial_lcd_init();
   serial_lcd_WriteLine(1);
   serial_lcd.println("Textstar Demo");
   serial_lcd_WriteLine(2);
   serial_lcd.println("by James McEwan");
   serial_lcd_ShowLine(1);


   delay(3000);             // give you a chance to see the result

// show initial values

   serial_lcd_init();
   serial_lcd_WriteLine(1);
   serial_lcd.print("Fuel ");
   serial_lcd.print(fuelPercent);
   serial_lcd.print("%");
   serial_lcd_WriteLine(2);
   serial_lcd.print("Alt  ");
   serial_lcd.print(altPercent);
   serial_lcd.print("%");
   serial_lcd_ShowLine(1);
   
   delay(3000);             // give you a chance to see the result




 
}


void loop (){
 
 // changes bar chart
   serial_lcd_init();
   serial_lcd_WriteLine(1);
   serial_lcd.print("Fuel");
   serial_lcd_Graph(graphStyle, graphLength, fuelPercent );  // draw the graph
   serial_lcd_WriteLine(2);
   serial_lcd.print("Alt ");
   serial_lcd_Graph(graphStyle, graphLength, altPercent );  // draw the graph
   serial_lcd_ShowLine(1);
   
   //delay(50);             // give you a chance to see the result
 
   fuelPercent = --fuelPercent;
   altPercent = ++altPercent;
 
 
 // stop the % going negative - optional
 if (fuelPercent == 0) {
                       fuelPercent = 1;
                       }    
                         
  if (altPercent == 0) {
                        altPercent = 99;
                       }    
                   
}

/* Sends LCD command sequence to initialise the LCD
* Sets cursor style to 'no cursor'
*/
void serial_lcd_init() {
   delay(2500); // let the screen initialise if it has only just been powered up

   /* Clear the display and take us to line 1 cell 1
    * Notice that this instruction to the LCD does not
    * require a command-bit to be send first
    */
   serial_lcd.println(12,BYTE);

   /* Setup the Cursor Style */
   serial_lcd.print(254,BYTE);  // we are sending a command
   serial_lcd.print(67,BYTE);   // we wish to set the cursor style
   serial_lcd.println(0,BYTE);  // we wish to have no cursor
}

/* Sends LCD command sequence to write to LCD line n
* @param  int   lineNum   Line Number to write to
*/
void serial_lcd_WriteLine(int lineNum) {
   serial_lcd.print(254,BYTE);       // we are sending a command
   serial_lcd.print(76,BYTE);        // goto line n command
   serial_lcd.print(lineNum,BYTE);   // clears the line the line number (1-16)
}

/* Sends LCD command sequence to display to LCD line n
* @param  int   lineNum   Line Number to display (top of screen)
*                         will show n and n+1
*/
void serial_lcd_ShowLine(int lineNum) {
   serial_lcd.print(254,BYTE);       // we are sending a command
   serial_lcd.print(71,BYTE);        // display the following line number
   serial_lcd.println(lineNum,BYTE); // the line number (1-16)
}



void serial_lcd_Graph(int graphStyle, int graphLength, int graphPercent){
   serial_lcd.print(254,BYTE);       // we are sending a command
   serial_lcd.print(graphStyle, BYTE);  // setting style 98 for closed graph or 66 for open graph
   serial_lcd.print(graphLength, BYTE);  //setting the number of chars 16 max
   serial_lcd.print(graphPercent, BYTE);  // setting the value to display
}


AltairLabs

Nice work, THANKS !

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy