## ADC input display on LCD in voltage

13 posts / 0 new
Author
Message

Task: Develop a program that displays the voltage at the input channel A0 as a single bar graph and number on the LCD. The voltage range is 0-5v.

How to take input from adc and then display it as voltage on lcd. I am using Avr studio 4.

Last Edited: Mon. Jun 26, 2017 - 03:48 PM

What micro? In other words - is there enough room for a floating point library and a floating point display routine? (to be on the safe side you probably need a 4K micro or larger for all that - probably ~1K for the floating point maths and ~2K for the floating point printf()).

Oh and when you say "Studio 4" do you mean JUST Studio 4 which, by implication means the Atmel assembler or is C going to be involved in this somewhere?

Micro is atmega128. Avr studio 4 software that uses C language

Avr studio 4 software that uses C language
But Studio 4 does not come with a C compiler? Presumably you have added either "WinAVR" or "Atmel Toolchain for Windows" to it?

Anyway, in a 128K micro you should have no problem using floating point if you want to.

After that it's simply a case of translating the 0..1023 reading you get from the ADC into a 0 .. 5.0V value to show on the display. As you can use floating point you might as well use:

```float volts = (ADC / 1023.0f) * 5.0;
sprintf(buffer, "V = %0.2f", volts);```

or something along those lines.

Say the reading was 735 then you would get 735 / 1023.0f = 0.71848 then 0.71848 * 5.0 is 3.59238. Using "%0.2f" means "show this with just 2 decimal places" so the display value in buffer[] would be "V = 3.59". Then it's just a question of sending the contents of buffer[] to be displayed on the LCD.

So why are you posting in the Site Feedback forum?!

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

awneil wrote:
So why are you posting in the Site Feedback forum?!
ignore that comment  - I have moved it.

(Andy either use "report" or tell the user to post elsewhere - don't do both - it will just cause confusion).

...and number on the LCD...

Quite a spec you have given.  Tell us more about this assignment.  School work?  Work for hire?

There are many different types of "LCD".  Which type/size/characteristics are we to work with?

...and others.

I've posted my "character LCD" bar graph before...

https://www.avrfreaks.net/comment...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. Jun 26, 2017 - 04:06 PM

Please show how to send buffer value to LCD.

In case the post from theusch didn't make it clear: We can say nothing meaningful unless you tell us what type of display you're working with. And make and model, preferably.

7-segment?

Character based?

Graphics display?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Just to note that whatever kind of "LCD" it is you are talking about there's a pretty strong chance someone has already written some "library" code to support it. So there a probably functions available like lcd_init(), lcd_putchar() and lcd_putstring(). But as the others have said you will have to say what kind of LCD display it is first. I'm guessing that of the choices Lee showed it's most likely to be something like:

if it is then the kind of code you are looking for is "HD44780" - it is VERY common.

Well, I would shun 7 segments, as they are complicated to program (eat 7+n pins, if multiplexing n denotes the number of digits you want to display or the length of the bargraf; if they are not multiplexed, change "+" into "*" .... and current consumption is likely to increase, too). They may be more expensive than other types...

Nobody can give a ready solution with graphic (monochrome? colored? I2C interface?SPI interface? other?) displays, without a crystal ball or telepathic talents. Edited : some maybe cheaper, now, than character devices....

For character based LCD, http://www.johanekdahl.se/rwiki/... gives links to documentation, fully tested libraries and a simple, demo oriented  library  (carefully initialises the LCD; send a char to the LCD and goes to the next position).

I suppose you have a 16x1 char LCD, and a 16 bits rawvalue (0..1023)

integer result (in volts) is (rawvalue*5)/1023, very near (0.1% error, less than usual 5v references) (rawvalue*5)/1024 -> this value can be converted into an integer, and send, char after char, to the LCD.

Then comes a decimal point -> sending it to the LCD is very trivial

Suppose yoy want 1+2 digits (ex : display 2.57) decimal part is ((rawvalue *500uL) /1024uL)  % 100 ; then, one justs has to convert it into decimal, with leading zeroes,  and send each and every char to the LCD

For an horizontal bargraph it should be  say, max 16 chars long (and a char like '*' or '#' might be pretty)

you divide the maximum voltage into 1024/16 values == 64 value

for (int iv =  0; iv  < rawvalue; iv = iv +64)  LcdSendByte  LcdSendCharacter ("#') ; // edited....

might  be enough....

Last Edited: Mon. Jun 26, 2017 - 05:59 PM

clawson wrote:
there's a pretty strong chance someone has already written some "library" code to support it.

The most important thing is not to try to do everything all at once!

Start simple; Take it one step at a time.

eg, start by just writing fixed text such as "Hello, World!" to the LCD.

Then a run-time variable number - just a count in a loop.

etc, etc, ...

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...