Limiting number of decimal places

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
Post Reply
platypus
Posts: 14
Joined: Mon Aug 13, 2012 11:01 am

Limiting number of decimal places

Post by platypus » Wed May 22, 2013 12:32 am

I have a V2.0 lcd shield sitting on an Eleven, V1.0.

There is one line of lcd.print() code that refuses to display a limited number of decimal places.

example;
float Irms = emon1.Irms;
lcd.print(Irms,1);

This should constrain the number of places to one - I get three to four - random!

All other lcd.print() statements for other variables, eg lcd.print(X,1) lcd.print(Y,2) etc play the game and the lcd displays one or two places.

There is nothing anywhere that I can see that would cause one line to be corrupted.

Has anyone seen this random behaviour in their code?

platypus
Posts: 14
Joined: Mon Aug 13, 2012 11:01 am

Re: Limiting number of decimal places

Post by platypus » Wed May 22, 2013 11:34 pm

Only Irms and PF have an issue - the other variables accept the decimal place confinement code.

I agree, there seems nothing wrong with the code - but the problem is there somewhere and why only two of the variables?? Its random!

Don't get a headache from the code...

The code is on http://www.openenergymonitor.org

platypus
Posts: 14
Joined: Mon Aug 13, 2012 11:01 am

Re: Limiting number of decimal places

Post by platypus » Wed May 22, 2013 11:47 pm

Code: Select all

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library

#include <LiquidCrystal.h>

EnergyMonitor emon1;  // Create an instance


LiquidCrystal lcd(8,9,4,5,6,7);


void setup()
{  
  lcd.begin(16,2);
  //Serial.begin(9600);
  
  emon1.voltage(5, 232, 1.5);  // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 570);       // Current: input pin, calibration.

lcd.clear();
}

void loop()
{
    
emon1.calcVI(20,1000);         // Calculate all. No.of wavelengths, time-out
  
  }
  
  lcd.setCursor(0,0);
  
  lcd.print("V=");
  lcd.print(Vrms,1);
  lcd.print(" I=");
  
  }
 
  lcd.print(Irms,1);
  lcd.print("   ");
 
   
  delay(500); 
}
Last edited by platypus on Fri May 24, 2013 10:48 am, edited 1 time in total.

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

Re: Limiting number of decimal places

Post by angusgr » Thu May 23, 2013 1:22 am

platypus wrote: I agree, there seems nothing wrong with the code - but the problem is there somewhere and why only two of the variables?? Its random!
Hi platypus,

Just some random thoughts, in addition to John's suggestion:

- Are the "incorrect" values sensible ones (ie is it the correct number, just with too many digits)?
- What happens if you tell it to print(Vrms, 3) for the same value?
- Do you always get 3-4 decimal places for those variables, or only sometimes/for certain values? Do the extra digits change?
- If you do a Serial.print(Vrms, 1) then does that come out the same (it should use the exact same formatting code for the number, so that narrows it down to either the number formatting code or the LCD display.)

The other thought I had is that the print() for floating point actually takes a 'double' (ie a double-precision floating point number, twice as big as a 'float' with twice the precision), and looking at the EnergyMonitor library it also stores those values as 'doubles' internally. So saving them to a 'float' actually makes the conversion double->float->double, throwing away precision and then adding it back again.

Probably not important when you only care about 1 decimal place, but what happens if you change the local variables from 'float' to 'double' as well?

- Angus

platypus
Posts: 14
Joined: Mon Aug 13, 2012 11:01 am

Re: Limiting number of decimal places

Post by platypus » Thu May 23, 2013 5:14 am

I pulled out my ethermega and ran the data again - same type of lcd.

By the way have a look at this http://arduino.cc/en/Reference/Float
In Arduino, float is the same precision as double - it doesn't matter how they are used - still 4 bytes.

Serial output
V,I,KW,KVA,PF all set as serial.print(X) in the source file code - see back a couple of posts for the cpp - right down the end. The sketch calls data to the serial window using emon1.calcVI()

Default for float or double is 2 dec places

Get 2 dec places for all.

LCD output
Dec places set as (X,1) for V,I,KW,KVA and (X,2) for PF

LCD displays
V, KW,KVA each set as 1 dec place (X,1) - each displays 1 dec place
I displays up to 4 places, PF displays 3 places.

Set (X,2) for V,I and PF (KW,KVA commented out to make room for test)
Had to place V on line(0,0) and I and PF on line(0,1) and removed padding spaces to test display.

LCD with no set places
Get V, 2 places, I, 2 places and PF 3 places - not too bad.

I have a 20,4 lcd which I will setup and try - not sure that it will change things.

The data is not affected, its just an annoyance that output display is not held by all variables.

So the same behaviour on the 328 and the 2560 - so its not the controllers, but the program code.

But the cause seems elusive.

I have seen this behaviour in the past and it was caused then by copy/paste of code.
It was rectified by typing the code in - not this time.

Still,I can live with it - nothing is as perfect as it might appear.

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

Re: Limiting number of decimal places

Post by angusgr » Thu May 23, 2013 6:45 am

platypus wrote: By the way have a look at this http://arduino.cc/en/Reference/Float
In Arduino, float is the same precision as double - it doesn't matter how they are used - still 4 bytes.
How silly of me, thanks for correcting.

Looking at your code and your results again, I don't see any common patterns either. If you remove the EnergyMonitor from the equation entirely and just print known values, are you able to find a combination that reproduces it? (if you can find one then we can run it here, as well.)

At the same time, if you say you can live with it then that might be the least frustrating option in the long run. :)

platypus
Posts: 14
Joined: Mon Aug 13, 2012 11:01 am

Re: Limiting number of decimal places

Post by platypus » Thu May 23, 2013 7:22 am

Yes,sometimes its not worth chasing things when its very likely tied up somewhere in the IDE source code.

No issues with precision - I have just been head down into it. But appreciate all the efforts put in by you with this rather frustrating issue.

Well its a proto only so I am not concerned.

Just running the ethermega and a 20x4 lcd - bigger screen same @!%#

We will likely move on from this type of proto system very soon into something more elaborate.

But I give these atmegas credit - they are not bad for their speed and memory size.

Thanks for your help.

clibin009
Posts: 563
Joined: Mon Oct 23, 2017 2:57 am

Re: Limiting number of decimal places

Post by clibin009 » Wed Jan 03, 2018 6:15 am

clb0103
michael kors outlet clearance
cheap jordan shoes
ugg boots outlet
oakley sunglasses outlet
coach outlet canada
mulberry
coach outlet online
coach outlet online
canada goose coats
ralph lauren outlet online
cheap ugg boots
adidas nmd r1
polo ralph lauren outlet
canada goose outlet
michael kors outlet online
michael kors outlet online
polo ralph lauren outlet online
cheap ugg boots
the north face jackets
canada goose jackets
fitflops sale
ray ban sunglasses discount
burberry handbags
michael kors outlet clearance
canada goose jackets
pandora jewelry outlet
uggs
coach factory outlet
ray ban glasses
cheap jordans
ugg boots sale
pandora jewelry
coach factory outlet online
moncler
ugg boots
michael kors outlet online
ugg outlet online
coach factorty outlet online
burberry handbags
nmd adidas
yeezy boost 350
michael kors outlet online
michael kors outlet clearance
polo ralph lauren outlet
uggs clearance
timberland outlet
christian louboutin shoes
pandora charms
polo ralph lauren outlet
ralph lauren outlet online
yeezy boost 350
coach purses
canada goose jackets
cheap nfl jerseys wholesale
nike sneakers
ugg outlet online
the north face outlet
moncler coats
north face sale
michael kors outlet online
ralph lauren outlet online
cheap ugg boots
ugg boots
canada goose coats
hermes outlet
canada goose sale
pandora uk
polo ralph lauren outlet online
north face jackets
pandora jewelry
toms shoes
christian louboutin shoes
cheap air jordans
louis vuitton factory outlet
michael kors outlet store
louboutin outlet
mulberry outlet uk
polo ralph lauren outlet online
michael kors outlet store
nike shoes
adidas outlet
uggs clearance
ugg outlet store
ralph lauren outlet online
canada goose outlet online
ugg outlet
nike outlet store
polo ralph lauren outlet online
hermes bags
coach factory outlet
canada goose jackets uk
cheap oakley sunglasses
louis vuitton outlet online
coach outlet online
coach outlet store online
longchamp sale
ugg boots
moncler sale
michael kors
adidas yeezy boost
red bottom heels
coach factory outlet online
uggs outlet
pandora charms outlet
nike outlet store online
north face jackets
pandora outlet
birkenstock outlet
fitflops sale clearance
nfl jerseys
cheap jordans free shipping
canada goose sale
adidas nmd runner
canada goose
mulberry handbags
ugg canada
ralph lauren outlet online
cheap jordan shoes
coach outlet online
canada goose jackets
canada goose jackets
ralph lauren sale
jordans
canada goose jackets
polo ralph lauren outlet online
cheap ugg boots
moncler outlet online
canada goose jackets
canada goose jackets
ugg outlet store
yeezy shoes
ugg canada
coach outlet online
pandora outlet
moncler outlet online
kate spade handbags
adidas shoes
canada goose sale
canada goose coats
pandora charms sale clearance
tory burch outlet online
hermes bag
gucci outlet online
louboutin outlet
canada goose jackets
cheap air jordans
kate spade handbags
coach factorty outlet online
cheap air jordans
bottes ugg
canada goose jackets
coach outlet online
michael kors outlet online
burberry handbags
pandora sale clearance
the north face outlet
michael kors outlet online
canada goose outlet
louis vuitton factory outlet
ugg outlet
ugg boots
michael kors outlet store
fitflop sandals
ferragamo outlet
oakley sunglasses for women
coach outlet online
mulberry uk
timberland outlet store
canada goose jackets
ralph lauren uk
valentino
caterpillar boots
ralph lauren
mlb jerseys
coach outlet
ugg outlet online
ugg boots
canada goose jackets
ugg boots
discount oakley sunglasses
pandora jewelry
hermens
coach factory outlet online
adidas yeezy boost
coach factory outlet online
philipp plein
tory burch outlet online
gucci outlet
canada goose outlet store
michael kors
cheap nike shoes
coach outlet store
coach outlet store
adidas nmd runner
coach outlet online
north face outlet
polo ralph lauren outlet
cheap jordan shoes
louis vuitton handbags
canada goose jackets
pandora jewelry store
ugg boots
nike outlet online
moncler uk
ferragamo shoes
adidas
ugg boots
ray ban sunglasses discount
cheap nfl jerseys wholesale
red bottoms
birkin handbags
uggs outlet
nike zoom
canada goose outlet
louboutin shoes
pandora jewelry outlet
fred perry polo shirts
oakley sunglasses outlet
uggs outlet
louis vuitton outlet store
yeezy boost 350
kate spade outlet
burberry outlet online
fred perry shirts
valentino outlet
coach handbags outlet
adidas yeezy shoes
polo ralph lauren outlet
canada goose jackets
cheap jordan shoes
ralph lauren outlet
michael kors
ray bans
michael kors outlet store
moncler outlet online
canada goose
pandora uk
pandora charms sale clearance
moncler jacket
columbia sportswear outlet
adidas campus shoes
pandora charms outlet
ralph lauren uk
air max shoes
uggs outlet
moncler jackets
polo ralph lauren outlet
pandora charms sale clearance
coach outlet online
mbt
ray ban sunglasses cheap
longchamp bags
moncler sale
coach outlet store online
uggs outlet
michael kors bags
uggs outlet
coach outlet online
coach outlet online
ugg boots
polo ralph lauren
moncler jackets
cheap oakley sunglasses
oakley sunglasses outlet
uggs outlet
christian louboutin sale
moncler outlet online
coach outlet online
ralph lauren
cheap jordan shoes
coach factory outlet
ugg boots outlet
ralph lauren sale
cheap oakley sunglasses
michael kors
coach outlet canada
cheap ray ban sunglasses
pandora charms sale clearance
canada goose coats
fitflops sale
ugg outlet
adidas superstars
adidas outlet store
ralph lauren outlet online
adidas nmd r1
uggs outlet
ugg outlet store
ugg boots
coach factory outlet
nike shoes
yeezy shoes
cheap jordans for sale
kate spade outlet online
canada goose outlet
supreme shirts
coach outlet online
coach outlet online
fitflop sandals
michael kors handbags
nfl jerseys
pandora charms
coach outlet store
uggs outlet
pandora charms
michael kors outlet store
adidas nmd r1
tory burch shoes
polo ralph lauren
mbt shoes sale
ugg boots women
coach outlet online
coach factory outlet online
salvatore ferragamo outlet
air max
ralph lauren
yeezy shoes
coach factory outlet online
red bottom
michael kors bags
mlb jerseys
ralph lauren uk
the north face outlet
air jordan shoes
polo outlet online
ray bans
adidas outlet online
discount ray ban sunglasses
hermes handbags
michael kors outlet online
coach factory outlet
mlb jerseys cheap
louis vuitton factory outlet
ralph lauren uk
kate spade outlet online
ugg outlet store
ugg outlet
louis vuitton outlet
kate spade handbags
adidas nmd r1
michael kors
canada goose outlet online
ray ban sunglasses discount
moncler jackets
canada goose coats
michael kors handbags outlet
adidas store
coach outlet online
michael kors outlet store
canada goose parka
adidas yeezy
longchamps
coach outlet online
uggs on sale
michael kors outlet store
nike outlet
air jordan retro
mbt
ray ban sunglasses sale
adidas yeezy boost
canada goose
christian louboutin shoes
nike sneakers
adidas ultra boost
ugg outlet
nike air max 97
uggs outlet
harden vol 1
canada goose jackets
timberland boots
moncler coats
adidas yeezy
coach outlet online
yeezy boost 350
fitflop shoes
longchamp outlet
pandora charms sale
ugg
canada goose sale
ray ban sunglasses outlet
kate spade outlet
canada goose jacket
longchamp outlet store
hermes bags
nike outlet online
canada goose jackets
uggs outlet
ugg boots
ugg sale
nike air max 97
longchamp bags
ugg boots outlet
coach outlet online
nike outlet store
nike air max 2018
yeezy boost
kate spade outlet online
adidas outlet store
canada goose jackets
canada goose outlet
adidas sneakers
kate spade outlet online
salvatore ferragamo shoes
ray ban sunglasses outlet
michael kors outlet online
supreme uk
michael kors outlet clearance
air jordans
michael kors outlet store
coach outlet store online
cheap ray ban sunglasses
north face outlet
adidas superstar shoes
kate spade handbags
pandora charms outlet
timberland outlet
moncler uk
coach factory outlet online
burberry outlet online
pandora jewelry
supreme clothing
retro 11
oakley sunglasses outlet
pandora charms outlet
moncler pas cher
burberry outlet
nike air max 2018
canada goose outlet
michael kors outlet canada
canada goose
michael kors outlet
adidas yeezy boost 350
ralph lauren outlet online
canada goose jackets
michael kors outlet clearance
canada goose coats
moncler coats
polo ralph lauren outlet
air max
coach factory outlet online
jordan shoes for sale
adidas outlet online
cheap ray bans
ralph lauren outlet online
pandora charms sale
canada goose jackets
louis vuitton outlet online
ugg boots
coach outlet store online clearance
coach outlet online
philipp plein outlet
birkenstock shoes
uggs on sale
coach factory outlet online
uggs outlet
cheap uggs
cheap oakley sunglasses
uggs outlet
supreme shirts
nfl jerseys
coach outlet online
ralph lauren
canada goose sale
burberry outlet online
michael kors outlet canada
coach factory outlet online
coach factory outlet online
clb0103


somphob78900
Posts: 68
Joined: Mon Dec 25, 2017 4:27 am

Re: Limiting number of decimal places

Post by somphob78900 » Thu Feb 01, 2018 3:09 am

Image

Welcome to the best online casino. For members and gamblers who like to play casino games and slots online.
With online casino games and gambling, gclub ผ่านเว็บ
many sports are available for you to play with.
Get many promotions, whether they are old or new. We can get bonuses immediately.


Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests