Page 1 of 1

Which Display unit?

Posted: Sun Oct 05, 2014 6:11 pm
by Dave
Following on from my other post,
Which display unit do I need?
How to connect it to my Arduino Leonardo analog pins?
Can someone provide me with the Sketch to do what I want?

Re-cap from other thread,
I've built myself a Magnetic Loop,
In the loop is a 10 turn potentiometer.
From this potentiometer will be 1 to 5 volts coming back to the Arduino.
I want to connect this potentiometer to the Arduino analog pin and then for the Arduino to convert the volts to be displayed as MHz on the display.
So as the potentiometer is turned from 1v to 5v's the display will run through the MHz,
ie
1v displays as 3.789HMz,
2v displays as 7.150MHz,
3v displays as 14.200MHz.....
I think you get the idea.
Any help here would be very much appreciated.
Regards Dave.

Re: Which Display unit?

Posted: Mon Oct 06, 2014 11:37 am
by andrew
We sell displays in all shapes and sizes but assuming a simple 16 x 2 line character display would be sufficient then our 1602 modules would be your cheapest and easiest options. We sell two versions of theses module. A parallel version:

http://forum.hobbycomponents.com/viewto ... =75&t=1326

And a serial version:

http://forum.hobbycomponents.com/viewto ... =75&t=1125

The serial version is the easiest to wire up to your Leonardo but costs more than the parallel version. Both of the above links contain example sketches and any libraries you may require. Additionally there is also our LCD keypad shield which you can just plug strait in to your Leonardo:

http://forum.hobbycomponents.com/viewtopic.php?f=40&t=4

If you want an example of how to read a voltage from one of the analogue inputs on your Leonardo, there are already some examples in your Arduino development environment. Just take a look under File->Examples->Analog

When you read in a voltage in from an analogue pin it is converted to a value between 0 and 1023 where 0 = 0V and 1023 = 5V. So for example a value of 512 = (5V / 1024) * 512 = 2.5V

I can see for your information that the relationship between frequency and voltage is not linear. So you would either need to work out the equation to convert voltage into frequency (ideal) or if you cant do that you need a 'look up' table kind of like what you have posted but obviously with a lot more values in it.

Re: Which Display unit?

Posted: Mon Oct 06, 2014 2:22 pm
by Dave
Thank you for your helpful reply.
I've just ordered the 1602 from your online shop.
I'll have a good look at it when it arrives and see how it goes.
Just a heads up.... I'm 56, grey and have grand kids so may seem a little slow to catch on.
I've never coded in my life so please bear with me (not literally) but you get what I mean.
Once again many thanks for all your help.

Regards Dave..

ps. uuumm what to buy next??? I know...........

Re: Which Display unit?

Posted: Wed Oct 08, 2014 8:52 am
by andrew
If your into tinkering with electronics, microcontrollers and in particular Arduino boards are a very useful thing to learn how to use. It is a bit of a learning curve but I would break the task you are trying to do into a series of smaller tasks. First of all figure out how to get the display working and what our example sketch is doing to display something on the screen. Once you figure that out try the analogue input examples to see how they work. Then you can have a go at at trying to combine the two to get the information from analogue input onto the screen.

Re: Which Display unit?

Posted: Fri Oct 10, 2014 6:02 pm
by Dave
Hi Andrew.
I got my display this morning and it works well.

I have a small problem with the code that i am using with it.

I put together a code for converting Volts to MHz.
I have 1 to 5 volts coming in to the Arduino Leonardo analog pin 1
The code then out puts the Volts to the display as MHz.
All works good but the text on the display is scrolling and the gaps between each text set is filled with white blocks.

How can I stop this scrolling, center the display and to refresh were it is?

here is the code I using.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
int analogInput = 1;
int refresh = 1000;
float MHz = 0;
int value = 0;

void setup(){
// declaration of pin modes
pinMode(analogInput, INPUT);

// begin sending to LCD
lcd.init();
lcd.init();
}

void loop(){
// Make sure the backlight is turned on
lcd.backlight();
// read the value on analog input
value = analogRead(analogInput);
if (value >= 1023) {
lcd.println("MAX!!");
delay(refresh);
return;
}
else if (value <= 0) {
lcd.println("MIN!!");
delay(refresh);
return;
}
// Volts to MHz
MHz = ((21.15 - 3.70) * value / 1024) + 3.7;

// print to LCD
lcd.print(MHz);
lcd.println("MHz");

// sleep...
delay(refresh);
}

Thanks for any help.
Regards Dave.

Re: Which Display unit?

Posted: Fri Oct 10, 2014 7:07 pm
by Dave
Problem solved.

I've just changed the code a bit.

// print to LCD
lcd.setCursor(0, 0);
lcd.print("Kenwood TS-590S");
lcd.setCursor(4, 1);
lcd.print(MHz),lcd.print(" MHz");

Regards Dave.

Re: Which Display unit?

Posted: Sat Oct 11, 2014 8:27 am
by andrew
Looks like you're on top of things :D

Re: Which Display unit?

Posted: Sat Oct 11, 2014 9:29 am
by Dave
One more thing,
How do I get it to print 7.175 instead of 7.17?
I need it to show 3 decimal places 0.000
any ideas?
Regards Dave.

Re: Which Display unit?

Posted: Mon Oct 13, 2014 10:57 am
by andrew
Try changing the bit of code where you output the frequency from this:

lcd.print(MHz)

to this:

lcd.print(MHz,3)

Re: Which Display unit?

Posted: Mon Oct 13, 2014 2:52 pm
by Dave
Thanks once again Andrew. 8-)
That did the trick.
Regards Dave.