Little Bird Electronics posted an article about using an analog voltage reference with Arduino. This is a tool available when using an analog-to-digital converter. By setting up either an internal or external AREF, you can better use the ADC considering its resolution limitations. For instance, if you are measuring a signal that you know will always be below 2V, an external circuit, such as a voltage divider or an adjustable regulator, can give you a reference voltage just above that upper limit; say 2.5V. This way the 1024 divisions of resolution will be spread across your signal’s range, rather than just the lower half of the ADC readings.
Analog references are common to microcontrollers that have ADCs. Even if you’re not working with an Arduino, read through the article and use what you learn with your uC of choice.
Worst post ever ;)
@Alex Rossie:
Why’s that? It explains a neat little trick that will prove most useful in some projects where you have to mess around with analog voltages. Sounds to me like you just don’t understand it.
@tulcod, whats to understand it’s a voltage divider attached to the Aref pin.
This post would only serve a moron, that is a moron who couldn’t use google to find the documentation on this at http://arduino.cc/en/Reference/AnalogReference
Now stop trollin’
@Alex Rossie
/disagree
How ever simple and basic this is alot of people using the arduino are just starting out with ucontrollers and those thoughts do not always occur to them. I remember when I first started I didnt know every little trick. and for that matter still dont.
good tip but isn’t that what the AREF is supposed to be there for? so basically it’s not a hack
He’s wrongfully saying that the external voltage reference may be between zero and 5V which is incorrect. The voltage reference should be between 1V and VCC. Check the datasheet….
A voltage divider hanging between Vcc and Ground is going to inherit whatever noise problems may exist on the Vcc line. The derived reference should at least be bypassed, I think.
A much better solution is to use an external voltage reference, IMO.
@Eardrill
I have always bypassed my VREF but I was just thinking if you leave it at VCC with the noise assuming the same noise is on the sample pin these would cancel out (like an differential input) and give a better reading.?
I dont think I would ever do this but just a thought
agree with zool. this is a good tidbit, i guess, but im 99% sure you’d come across this if you just read a couple paragraphs from the datasheet regarding A/D conversions.
this is why arduino sucks in a way, most people wouldnt think to just go read the atmel datasheet…
@Dext3r: that’s what’s great about Arduino. Most people wouldn’t just go and get into programming microcontrollers. This will wet many people’s appetites who otherwise wouldn’t have even tried, resulting in more electronic hobbyists.
@Mike Szczys,
dont get me wrong, i agree. arduino is pretty great overall. something like this would have been noticed though if you were setting up A/D on your own, so its almost like running in circles, regurgitating the same info. perhaps it could be better on Arduino if the reference was included as part of AnalogRead() in some way.
Why not just use a Zener diode? find one with the right breakdown voltage and set it parallel to ground with the external voltage pin and you are good to go.
This is the oldest trick in the book when it comes to ADC’s, I thought this site was about “hacks”?? :P
@Mike Szcys
Incorrect, sir. A good percentage of the dedicated EE majors I went to school with were playing with microcontrollers since their early high school years, or earlier.Your average “arduino” user will learn very little from simply plugging in code from other people’s projects. The real men (and, ahem, ladies) are defined when they break away from this sheltered little “arduino” world and work with MCU’s on their own! I’m betting that >90% of arduino users have never perused an MCU data sheet, as dext3r says.
@Ekaj: I’ve learned the most from a project which was made by someone else, but then I started to look at datasheets ;)
@Mike Szczys: It’s great that more people will get into uC, but “make it easy enough that even stupid people can use it and it will be used by stupid people”.
This site’s spirit of hacking seems to be about accessibility above most else. No need to knock the intros.
This is exactly why I hate the Arduino. This is really really REALLY basic stuff.
For my next hack, I will set an IO pin to an output! WHOHOO!! And I only needed to use a 30 euro Arduino. And 10kb flash of library.
This is no hack, this is putting two lego pieces together and calling it a house.
@Mike Szcys,
Whet is the appropriate term, not wet.
I may have missed something (I only skimmed the article) but I didn’t see ANY reference that mentions the proper way to do this (ie. using a dedicated reference supply (IC), well regulated, and noise free).
This is what’s wrong with Arduino. It’s either the easy way, or nothing. It would be different if the proper way to do this were taught.
I agree this is not really a hack. It is nice info if I ever need to use the analog IO for some thing other than reading a pot.
I wish the arguing over Arduino vs other development platforms would just go away. I use Arduino for developing custom products for my business. I like the form factor of the varius boards. I USE to do LOTS of programming in varius languages. Unfortunately I did not do much in any of the C variants.
So I am getting work done that needs doing and getting back in to programming. It also looks like if I need to do some thing directly in C I can. So get over it. After I get good with this I will try to program a few PIC chips I ended up with.
@tjb
>I USE to do LOTS of programming in varius >languages.
So what? The only languages that matter in the uC world are C and assembly.
>So I am getting work done that needs
>doing and getting back in to programming.
And your employer is fine with you using lots of third party code a lot of which is GPL etc? Have you had your legal department sign that off?
@cantido some of us DO use GPL code. I work in php, my company typically writes customized plugins and systems for other companies using already existing cms system like Typo3. This way we can do in one week things that could take our competitors about a month. We always give clients code so if they want they can take it and go to someone other for support. We just try to make everything as good as possible so that clients stay with us ;). Using gpl comercially is a viable business model.
@yetihehe
Yes, I have used GPL code too (big companies require code audits and only special approved versions of third party code to be used though)… delivering a plugin for a CMS written in PHP is a little bit different than an embedded device however… One of the big differences being that because PHP is an interpreter you actually escape most of the issues involved in distributing third party code as PHP includes/links against that code and you don’t directly ship it, you just call it.
PHP is essentially the Arduino of the interwebs.
In your situation you only have to give the code to your client under the GPL.. I’m not totally sure that would be the case though, I’m sure you could get away without sharing any code. I guess it depends on what you consider a “derivative work”.
If an embedded product contains GPL code which is attached to some piece of super secret IP and you’re shipping lots of units containing your GPL tainted super secret IP you suddenly have a lot of people that have a legal right to your super secret IP(TM).
Web development != The whole computing/tech industry whatever “web developers” might think.
> Using gpl comercially is a
>viable business model.
Not if you can’t ship your product anymore because you didn’t properly understand the issues involved. Whether or not “using GPL commercially” is a “viable business model” isn’t the issue anyhow. There are businesses doing well and businesses doing badly on both sides of the fence. Open code definitely benefits the small time developer because it means they can “do” (or at least make out that they have) a lot more in less time… the original funds that paid for all that lovely code your using might not be something you agree with though (think DARPA, think all the not so nice players in the web world).
Great article. Remember that for every complaint or whine posted here, there’s hundreds and hundreds of arduino hackers that enjoy reading this. If it’s too simple or trivial for some of you guys, then remember that you are a minority, get over it already. Use your great knowledge to contribute some articles instead.
@cantido
I OWN the business in question. Some projects just get done and out the door. Some projects get a registered copyright. Some just used internally. It depends on the project.
This is not my main biz. Just a side thing that grew out of solving our own needs in elegant ways.
As far as the languages I use to use I guess I was not very clear. Once you know how to program the language is not important. Good coding practices apply to ALL languages. If you understand an how to loop and branch and WHY to do it then the rest is just the syntax.
At least the Arduino IDE is similar enough to C that making the leap to just using C is not that big. Certainly less of a learning curve than Basic or some of the old database report languages.
Whining about some one using an Arduino in a project is like whining that some one used LEDs and resistors. They are just a component and in this case a tool.
OK seriously if you dont know this do youself a favor- step on you arduino and crush it to bites , now go to bookstore and really begin this time
@yetihehe if you didn’t use typo 3 you’d have it done in a day instead of a week :P
@learn to spell before you trash other people? :)
To be honest this isn’t a hack, far from it, it’s also debatable how usable it really is. But at least it raises awareness of a certain function – i guess that’s worth something.
what is it with the arduino that seperates the masses? its simple to use because it hides the complexity you actually dont need. if one day you thinkyou could need more complexity or features, no problem, they are there!
I really really cant understand all this elitist crap anymore.
@tjb
>As far as the languages I use
>to use I guess I was not very clear.
Well, on an MCU you will be using either C and some assembly (Start up code, platform specific stuff that isn’t covered by C and/or you don’t have toolchain vendor supplied macros for) or assembly.. It’s all very well chaining together “almost C with a massive library of prewritten code” but what happens when you actually need to know what your micro is doing? If you know how the status register(s), interrupt system, SFR’s etc work on one platform you can apply it to another.. but if that has been totally hidden from you and you can do stuff like i2c or SPI with a single call to some supplied code I would argue that you haven’t learned an awful lot. In this case if you had read the datasheet to work out how to use the AVR’s ADC you would have bumped into how to use it’s reference voltage pin..
If you’re knocking up some blinky LEDs and consider yourself more of an artist that’s fine but trying to sell Arduino as the greatest thing since sliced bread for embedded development is just meh.
>If you understand an how to loop and branch
>and WHY to do it then the rest
>is just the syntax.
Ok, let’s throw this into the mix.. if your platform has a DMA controller does doing a simple copy byte from src to dst n times turn into a DMA transfer? Even simpler.. if you do multiple linear byte transfers does the compiler turn that into transfers of the best size for your platform?
In normal high level programming with an OS you basically don’t have to give a shit but in the low level bare metal world these things are important.
>At least the Arduino IDE is similar enough to C
IDE != Programming language though. You are comparing two different things.
Does the Arduino IDE support debugging beyond printing out of the serial port yet? Does it have GDB integration or anything useful like that?
>that making the leap to just using C
Jumping from hand-held C (Arduino) to hand-held C (Toolchain with support headers, macros etc) isn’t that big of a jump maybe. Depends on what you get doesn’t it? C is a very sparse language and most of it’s functionality comes from your libraries (The most important of which being your standard c library). With the AVR you have libc-avr which has lots of juicy goodness (it’s what the Arduino stuff is based on after all). Getting C running on a baremetal platform without pre-supplied startup code, linker scripts etc is a massive pain in the ass.
>than Basic
Any basic is going to be hand-held though… the very fact that basic is running on your chip or you have a compiler that will spit out working machine code from basic source for you shows that someone else has been there and done the hard work(tm) for you. Even assembly can be simplified to the point where anyone can do it.. DOS is a great platform to do X86 assembly because you can use int 21h. ;)
>Whining about some one using an Arduino
When people “whine about the arduino” it’s usually that it was unnecessary (i.e. a 555 could have been used instead) or that the problem solved was trivial and doesn’t really deserve to be a “hack” or any back patting.. and then come the “I use Arduino! it is the bestest thing in the world! All you haters don’t know how good it is!”. I guess what happens is getting a blinky LED working so quickly goes to peoples heads.
@cantido
I think part of the problem here is you Assume that any one who used Arduino does not know any thing about the underlying hardware. And I will agree there are a large number who don’t. Some don’t know the difference between the micro-controller and a shift register. Those are the ones who use an Arduino where a 555 (or even just a couple of transistors and other components would work.)
After a while they get board and go away or they learn more. At some point they out grow the Arduino IDE and simple C and need to do more. Some times they just have to figure out how to address a pin directly. The Arduino IDE and language does allow for this. The hardware is NOT as hidden as much as you seam to imply. It is there if you decide to look.
Then you have the group who really DO know what is going on under the hood. They are the ones writing the libraries and getting more stuff to work with it.
To me it is just a tool. One tool in a very large array of tools. I use it where it works for me. I also look at data sheets.
Wow, what a waste of a thread, is this about information,or a place to crow?
some of us haven’t done a project since the 8085 and it’s single voltage and bi directional bus made it easier to wire wrap a home PC.
We remember when direct modems were illegal, but we built them anyway..
Some of us are rusty, we enjoy the Arduino because it’s easy and far less expensive, than most of what we’ve seen.
I used to have most of the pin outs memorized in families of chips.. not anymore..
Call me a Moron if you like, but in my travels, it’s the man that knows everthing you want to steer clear of :-)