Bluetooth Remote Control RGB LED

The Plan

I wanted to add some cool lighting effects to some of my projects and thought I would start playing around with some RGB LED’s.  I want to be able to use my Android device to control the color of the RGB  LEDs.  I will use an Arduino to control the RGB LED.  I will also need a Bluetooth Module to have communications between the Arduino and my Android phone.

Here is the video demo of the completed project….

The RGB LED Research

From my quick research around the web, it turns out that a RGB LED is a pretty simple device.  It essentially is just 3 small LEDs all bunched into one dome.  Here is a crude diagram to illustrate…

RGBLEDSimpleDiagram

My diagram is for a common cathode RGB LED.  There is one ground pin and whichever color LED has a high enough voltage on its leg, it will turn on and glow.  The brightness of the color will depend on the voltage level. Note:There are also common anode RGB LED’s where there are 3 grounds and 1 positive pin but I find that would be less intuitive to use.

The Supplies

The Hardware Diagram

Here is a Fritzing diagram of my setup. BT_RGBLED_Schematic

The Arduino Sketch

The Arduino sketch consist of a loop that reads all the characters coming in on a SW UART looking for key words.  The SW UART is connected to the Bluetooth module which is paired to an Android phone running a custom app sending requests to control the colors of the RGB LED.  Once a key word is found, the line is parsed to determine the color and value to set.  The Android app sends a command with the letter for the color and value between 0 to 255.  The value is the analogWrite value for the PWM pin connected to the corresponding LED color. You can download the full Arduino sketch here: https://drive.google.com/file/d/0B1a0nPfCQQvKS3lCVkJ3czlpbEk/view?usp=sharing.  You will need to have the companion Android app below to make it work.

The Android App

I used MIT’s AppInventor platform to make the companion Android app to send color request through a Bluetooth interface to my Arduino via a HC-06 Bluetooth module.  I based it off of the AppInventor project described in my previous post “Simple Android to Arduino Bluetooth Communication”.  I added 3 slide bars, 1 for each color LED.  There are also 3 text boxes that get updated with the slide bar position whenever the slide bar position changes.  In addition to updating the text box, the value is also concatenated into a “[color letter]:[value]|” command to be sent through the BT interface which is picked up by the Arduino sketch as described above.  Here is a snapshot of the screen setup… Here are the relevant AppInventor blocks… If you would like to install the app on your device, you can get the .apk file here…. https://drive.google.com/file/d/0B1a0nPfCQQvKOHdwdFdhX2pnajQ/view?usp=sharing If you are familiar with the AppInventor environment and would like the .aia file to look at all the blocks an play around with it yourself, you can get it here… https://drive.google.com/file/d/0B1a0nPfCQQvKeGtXV21nQm5jMXM/view?usp=sharing

The Testing

You can see a quick demo video of the setup working at the top of this post.  After playing around with it some more, I do find there are sometimes glitches in the setup.  The color jumps and then self corrects if I slide one of the colors too fast.  Most likely loss of characters during Bluetooth transfer or the 9600 serial port baud rate SW UART is too slow to keep up.  I could probably put in some error checking in the string received, but this is just for simple demos for now.  If I really want this to be in some more elaborate project, I will add the error handling.

Ardiuno Pro-Mini Bring Up

 The Plan

I have been playing around with various projects using my Arduino Uno and Mega.  Each time I have to rip up my previous project to move on to another to re-use the Arduino.  I would like to keep some projects in tact so I found a really cheap Arduino Pro-Mini platform for $3.08.  I bought it here: http://www.banggood.com/Wholesale-New-Ver-Pro-Mini-ATMEGA328-328p-5V-16MHz-Arduino-Compatible-Nano-Size-p-68534.html.  It is cheap enough that I could buy a few and dedicate them to some of my projects.

In addition to being really cheap, it is tiny.  It can be used on projects that I might want to be kept small.  The entire module is not much bigger than quarter.  Here is a picture…

IMG_0828

The Trade Offs /Limitations

Due to the small size (and likely the low price) this board is missing some things:

  1. This Arduino board doesn’t have a USB to serial module on board.  You will not be able to just plug in a USB cable to a PC and start working.  I plan on using a Arduino Uno’s SW UART to communicate with it.
  2. The Uno and Mega is powered from the 5V supply of the USB from the PC.  Since there is no USB port on the Pro-Mini, I will need to find another way to power the board.  If I am already using an Arduino Uno to communicate with it, I can just use the 5V output of the Uno to power it.

The 1st Power Up

All I did was to power up the Pro-Mini using my Uno.  Here is the Fritzing diagram….

ProMiniPowerUp

When power was applied, the power LED turns on and another LED started blinking.  With some probing around, I see that the digital IO pin 13 is the one blinking the LED.  I am assuming that the Arduino example sketch “Blink” was pre-loaded on the board…..

ProMiniBlinkLED

The Sketch Programming Process

I first tried to program the Pro Mini by following several tutorial on line with no success.  I was able to successfully reprogram the boot loader on the Pro Mini using this tutorial… http://arduino.cc/en/Tutorial/ArduinoISP but when I tried to load a sketch, it wouldn’t work.

I also found a tutorial on how to use an FTDI USB to Serial TTL adapter cable to load sketches to the Pro Mini here: http://arduino.cc/en/Guide/ArduinoProMini.  Reading through it, it looked really simple.

  • The serial communication is just using the standard serial RX and TX.
  • Power is supplied using the 5V supply of the USB cable.
  • The only somewhat complicated portion was using the cables RTS line to reset the Arduino.  This pin would be connected to the pin labeled DTR on the Pro Mini board.

Looking at the Pro Mini schematic (http://arduino.cc/en/uploads/Main/Arduino-Pro-Mini-schematic.pdf), this DTR line is a way to toggle the Atmel chips reset line…..

ProMiniDTR

It also looks like the push button can also toggle this reset line.

The Simplified Sketch Programming Process – My version

I really don’t want to purchase a FTDI cable so I came up with my own hack way of using my UNO board to program the Pro Mini.  In essence, I am going to use the USB to Serial module built on the UNO board as an FTDI cable replacement.  To do that…

  • connect the TX of the UNO to the TX of the Pro Mini
  • connect the RX of the UNO to the RX of the Pro Mini
  • connect the 5V of the UNO (which is being powered by the USB cable to the PC) to the VCC of the Pro Mini.
  • disable the rest of the UNO HW by tying the RESET line of the UNO board to ground.

Here is a quick Fritzing diagram…

ProMiniSketchProgrammingSetup

The only thing missing in this simplified set up is that the Arduino IDE can’t reset the Pro Mini during the programming process.  To get around that , I simply manually reset the Pro Mini during the programming process with the push button on the Pro Mini board (not the UNO board).  The sequence is….

  1. Set the board type to the Pro Mini in thd Arduino IDE.
  2. Set the COM port # to the COM port # of the UNO board.
  3. File -> Upload…
  4. When the IDE status is showing “Compiling”, I press and hold the reset button on the Pro Mini board.
  5. When the IDE status reaches “Uploading”, I let go of the reset button on the Pro Mini board.

You have to make sure to let go soon after the “Uploading” shows up.  The time window is about 2-3 seconds so is not that hard to time.  If you wait to long, you will miss the hand shaking during boot up and it won’t work reprogram the Pro Mini.   There is probably some signal I could find on the UNO that I could solder to to make the reset work but I like not needing to make too many mods to get this working.

With this process I can now reprogram my Arduino Pro Mini with HW I already have set up most of the time.

The Cautions

Soldering Capability:

  • The unit I bought did not have any of the headers soldered on.  I had to solder them on myself.  If you are not comfortable soldering, you might not be able to use the board.

L Header Placement:

  • This board has a convenient header with just the 6 essential signals to get the board running on one edge.  The kit also comes with an L header that is intended to be used for it.  I mistakenly soldered it to the underside of the board like the other 2 straight headers.  This causes a problem when trying to plug the board onto a bread board.  The L bracket gets in the way.  Here is a picture of the problem…
  • ProMiniLHeaderProblem
  • Once soldered on, it is really hard to remove since you would need to melt the solder on all 6 pins simultaneously while trying to pull out the header.  I am just living with it on this first one I bought.  Lesson learned.

Simple Android to Arduino Bluetooth Communication

The Plan

In my last post, I showed basic serial communication between an Arduino Uno and a HC-06 Bluetooth module (Arduino + Bluetooth Module Bringup).  I will now show how to use that to send characters back and forth between an Android phone/tablet and the Arduino over Bluetooth using the HC-06 module.

The Setup

Arduino Side:

I have the same Arduino Uno + HC-06 Bluetooth module setup from the above referenced post.  Here is the Fritzing diagram again…

HC06BasicConnectCorrected

I used the same serial passthrough Arduino sketch as I showed in the above referenced post.

DIAGRAM UPDATED: Someone noticed that I had the HV and LV supply reversed in my original diagram. I have corrected it.

Note: I used a HC-05 Fritzing symbol here (only one I could find). The State and Key pins are not there on my HC-06 module. Not sure what they should be connected to if it were a HC-05.

Andriod Phone/Table Side:

I used an Android tablet for my testing.  To prepare for the testing, I powered up the HC-06 module and Bluetooth paired my tablet with the HC-06 using the standard Android Bluetooth settings menu.  When I searched for devices in the Android Bluetooth menu, I saw a new device with name HC-06.  When I tried to pair with it, I was asked for a pin.  I found the default pin listed in the HC-06 datasheet (http://silabs.org.ua/bc4/hc06.pdf) as 1234.  I entered 1234 and successfully paired my Android tablet with the HC-06 module.  The HC-06 data sheet gives the command to change the pin if needed but I am just going to leave it as the 1234 default for now.

Next was to find an Android App that could send and receive Bluetooth characters/strings.  Since I have been playing with MIT’s AppInventor recently (see some of my previous posts with the AppInventor tag), I decided to just build my own.

The Bluetooth Android App

I have a feeling I will be working with Bluetooth often from now on so I decided to make a very generic Android App that can be set to run as BT server or BT client.  Once a BT connection is made in either mode, I want to be able to send and receive characters to the other side.

I created the app in MIT’s AppInventor environment but it would be a little too long to post a tutorial on all the steps.  If you are interested, here is my .aia file if you want to load it into your AppInventor environment and review it on your own….

https://drive.google.com/file/d/0B1a0nPfCQQvKd3NXdkJYeTk4dGM/view?usp=sharing

If you just want to install and use it, here is the .apk file…

https://drive.google.com/file/d/0B1a0nPfCQQvKTk9PZ0JkVG1sSk0/view?usp=sharing

Here are a couple screen shots…

ManualBTscreenshotManualBTScreen2

The App can actually be used without the Arduino + HC-06 setup.  It can even be installed on 2 Android devices then:

  1. Pair the 2 Android devices first
  2. Launched the app on both devices
  3. Click the “Start as Server” button on the 1st device
  4. Click the “Start as Client” button on the 2nd device
  5. If the Bluetooth link is established, the screen on both sides should change to have Send Text / Received Text boxes and Send button.
  6. Just type a string in the Send Text box and hit the Send button.  You should see the string show up in the Received Text box on the other device.

Here is a quick video demo…

The Android to Arduino Bluetooth Test

I didn’t find any documentation on the HC-06 datasheet on how to connect to a BT server so I assumed it was default set up as a BT server.  I launched my Android App and clicked “Start as Client”.  I had previously already BT paired the HC-06 on that tablet so it popped up as one of options to connect to.  I selected HC-06 and the connection was successful.  The red LED on the HC-06 went from blinking to solid on.  When I sent something from the Android App, it showed up in the Arduino serial monitor window.  Now when I typed something in the Arduino serial monitor window, it popped up in the “Received Text” box on the Android App.  Before the Arduino serial to HC-06 was for AT commands, but as soon as a BT connection established, it looks like the HC-06 automatically switched to serial pass through mode.

To better illustrate, here is a quick video demo….

Arduino + Bluetooth Module Bringup

The Plan

I wanted to add Bluetooth communication capabilities to my Arduino projects.  I found a $5.01 Bluetooth module here… http://www.banggood.com/HC-06-Wireless-Bluetooth-Transceiver-RF-Main-Module-Serial-For-Arduino-p-80364.html.  This post shows the basic setup I did to get communications started.

The Hardware Setup

The voltage for the module from the supplier listed above was set for 3.6V – 6V so the Arduino 5V supply output is ok.

I found the data sheet for the HC-06 module here: http://silabs.org.ua/bc4/hc06.pdf.  Unfortunately the Tx and RX voltage is 3.3V still so I also purchased a cheap $1.82 level shifter here: http://www.banggood.com/Logic-Level-Converter-Bi-Directional-IIC-4-Way-Level-Conversion-Module-p-938774.html.

For the basic communication, I just hooked up the TX and RX through the level shifter to a SW UART on my Arduino UNO.  Here is the Fritzing diagram…

HC06BasicConnectCorrected

DIAGRAM UPDATED: Someone noticed that I had the HV and LV supply reversed in my original diagram.  I have corrected it.

Note: I used a HC-05 Fritzing symbol here (only one I could find).  The State and Key pins are not there on my HC-06 module.  Not sure what they should be connected to if it were a HC-05.

The Arduino Code

For the basic test, I am just using a basic pass through Arduino sketch…

/*
 Software serial test
 
 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 6); // RX, TX

void setup() 
{
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 mySerial.begin(9600);

 
}

void loop() // run over and over
{
 while (mySerial.available()>0 )
 Serial.write(mySerial.read());
 
 while (Serial.available()>0 ){
 mySerial.write(Serial.read());
 }
}

The Initial Test / Debug

I uploaded the Arduino sketch and opened the serial monitor and tried to send “AT” to the module.  Nothing came back.  Google’d around and found this post http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/?ALLSTEPS.  One of the comments in the post said that you can’t send NL or CR in the serial communication to the HC-06 module.  Changed the serial monitor settings…

HC06SerialWindowBasicComm

Once I changed the serial monitor to not send any line ending, I was able to send AT+VERSION and get the response in the above screen capture.  Sending any line ending character resulted in no response.

The Next Post

I was able to Bluetooth pair the HC-06 with my Android tablet and write an Android app to send text back and forth to the Arduino.  That will have to be covered in a separate post.  I will post those development steps in my next blog post tomorrow (or sometime soon).

Arduino + ESP8266 remote control LED using an Android App with Camera Live View

The Plan

In several of my previous post, I showed…

  1. …my setup to control LED’s using an Arduino + ESP8266. (LED’s Control Through ESP8266 + Arduino Web Page)
  2. …using the AppInventor environment to send a Web.PutText to send a message to the Arduino. (AppInventor2 Web Interface Trial)
  3. …embedding a live stream of a Foscam Wireless Camera into an AppInventor application. (Real time Wireless Camera view using AppInventor2)

My plan is to now mash up all three into one project.  I will make an app that will send Web.PutText to the Arduino through the ESP8266 to trigger LED light changes and have an embedded live Foscam Wireless window all on the screen on an Android App built in the AppInventor environment.

The Android App (built in AppInventor2)

The screen layout is made up of

  • 6 buttons to turn on/off 3 LED’s.  The buttons are just sending custom WebPutText keywords.
  • A WebViewer element which loads will load web page defined in text box element when the Go button is clicked.
  • Another text box to specify the web address of the Arduino + ESP8266 system.

Here is what is looks like….

RemoteLEDWithLiveViewScreenLayout

The AppInventor code to point the Web component to the ESP8266/Arduino server will set the Web1 URL to point to the web address that is entered in the corresponding text box.  I was running out of screen space and didn’t want to have to add another button so I just have the code run after the address is typed into the box and something else on the screen is touched.  It looks like this…

ArduinoAddressBlock

The code to start up the live camera view is really just creating a Webviewer window which will display the web site specified in the corresponding text box whenever the Go button is clicked.  The rest is really up to the Foscam camera to serve up the live stream….

CameraViewCode

The LED controls are just sending some custom strings using the Web.PutText function.  I am using “PtcApp” as a keyword that is not likely to be seen by the server that I can key off of.  I follow up “PtcApp” keyword with a code for the {first letter of the LED color}:{1 for on / 0 for off}.  The magic will happen on the upcoming Arduino code.  Here is the AppInventor code….

LEDControlCodeBlocks

The Arduino Code

I am only going to cover the additional Arduino code I add to implement the AppInventor functionality here.  The rest of the program has been detailed in many of my previous post.

The first step is really simple.  I just added another parser block to look for “PtcApp” in the incoming line from the ESP8266.  I left all the previous parsing blocks and function so that all the previous features will still continue working (ie: the web page interface is still fully functional).   Once the “PtcApp” is found, I call a function to parse out which color LED to control and if it is a request for On or OFF.  Here is the code snips….

 if (InLine.indexOf("PtcApp ") != -1) {
    CommandQue[QueIn++]=PUT_REQUEST;    //** See next section in post for what this is for **
    ParseCustomAppRequest(InLine);
    UpdateLCDStats();
    NumberAppReq++;
    UpdateLCDStats();
 }
....
//*** This parses out the LED control strings from custom Android App and sets the appropriate state vars *** 
void ParseCustomAppRequest(String InLine){
 if (InLine.indexOf("R:0")!=-1) RED_State=false;
 if (InLine.indexOf("G:0")!=-1) GREEN_State=false;
 if (InLine.indexOf("B:0")!=-1) BLUE_State=false;

 if (InLine.indexOf("R:1")!=-1) RED_State=true;
 if (InLine.indexOf("G:1")!=-1) GREEN_State=true;
 if (InLine.indexOf("B:1")!=-1) BLUE_State=true;
}


The First Test

This all actually started working very well initially.  Everything worked pretty much on the first attempt, but after 5 LED change requests from the Android App, the ESP8266+Arduino stopped seeing any more requests.

Debugging the logs, I found that each PUT request was holding an additional IPD channel open.  (In case you haven’t been following my previous posts, an IPD channel is the ESP8266 way of handling multiple TCP clients.  Each channel corresponds to a client so the server can send messages to a specific client).  The ESP8266 seems to have a limit to only be able to hold open 5 open IPD channels and then stop accepting any more connections.

I remembered another similar situation where the client wasn’t closing the connection.  It was because I wasn’t sending an HTTP header back for a GET request (see the “Extra Fix” section in my post “Arduino + ESP8266 Mini Server with Command Que“).  Hoping it was the same problem I made a very simple HTTP header with 0 length response and send it back each time I get a PUT request…

String PutResponse ="HTTP/1.0 200 OK \r\n"
 "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
 "Content-type: text/html\r\n"
 "Content-length: 0\r\n"
 "Connection: Closed\r\n"
 "\r\n";

...

 case PUT_REQUEST:
    SendCIPChunk(PutResponse,CommandQueIPD_CH[QueOut]); // Send the CIPSEND command to respond to Put request 
    break;

Once I sent back the proper HTTP header, the client automatically closed the connection and all the requests from the AppInventor Web.PutText button clicks were coming in on IPD channel 0 consistently.  I was able to get the LED to change +100 times through a day of testing so I think it is pretty stable now.  🙂

BTW – I will include a link at the end of this post for the full Arduino code to get the complete picture.

The Demo

Here is a short video demoing the setup…

The Arduino Code

If you want the code…

https://drive.google.com/file/d/0B1a0nPfCQQvKenVWUGtvU0RxNEU/view?usp=sharing

AppInventor2 Web Interface Trial

The Plan

So far I have been able to demo using a simple TTY or a more complex HTML web page with an embedded form to control 3 LEDs connected to an Arduino through an ESP8266 wifi module.  I was looking for a way to control things directly from an Android App to make it look cooler and to allow for a more flexible messaging system.  In my last post, I also showed how I started messing around with MIT’s App Inventor 2 environment (Android Programming with AppInventor2).  I tried finding some sort of raw TCP IP connection or UDP packet sender in the App Inventor 2 tools, but couldn’t find anything.  The closest I could find was the Web.PutText and Web.PostText.  This blog post is to show the details of what I found trying to get familiar with this AppInventor feature.

The AppInventor Implementation

The AppInventor screen layout is very simple.  All I want to do at this point is to send either Web.PutText or Web.PostText so I just made 2 buttons on the screen that I can attach some code to.  I also added a Web component with the URL set to the IP address of my ESP8266 (see my previous post “Adding LCD to Web Page Controlled LED” for details on the ESP8266).  Here is a snapshot of the screen layout in AppInventor…

AppInventorWebFeatureTrialScreenLayout

The “code” is also dead simple.

  • When Button1 is clicked, send a Web.PutText with a payload of “Hello put”
  • When Button2 is clicked, send a Web.PostText with a payload of “Hello post”

Here is what the “code” looks like…

AppInventorWebFeatureTrialCode

The Results

I fired up my Arduino + ESP8266 system and launched my AppInventor application on my Android tablet.

When I click the button to test the Web.PutText feature, this is what the Arduino saw coming from the ESP8266…

  • +IPD,0,237:PUT / HTTP/1.1
    User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.2.1; M470BSA Build/JOP40D)
    Host: 192.168.0.175
    Connection: Keep-Alive
    Accept-Encoding: gzip
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 9
    
    Hello put
    OK

When I clicked the button to test the Web.PostText feature, this is what the Arduino saw coming from the ESP8266…

  • +IPD,1,240:POST / HTTP/1.1
    User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.2.1; M470BSA Buil 192.168.0.175
    Connection: Keep-Alive
    Accept-Encoding: gzip
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 10
    
    Hello post
    OK

Both of these will send a full HTTP header before the text that I want to send.  So it isn’t exactly what I wanted like a TTY app which can send just the raw characters, but it still drastically cuts down on the data traffic vs. my previous implementation using a full HTML page with embedded form.  Using the HTML form required me to send a full HTML page just so a user could send back a POST command and then required me to send back another full HTTP header and HTML page.  Now I can build a fully customized Android app that can send a PUT or POST command without needing my server to send it something first.  Also don’t need to send back a full HTTP header and HTML to satisfy the browser.  Should make my system a little more robust when a user has the custom Android app.

The Next

Now that I have a better grasp of what raw data will be going through the ESP8266 when AppInventor calls the Web.PutText function, I will enhance my previous Arduino code to be able to control LED’s from messages coming from a custom Android app utilizing the Web.PutText component.

BTW – I contemplated if I should use the Web.PutText or Web.PostText component and decided to go with the Web.PutText for now.  The Web.PostText sends the string “POST / HTTP” which is identical to the trigger I use for controlling LEDs and sending back a full HTTP header and HTML page with the current LED states when using a HTML form.  The Web.PutText will send a string with “PUT / HTTP” which I am currently NOT looking for.  This will allow me to add to my current system instead of replacing my current system.

Hopefully my next post will be to demo a custom Android App controlling LED through the ESP8266 and Arduino from anywhere in the world where I can access the internet.

Adding LCD to Web Page Controlled LED (Arduino + ESP8266)

The Plan

In my previous post (LED’s Control Through ESP8266 + Arduino Web Page), I demonstrated how I used the ESP8266 and an Arduino Mega to create a web page that could control some LED lights from anyplace I could access the internet.  In my other previous post (Cheap $4.59 LCD with Arduino), I showed how I wired up a very cheap LCD to my Arduino and the demo software that showed how to draw various item and text on the screen.  I have not played around with the LCD a little and am now going to mash the 2 together and display a few key server statistics on the LCD screen.  Amazingly, it wasn’t as hard as I thought it would be.

In some of my previous posts, I already included details about how I have a counter for some key servers stats like number of web pages served, number or LED change request served, etc.  I am going to reuse those same counters and display to the screen.

The Arduino SW

First I draw the basic background of the screen by the following code.  I added comments to help make things easy to understand.

Note: I luckily guessed the LCD library was using the same color codes used for HTML pages.  I used this page to get the colors I wanted… http://www.w3schools.com/html/html_colors.asp

...
#define LCD_NETWORK_ROW 101
#define LCD_IPADDR_ROW 114
#define LCD_GRAY_ROW 101
#define LCD_SERVED_ROW 14
#define LCD_CHANGES_ROW 28
#define LCD_RESETS_ROW 42
...
void SetUpLCDBaseDisplay(){
 myGLCD.InitLCD();
 myGLCD.setFont(SmallFont);
 myGLCD.clrScr();

 //*** Create blue title bar with name ***
 myGLCD.setColor(0, 0, 255); // Blue for interior of rectangle coming up
 myGLCD.fillRect(0, 0, 159, 13); // Draw a solid rectangle from upper left = (0,0) to bottom right (159,13) 
 myGLCD.setBackColor(0, 0, 255); // Blue background for upcoming text
 myGLCD.setColor(255, 255, 255); // White lettering for upcoming text
 myGLCD.print("Pete's ESP8266 Hack", RIGHT, 1); // Write the text right justified at row 1
 
 //*** Create gray bar at bottom with status ***
 myGLCD.setColor(64, 64, 64); // Grey 
 myGLCD.fillRect(0, LCD_GRAY_ROW, 159, 127); // Gray box at bottom of screen
 myGLCD.setBackColor(64, 64, 64); // Gray background for upcoming text
 myGLCD.setColor(255, 255, 255); // White lettering for upcoming text
 myGLCD.print("Network:", LEFT, LCD_NETWORK_ROW); 
 myGLCD.print("...init",RIGHT, LCD_NETWORK_ROW);
 myGLCD.print("IP Add:", LEFT, LCD_IPADDR_ROW);
 myGLCD.print("...init",RIGHT, LCD_IPADDR_ROW);

 //** Create labels for key server stats 
 myGLCD.setBackColor(0, 66, 0); // Darkish Green ... note: lettering is set to white from last above still
 myGLCD.print("LED Changes: " + String(int(NumberLEDRequest)), RIGHT, LCD_CHANGES_ROW);
 myGLCD.print("Web Served: " + String(int(NumberServed)), RIGHT, LCD_SERVED_ROW);
 myGLCD.print("ESP8266 RSTS: " + String(int(NumberOfResets)), RIGHT, LCD_RESETS_ROW); 
}

This is what the screen looks like ..

20141224_233050

Whenever I increment any of my key server stats, I call this function…

void UpdateLCDStats(){
 myGLCD.setBackColor(0, 66, 0); // Darkish green background
 myGLCD.setColor(255, 255, 255); // White lettering
 myGLCD.print(String(int(NumberLEDRequest)), RIGHT, LCD_CHANGES_ROW);
 myGLCD.print(String(int(NumberServed)), RIGHT, LCD_SERVED_ROW);
 myGLCD.print(String(int(NumberOfResets)), RIGHT, LCD_RESETS_ROW);
}

This will update the LCD with the most recent counter values.  I was originally re-writing the entire line including the label, but found that I would sometime miss some of the incoming serial data.  The screen updating turns out to be pretty slow so writing all the characters must have been taking too long.  I minimized the amount of LCD update to just 3 digits to try to avoid this issue.

Here is the full Arduino sketch if you want it…

https://drive.google.com/file/d/0B1a0nPfCQQvKc2otRWY4Tkc4Tkk/view?usp=sharing

Save to your local drive and then you can open it in a text editor if you don’t have the Arduino IDE.

The Results

The testing went pretty well so here is a quick video of the system in action….