LCD Display shows weird character

I am using this LCD display, http://www.adafruit.com/products/715 with a Arduino Uno Ethernet board. It also has an RFID reader (http://www.adafruit.com/products/364) but I haven’t really implemented the RFID yet.

Anyways, everything works pretty good so far. I am using this to create a timeclock and I created a restful API and that is what I am coding against. Anyways, the API I am dealing with an the moment returns the current time in the format hh:mm<am|pm>. So, I got that working, but what happens is that I get the time, and when I try to write it out to the LCD the character directly in front of the time is strange. Anyways, here is the code - please note that there is a few variables that aren’t used but that’s cause they’re is another setup that has the rest of the hardware implemented and I’m kind of merging the two.

// include the library code:
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_PN532.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// Param Order:    SCK, MISO, MOSI, SSEL
Adafruit_PN532 nfc(4, 5, 3, 2);

char* lcdText[] = {"", ""};
char* current_time = "GET /timeclock/current_time HTTP/1.1";
char* employee_api = "GET /timeclock/employee/rx/xyz HTTP/1.1";
char* payperiod_api = "GET /timeclock/payperiod/tx/xyz HTTP/1.1";
char response_used[512];
char* action;

int crlf = 0;
int char_int = 0;
int main_loop = 0;

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB9, 0xF0 };
EthernetClient client;

void writeToLCD(char* text1 = "", char* text2 = "") {
  if (lcdText[0] != text1 || lcdText[1] != text2) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(text1);
    lcd.setCursor(0,1);
    lcd.print(text2);
    Serial.print("Text: "); Serial.println(text2);
    
    lcdText[0] = text1;
    lcdText[1] = text2;
    
    lcd.setCursor(0,0);
  }
}

void setup() {
  uint32_t ChipVersion;
  
  Serial.begin(9600);
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  nfc.begin();
  ChipVersion = nfc.getFirmwareVersion();

  if (Ethernet.begin(mac) == 0) {
    writeToLCD("    Ethernet", "     Failed");
  }

  Serial.println(Ethernet.localIP());
  write_request(current_time);
  action = "current_time";
  
  lcd.setCursor(0,0);
  if (!ChipVersion) {
    writeToLCD("RFID Error", "");
  } else {
    writeToLCD("Company Name", "Initializing");
    nfc.SAMConfig();
  }
}

void loop(void) {
  lcd.noBlink();
  main_loop++;
  
  if (main_loop == 360) {
    main_loop = 0;
    if (action != "current_time") {
      write_request(current_time);
      action = "current_time";
      main_loop = 359;
    }
  }
  
  while (client.available()) {
    char c = client.read();
    
    if (c == '\r' || c == '\n') {
      crlf++;
    } else {
      if (crlf != 4) {
        crlf = 0;
      }
    }
    
    if (crlf == 4) {
      response_used[char_int] = c;
      char_int++;
    }
  }
  
  if (!client.connected()) {
    client.stop();
  }
  
  writeToLCD("Company Name", response_used);
} //End loop

Output of Serial Monitor:

192.168.150.117
Text: Initializing
Text: 
9:00am

Output Of LCD:

['C', 'o', 'm', 'p', 'a', 'n', 'y', ' ', 'n', 'a', 'm', 'e', '', '', '', '']
['[]', '9', ':', '0', '0', 'a', 'm', '', '', '', '', '', '', '', '', '']

So basically that [] is the part I am trying to get rid of and I’m not 100% sure why it’s there… Anyways, thanks!

Well, I fixed it.

// include the library code:
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_PN532.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// Param Order:    SCK, MISO, MOSI, SSEL
Adafruit_PN532 nfc(4, 5, 3, 2);

char* lcdText[] = {"", ""};
char* current_time = "GET /timeclock/current_time HTTP/1.1";
char* employee_api = "GET /timeclock/employee/rx/xyz HTTP/1.1";
char* payperiod_api = "GET /timeclock/payperiod/tx/xyz HTTP/1.1";
char response_used[512];
char* action;

int crlf = 0;
int char_int = 0;
int main_loop = 0;
int ascii=0;

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB9, 0xF0 };
EthernetClient client;

void writeToLCD(char* text1 = "", char* text2 = "") {
  if (lcdText[0] != text1 || lcdText[1] != text2) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(text1);
    lcd.setCursor(0,1);
    lcd.print(text2);
    
    lcdText[0] = text1;
    lcdText[1] = text2;
    
    lcd.setCursor(0,0);
  }
}

void setup() {
  uint32_t ChipVersion;
  
  Serial.begin(9600);
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  nfc.begin();
  ChipVersion = nfc.getFirmwareVersion();

  if (Ethernet.begin(mac) == 0) {
    writeToLCD("    Ethernet", "     Failed");
  }

  Serial.println(Ethernet.localIP());
  write_request(current_time);
  action = "current_time";
  
  lcd.setCursor(0,0);
  if (!ChipVersion) {
    writeToLCD("RFID Error", "");
  } else {
    writeToLCD("Company Name", "Initializing");
    nfc.SAMConfig();
  }
}

void loop(void) {
  lcd.noBlink();
  main_loop++;
  
  if (main_loop == 360) {
    main_loop = 0;
    if (action != "current_time") {
      write_request(current_time);
      action = "current_time";
      main_loop = 359;
    }
  }
  
  while (client.available()) {
    char c = client.read();
    
    if (c == '\r' || c == '\n') {
      crlf++;
    } else {
      if (crlf != 4) {
        crlf = 0;
      }
    }
    
    if (crlf == 4) {
      ascii = c;
      if (ascii >= 32 && ascii <= 126) {
        response_used[char_int] = c;
        char_int++;
      }
    }
  }
  
  if (!client.connected()) {
    client.stop();
  }
  
  writeToLCD("Company Name", response_used);
  //menu();
  //punch();
} //End loop

It was returning an extra CR/LF. So, now it just checks to see if the response is an ASCII character.