16x2 LCD and serial reading [FIXED]

Hi..

This is my 1st attempts to "play" with arduino.
I'm using a 16x2 LCD with I2c interface connected to a mini pro arduino.
My goal is connect it via serial to a linksys router wrt54gs v1.0 with dd-wrt firmware ( 8 flash ram, with 3.5mg free for scripting and other stuff ) and get some info from it: wan IP, Load average, time and uptime, if any client is connected to it, if internet is up, etc
At this point, searching around, especially over this forum, i succeed to get these infos from the linksys and display it on LCD nicely. I pushed the goal with an new info, internal temperature reading, with a LM35, and success, I got it displayed on the LCD.
I'm not a code guy, i understand what I see on code, but it's hard to me to do it from scratch. So i have an issue, it 4 readings from the serial: wan IP, UPtime, Load Average, Number of clients and if connected to internet. and a separated one analog read from a LM35 temp sensor. The issue, on display I want it by this order, 4 serial data, an at the end temperature.
I tried with delay, while and counter, but never got success, all time i got wrong order for temperature, it will show on 2 or 3 place.
Here the code i used:

/*
 * Displays text sent over the serial port (e.g. from the Serial Monitor) on
 * an attached LCD.
 * DFRobot.com
 *Compatible with the Arduino IDE 1.0
 *Library version:1.1
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
float raw;
const int inPin = 0;
int vx;


void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  Serial.begin(9600);
}

void loop()
{
 vx = 0;
   while(vx < 4){
     int charcount;
  boolean secondline;
  if (Serial.available()) {
    delay(200);
    lcd.clear();
    charcount = 0;
    secondline = false;
    while (Serial.available() > 0) {
      if (charcount > 15 && secondline == false ) {
        lcd.setCursor(0,1);
        secondline = true;
      }
      lcd.write(Serial.read());
      charcount++;
    }
  }
  vx++;
  delay(3500);
}
    int value = analogRead(inPin);
    lcd.setCursor(0, 1);
    float millivolts = (value / 1024.0) * 5000;
    float celsius = millivolts / 10;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("TEMP");
    lcd.setCursor(0,1);
    lcd.print(celsius);
    lcd.print(" Celsius");
    delay(2000);
  vx=0;
}

to send value fron linksys: echo -ne "$NC client" > /dev/tts/1 , simple but working.

Any help is welcome, to guide me to get it working.

Some pics of my linksys and arduino:



Not clear on what you are asking...

Are you saying that you would like to display some values for a certain amount of time, then display some other values, then some other, etc and then start over in the rotation?

start a timer in setup:

startTime - millis()

in loop()

get the elapsed time:
elapsedTime = millis() - startTime

if elapsedTime < first interval (four seconds for example)
//display the first thing

else if elapsedTime < second interval (eight seconds, for example)
//display the next thing

else if ... and so on until:

else
//reset the timer
startTime = millis()

Hi.

Sorry for "not clear".
What I want... maybe looking at the code on the router:

SR="/dev/tts/1"
WIP=`nvram get wan_ipaddr`
NC=`grep 0x /proc/net/arp | grep br0 | wc -l`
DU=`uptime  | cut -c2-9`
UP=`uptime  | cut -c14-20 | sed s/[,]//g`
LD=`uptime  | sed -n -e 's/^.*average: //p' |  sed s/[,]//g`

  sleep 6
    echo -n "WAN IP:         $WIP" > $SR                                #  1 data from router
  sleep 6
 if ! ping -c1 -W1 208.67.222.222  > /dev/null; then
   echo -n "$NC client        no internet" > $SR                #
 else                                                                                           #   2 data from router 
   echo -n "$NC client        connected to net" > $SR    #
 fi
 
 sleep 6
    echo -n "Time $DU   UP $UP " > $SR                            # 3 data from router
 sleep 6
    echo -n "Load            $LD" > $SR                                    # 4 data from router
 sleep 6

So arduino will receive it by this order, and only at the end at positions 5 will read temperature and display it.

Thanks

OK,

You did this in a way I wasn't really familiar. It looks to me that you are transmitting the entire message from the router to the arduino, and displaying it.

I may have taken a different route and simply transmitted an int as a flag for internet up/down and an int for the number of connections.

you then need only to process the changes and update the display.

something like

if serial available, process the message and decode it 

if new number, save it to a variable 

if connection change save it to a variable 

then, 
get the elapsed time:
elapsedTime =  millis() - startTime

if elapsedTime < first interval (four seconds for example)
  //display the internet up/down and connections message

else if elapsedTime < second interval (eight seconds, for example)
  //display the temperature

else
  //reset the timer
  startTime = millis()

Hi

Thanks for you suggestion.

I got it working smoothly :slight_smile: but stay on initial work

I removed the internal loop

vx = 0;
   while(vx < 4){

And add a end line code \n to define last char from serial reading:

char inChar = (char)Serial.read();
          if (inChar != '\n') {
      lcd.write(inChar);
      }
      if (inChar == '\n') {
      stringComplete = true;
      }
      charcount++;
------//
and 

if (stringComplete) {
    int value = analogRead(temp);

Just got a fancy Chinese char when I sent "\n" for new line, need to clean it. :smiley:

That the way I got it working as I need.
As i say, I'm not a coder... some C very long time ago, i just usually work with linux and some bash script, nothing more.
So for me coding is copy-past for know working code and modify it to my needs.
For this tiny protect, I just need some thing really simple and modular for the data coming from the router.
So by this way i can send a lot of info from the router in block of 32 char each without need modify the code in the arduino.

Thanx again for your suggestions.

I like your project, it is a great application of attaching arduino to something that is just sitting there holding onto useful information and not telling anyone!

great work.