Hi again,
Well the result was like night and day. While I can't paste the LCD output, the only non-printable characters in the feed were (of course) LF & CR. Worked first time, and every time. Using the inbuilt UART is the way to go for the WiFly bee. Would be happy to hear if anyone works out how to get one running with SoftwareSerial for flexibility.
The other difference is I didn't need to add any delay after writing to the WiFly for it to respond.
For the record, here's my test code outputting to the I2C 16x2 LCD:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int waitTime = 2000;
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup(void) {
// start serial port
Serial.begin(9600); // WiFly
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear();
lcd.print("Starting in");
for (int i=0; i<15; i++) {
lcd.setCursor(0,1);
lcd.print(15-i, DEC);
lcd.print("...");
delay(1000); // allow 15 secs to reset WiFly bee manually if required
}
}
void doWiFlyCommand(const char* commandString) {
// write string to WiFly bee's serial buffer,
// then read WiFly bee's serial output buffer for results
int lcdPos = 1;
char thisChar;
lcd.clear();
for(int idx = 0; commandString[idx] != '\0'; idx++) {
lcd.print(commandString[idx]);
Serial.print(commandString[idx]); // to WiFly
}
lcd.print(":");
lcd.setCursor(0,1); // 2nd line
Serial.println(); // to WiFly
while(Serial.available()) {
thisChar = Serial.read();
if(byte(thisChar) != 10 && byte(thisChar) != 13) {
lcd.print(thisChar);
lcdPos++;
if(lcdPos > 15) lcdPos = 1;
if(lcdPos == 1) { // display wrap
lcd.setCursor(15,0);
lcd.print("+"); // + at end of top line indicates lower display line has wrapped
lcd.setCursor(0,1); // next char will be output at start of 2nd row again
delay(waitTime / 2); // after a short pause so you get to read it
}
}
}
delay(waitTime);
}
void loop(void) {
delay(300); // 250ms delay either side of command mode signal
Serial.print("$$"); // to WiFly
delay(300); // 250ms delay in going into command mode in the WiFly
lcd.clear();
lcd.print("Running...");
lcd.setCursor(0,1);
while (Serial.available()) lcd.print(char(Serial.read()));
doWiFlyCommand("show connection"); // status of WiFly bee
doWiFlyCommand("lites"); // on-board disco light show
doWiFlyCommand("get everything");
doWiFlyCommand("lookup google.com"); // DNS lookup
doWiFlyCommand("lites"); // turn off light-show
doWiFlyCommand("exit"); // depart command mode
}
Thanks for your suggestions Paul, and to the other lurkers who read all that text.
So now: back to the project at hand
Geoff