How to display 4 sets of data on lower line

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
Post Reply
brewski850
Posts: 5
Joined: Tue Jul 23, 2013 10:03 am

How to display 4 sets of data on lower line

Post by brewski850 » Tue Jul 23, 2013 10:15 am

Hi All,
I'm new to Arduino but bought an Arduino Uno plus LCD shield (16x2) two weeks ago.
I've been playing around with some programming & have adapted a Wattmeter sketch I found that displays Voltage, Amps on one line and Watts, Time on second line.

I have modified code to include WattHours & AmpHours & want to show this alternately on second line with Watts & Time.

Can anyone help?

Cheers,
Brewski

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: How to display 4 sets of data on lower line

Post by angusgr » Tue Jul 23, 2013 10:52 pm

Hi Brewski,

Can you post your sketch somewhere so we can have a look?

You can either insert it here (use the "Code" button at the top to put it in a "code block" so it formats correctly) or you can use a service like Pastebin and just post a link.

- Angus

brewski850
Posts: 5
Joined: Tue Jul 23, 2013 10:03 am

Re: How to display 4 sets of data on lower line

Post by brewski850 » Wed Jul 31, 2013 12:36 am

Hi Angus,

I joined Pastebin & hopefully this link will take you to the wattmeter sketch.
http://pastebin.com/10m7umdA

I was initially trying to show TIME (since unit connected to 12V to power connected appliance) & Watt Hours alternately on second line of display. When this didn't work successfully & then tried to combine the Wattmeter sketch with LCD shield button detect & backlight sketch to reduce power consumption of display. I removed the duplicate lines but no success.I guess too many things trying to write to only two lines of LCD?

Thanks,
Brewski850

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: How to display 4 sets of data on lower line

Post by angusgr » Thu Aug 01, 2013 12:11 am

Thanks for posting the code. I didn't actually realise you could "join" pastebin, I usually just paste whatever I have in on the front page! I should think about creating an account too.

So at the moment your code for writing to the second line is this:

Code: Select all

   lcd.setCursor(0,1);
   lcd.print(watts);
   lcd.print(" W ");
   lcd.print(ampHours);
   lcd.print(" Ah ");
If you want to alternate between these values and some other values then you can do so by checking the time (which you conveniently already have in a variable) and switching back and forth every second or two.

Here's the time bit of the sketch, for anyone else following along:

Code: Select all

unsigned long msec = millis();
float time = (float) msec / 1000.0;
The easy way to switch based on the time is with modular arithmetic.

For example, to switch every three seconds you can make an if statement like this:

Code: Select all

   lcd.setCursor(0,1);
   if( (int)time % 6 < 3 ) {
      lcd.print("First choice for bottom line");
   }
   else {
      lcd.print("Second choice for bottom line");
   }
The expression (int)time % 6 means:

* First, convert time from a float to an integer (ie round it down.)
* Then "time modulo 6", ie divide by six and look at the remainder (which will be a number 0 -5.)
* If the remainder is 0,1 or 2 then print the first choice, if the remainder is 3,4 or 5 then print the second choice.

This way the second line will switch between the two alternatives every three seconds.

You can probably see how to modify this snippet to make the second line change with different timings.

I haven't compiled or run the code above, so please let me know if you hit any problems with it. :)

- Angus

brewski850
Posts: 5
Joined: Tue Jul 23, 2013 10:03 am

Re: How to display 4 sets of data on lower line

Post by brewski850 » Tue Sep 03, 2013 2:11 am

Hi Angus,

Your solution worked perfectly.

My next challenge is getting a 1.8" TFT LCD (128 x 160) using ST7735 controller IC to take place of the 16 x2 LCD by modifying same sketch. I should be able to display all readings at same time using this graphic TFT LCD.
BTW. I am developing this Arduino Uno based Wattmeter to monitor a 2 x AGM battery bank with solar panel or generator charging & keep track of what is going in & what is being used so that batteries are never discharged below 50%.
Commercial 12/24VDC Wattmeters that show AmpHours, WattHours, voltage & current for this application are approx. $400.

Cheers..Bruce

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: How to display 4 sets of data on lower line

Post by angusgr » Tue Sep 03, 2013 9:17 am

Good to hear it's working!
brewski850 wrote: My next challenge is getting a 1.8" TFT LCD (128 x 160) using ST7735 controller IC to take place of the 16 x2 LCD by modifying same sketch. I should be able to display all readings at same time using this graphic TFT LCD.
There's our OLED128 as well if you're looking for alternatives, should be able to fit all the readings plus easily daylight readable. :) But nothing wrong with the TFT otherwise!
brewski850 wrote:BTW. I am developing this Arduino Uno based Wattmeter to monitor a 2 x AGM battery bank with solar panel or generator charging & keep track of what is going in & what is being used so that batteries are never discharged below 50%.
Commercial 12/24VDC Wattmeters that show AmpHours, WattHours, voltage & current for this application are approx. $400.
Very nice! I hope you write up some details of the whole project when you're done.

Cheers,

Angus

Cheers..Bruce[/quote]

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests