Go Down

Topic: Three voltage measurements + output to a LCD screen (Read 3 times) previous topic - next topic

PaulS

Quote
I guess it would be more sensible to measure the range of 0-10v so 5v sits in the middle.

Not on an Arduino, it wouldn't. You can only measure 0 to 5 volts.

dtokez

I need to use a voltage divider I think, and if I used two 10ohm resistors I should get 2.5v from 5v according to my calculations?

The thing I'm confused about is how would I adapt the coding?

PaulS

Quote
I need to use a voltage divider I think, and if I used two 10ohm resistors I should get 2.5v from 5v according to my calculations?

Yes.

Quote
The thing I'm confused about is how would I adapt the coding?

You still call analogRead() to get the ratio of input voltage to 5.0V, on a 0 to 1023 scale. That the measured/computed voltage came from the center tap of a voltage divider is irrelevant. If you want the measured/computed voltage to be shown with respect to some other scale, divide by R1/(R1+R2) or R2/(R1+R2) as appropriate (where R1 and R2 are the resistor values).

dtokez

Got it working now thanks  8)

I did not use 10 ohm resistors though as the current would have been stupid lol silly me!

One thing though, is there a way of calibrating, or is there no real reason why it should not be accurate?

when I place a voltage on one of the inputs, sometimes (more often than not) one of the other inputs rise a little. is this just noise?

I don't really want to decrease the value of the pull down's because someone suggested that its not really that good to have the analogue pulling to gnd

thanks for all the help  :)

liudr


I did not use 10 ohm resistors though as the current would have been stupid lol silly me!
or all the help  :)


You have a tendency to use small resistors where you should use big. You may have been confused between small power and small resistance. Small resistance with the same voltage needs large power. If you measure something you don't want to suck a lot of power from the signal to cause it to drop, like you don't want to put turn your microphone into a power source since regardless how loud you are the microphone won't be able to provide enough power for anything.

When you use default analog reference, it is tied (I guess) to the arduino 5V regulator or usb. These voltages are not very accurate. YOu should measure your arduino 5V-gnd voltage difference and scale the 1024 (not 1023) to this value. Say your arduino gives 5.02V, then each step is 5.02/1024(V). Make sure you do this if you want better accuracy.

dtokez

Excellent thanks, |measured Aref to gnd and got a difference of 5.02v so you were bang on :)

When I measure the 5v line to gnd I get about 4.9v - But I guess its the analoge ref that counts?

One issue I'm having is that sometimes the board does not run when first plugged in, I have to reset. This would be a bit of a pain once its mounted in an enclosure lol
Is there something wrong with the setup in the code?
Here is what I have now..

Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int analoginput = 0;
int analoginput1 = 1;
int analoginput2 = 2;
float vin = 0.0;
float vin1 = 0.0;
float vin2 = 0.0;

void setup(){
 
// declaration of pin modes
lcd.begin(16, 2);
delay(100);


    lcd.setCursor(0, 0);
   lcd.print("REAPsystems V1.1");
       lcd.setCursor(0, 1);
   lcd.print("iSensor tester");
   
   
   delay(4000);
   
   
   
  lcd.clear();

}



void loop(){
 
 
     delay(1400);


// read the value on analog input
lcd.setCursor(0,0);
lcd.print ("Vin:");
vin = analogRead(analoginput)*5.023/1024*2;
lcd.print(vin, 3);
lcd.setCursor(9,0);
lcd.print ("v");

lcd.setCursor(0,1);
lcd.print ("A:");
vin1 = analogRead(analoginput1)*5.023/1024;
lcd.print(vin1, 2);
lcd.setCursor(6,1);
lcd.print ("v");


lcd.setCursor(9,1);
lcd.print ("B:");
vin2 = analogRead(analoginput2)*5.023/1024;
lcd.print(vin2, 2);
lcd.setCursor(15,1);
lcd.print ("v");


delay(1400);

}


Thanks for the help!


liudr

I don't see anything wrong with the code. When you said it didn't work the first time you turn on arduino, do you mean the arduino fails to display anything at all?

What is your power source again and did you have a current-limiting resistor on the LCD back light?

Any pictures?

dtokez

#37
Aug 03, 2011, 06:54 pm Last Edit: Aug 03, 2011, 06:59 pm by dtokez Reason: 1
When it first powers up I get solid black along the first line ie. all pixels. 9 times out of 10 it hangs like this until I reset the board, rarely these squares appear for around 1-2 seconds then the code runs.

I have tried powering from 12v dc, and usb both with the same issue?

I am using a 150ohm resistor on the back light to drop from 5v to approx 4v

I have just uploaded a short video, let me know if you can view the format. http://shedbass.net/dtokez/VID_20110803_174424.m4v

thanks again!

liudr

I am still travelling and my file manager gets force stop trying to open your video. I Willy with my laptop. This sounds like the lcd is not initiating properly. Do you have any other lcd to try? Maybe yours is below spec. I have one of these that only workable with extra delays.

dtokez

I think you are right there, i have a same set-up at home (arduino uno, same model lcd) and that is also temperamental with exactly the same fault. I don't have any different LCD's to try I don't think, although I may have a serial display at work that I could possibly look at.

what kind of additions to the code do you have to put in to get your screen to work?

thanks for your time by the way  :)

liudr

You are welcome.

I remember it was about delay(5) after every lcd command. It's a pain so I went and got good working ones. Yours may even need extra delays in init sequence or something (I'm pretending I know what I am talking about ;)). I would not try to mess around inside LiquidCrystal lib just for those two displays. Care to post where you got them for others' sake?

This is a reliable source I have purchased in the past:

http://dipmicro.com/store/LCD-1602A-B

They also has yellow back light but I have not bought yellow ones.

You can also try chinaecomponent(s) on ebay. Bought from them and have not got any problems. I package them and other ones in my phi-2 shield and phi-2 shield 2004 so I know they are reliable.

dtokez

I guess it must be something to do with initial power up, I hope I don't have to have a hardware solution to fix it!

Thanks I will take a look at the links. The thing is we have about 400 of those screens at work, they were given as part payment from a customer, so I have no idea where they came from and it would be really good to be able to get some use out of them so I would like to fathom it out lol.

I tried a delay as the first thing the code runs but no luck :(

your phi-shields look useful I might have to get one for fiddling at home :)

Thanks again

PaulS

Quote
I Willy with my laptop.

You do what? In private, I hope.  8)

liudr


Quote
I Willy with my laptop.

You do what? In private, I hope.  8)

I guess my android phone is a pervert :smiley-mr-green:

dtokez,

Maybe start a new thread in display section and ask about initialization of lcd. 400 lcd certainly deserve some extra work. I thought you had two only.

cyclegadget


  Here are some things that I think could be affected from a "noisy" start-up that might require consideration that I found in the datasheet you provided.

Code: [Select]

• Instruction functions are available by programming
* Display clear , Cursor home , Display ON/OFF , Cursor ON/OFF
• Internal automatic reset circuit at power on.
• Internal oscillation circuit. [code]

It also mentions requiring 4.4volts for the power supply to the LCD. I wonder if you are getting low voltage right when you plug the Arduino in but, not when you are doing a reset.

To throw programming at it you could try putting a delay in before you initialize the LCD. You have nothing to loose if you give that a shot.

Mark




[/code]
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Go Up