Posts | Comments

Planet Arduino

Archive for the ‘ADC’ Category

[Trent M. Wyatt]’s CPUVolt library provides a fast way to measure voltage using no external components, and no I/O pin. It only applies to certain microcontrollers, but he provides example Arduino code showing how handy this can be for battery-powered projects.

The usual way to measure VCC is simple, but has shortcomings.

The classical way to measure a system’s voltage is to connect one of your MCU’s ADC pins to a voltage divider made from a couple resistors. A simple calculation yields a reading of the system’s voltage, but this approach has two disadvantages: one is that it constantly consumes power, and the other is that it ties up a pin that you might want to use for something else.

There are ways to mitigate these issues, but it would be best to avoid them entirely. Microchip application note 2447 describes a method of doing exactly that, and that’s precisely what [Trent]’s Arduino library implements.

What happens in this method is one selects Vbg (a fixed internal voltage reference that is temperature-independent) as Vin, and selects Vcc as the ADC’s voltage reference. This is essentially backwards from how the ADC is normally used, but it requires no external hookup and is only a bit of calculation away from determining Vcc in millivolts. There is some non-linearity in the results, but for the purposes of measuring battery power in a system or deciding when to send a “low battery” signal, it’s an attractive solution.

Being an Arduino library, CPUVolt makes this idea very easy to use, but the concept and method is actually something we have seen before. If you’re interested in the low-level details, then check out our earlier coverage which goes into some detail on exactly what is going on, using an ATtiny84.

Necessity might be the mother of all invention, but we often find that inventions around here are just as often driven by expensive off-the-shelf parts and a lack of willingness to spend top dollar for them. More often than not, we find people building their own tools or parts as if these high prices are a challenge instead of simply shrugging and ordering them from a supplier. The latest in those accepting the challenge of building their own parts is [Advanced Tinkering] who needed a specialty pressure gauge for a vacuum chamber.

In this specific case, the sensor itself is not too highly priced but the controller for it was the deal-breaker, so with a trusty Arduino in hand a custom gauge was fashioned once the sensor was acquired. This one uses an external analog-to-digital converter to interface with the sensor with 16-bit resolution, along with some circuitry to bring the ~8 V output of the sensor down to the 5 V required by the microcontroller. [Advanced Tinkering] wanted a custom live readout as well, so a 3D printed enclosure was built that includes both an LCD readout of the pressure and a screen with a graph of the pressure over time.

For anyone else making sensitive pressure measurements in a vacuum chamber, [Advanced Tinkering] made the project code available on a GitHub page. It’s a great solution to an otherwise overpriced part provided you have the time to build something custom. If you’re looking for something a little less delicate, though, take a look at this no-battery pressure sensor meant to ride along on a bicycle wheel.

Over the summer [ElectroSmash] put the finishing touches on the Arduino Audio Meter, a shield for the Arduino Uno that visualizes various aspects of an incoming audio signal on a set of four 8×8 LED dot matrices. Obsentisibly it’s for use on a guitar pedalboard, but thanks to the incredible documentation and collection of example code provided by the team, the project promises to be an excellent platform for all sorts of audio experimentation.

Incoming audio is amplified with an MCP6002 and fed into the Uno’s Analog to Digital Converter, where it’s processed via whatever Sketch the user has uploaded. User input is provided by a digital encoder with push-button. A set of four MAX7219 chips control the entire 256-pixel matrix with just three pins on the Arduino. The resolution of the display allows the Arduino Audio Meter to show more than just a simple VU meter, it can even do text and basic graphics.

[ElectroSmash] provides various Sketches for use with the Arduino Audio Meter that provide the expected repertoire of audio visualizations, but they also provide a number of interesting Sketches to expand the capabilities of the device in unexpected ways. Some of them could be useful for a stage musician, such a tool to tune your guitar, whereas others are fun uses of the hardware such as a game of “Snake”.

With the entire project released as open source, users are free to run wild with the Arduino Audio Meter. Writing your own custom software is an obvious first step to making the project your own, but adding additional hardware features and functions certainly aren’t out of the question either.

Our very own [Lewin Day] once walked us through the effort involved in building boutique guitar pedals, and while the Audio Audio Meter’s capabilities are somewhat limited as it doesn’t have the ability to change the audio going through it, we’re still interested in seeing what the community will come up with once they have an easy way to bring their ideas to life.

One of the great things about the Arduino environment is that it covers a wide variety of hardware with a common interface. Importantly, this isn’t just about language, but also about abstracting away the gory details of the underlying silicon. The problem is, of course, that someone has to decode often cryptic datasheets to write that interface layer in the first place. In a recent blog post on omzlo.com, [Alain] explains how they found a bug in the Arduino SAMD21 analogRead() code which causes the output to be offset by between 25 mV and 57 mV. For a 12-bit ADC operating with a reference of 3.3 V, this represents a whopping error of up to 70 least-significant-bits!

Excerpt from the SAMD wiring_analog.c file in the Arduino Core repo.

While developing a shield that interfaces to 24 V systems, the development team noticed that the ADC readings on a SAMD21-based board were off by a consistent 35 mV; expanding their tests to a number of different analog pins and SAMD21 boards, they saw offsets between 25 mV and 57 mV. It seems like this offset was a known issue; Arduino actually provides code to calibrate the ADC on SAMD boards, which will “fix” the problem with software gain and offset factors, although this can reduce the range of the ADC slightly. Still, having to correct for this level of error on a microcontroller ADC in 2019 — or even 2015 when the code was written — seems really wrong.

After writing their own ADC read routine that produced errors of only between 1 mV and 5 mV (1 to 6 LSB), the team turned their attention to the Arduino code. That code disables the ADC between measurements, and when it is re-enabled for each measurement, the first result needs to be discarded. It turns out that the Arduino code doesn’t wait for the first, garbage, result to finish before starting the next one. That is enough to cause the observed offset issue.

It seems odd to us that such a bug would go unnoticed for so long, but we’ve all seen stranger things happen. There are instructions on the blog page on how to quickly test this bug. We didn’t have a SAMD21-based Arduino available for testing before press time, but if you’ve got one handy and can replicate these experiments to verify the results, definitely let us know in the comments section below.

If you don’t have an Arduino board with a SAMD21 uC, you can find out more about them here.

We’d seen it done with buttons, switches, gestures, capacitive touch, and IR remote, but never like this. [electron_plumber] made an LED that can be blown out like a candle, and amazingly it requires no added sensors. The project uses an Arduino to demonstrate turning a tiny LED on and off in response to being blown on, and the only components are the LED and a resistor.

[electron_plumber] used an 0402 LED and thin wires to maximize the temperature responses.
How is this done? [electron_plumber] uses an interesting property of diodes (which are the “D” in LED) to use the LED itself as a temperature sensor. A diode’s voltage drop depends on two things: the current that is being driven through the diode, and the temperature. If the current is held constant, then the forward voltage drop changes reliably in response to temperature. Turning the LED on warms it up and blowing on it cools it off, causing measurable changes in the voltage drop across the device. The change isn’t much — only a handful of millivolts — but the effect is consistent and can be measured. This is a principle [Elliot Williams] recently covered in depth: using diodes as temperature sensors.

It’s a clever demo with a two important details to make it work. The first is the LED itself; [electron_plumber] uses a tiny 0402 LED that is mounted on two wires in order to maximize the temperature change caused by blowing on it. The second is the method for detecting changes of only a few millivolts more reliably. By oversampling the Arduino’s ADC, an effectively higher resolution is obtained without adding any hardware or altering the voltage reference. Instead of reading the ADC once, the code reads the ADC 256 times and sums the readings. By working with the larger number, cumulative changes that would not register reliably on a single read can be captured and acted upon. More details are available from [electron_plumber]’s GitHub repository for LEDs as Sensors.

Embedded below is a video that is as wonderful as it is brief. It demonstrates the project in action, takes a “show, don’t tell” approach, and is no longer than it needs to be.

In the past we have seen LEDs that can be blown out like candles in different ways; one used a microphone to detect blowing while another used a thermistor to detect the temperature change from blowing. [electron_plumber]’s project is notable not only for using no added parts, but also for being documented in a way that just about anyone can get up and running, and that’s something we always like to see.

We’re all familiar with the wide variety of Arduino development boards available these days, and we see project after project wired up on a Nano or an Uno. Not that there’s anything wrong with that, of course, but there comes a point where some hobbyists want to move beyond plugging wires into header sockets and build the microcontroller right into their project. That’s when one generally learns that development boards do a lot more than break the microcontroller lines out to headers, and that rolling your own design means including all that supporting circuitry.

To make that transition easier, [Sean Hodgins] has come up with a simple Arduino-compatible module that can be soldered right to a PCB. Dubbed the “HCC Mod” for the plated half-circle castellations that allows for easy soldering, the module is based on the Atmel SAMD21 microcontroller. With 16 GPIO lines, six ADCs, an onboard 3.3 V regulator, and a reset button, the module has everything needed to get started — just design a PCB with the right pad layout, solder it on, and surround it with your circuitry. Programming is done in the familiar Arduino IDE so you can get up and running quickly. [Sean] has a Kickstarter going for the modules, but he’s also releasing it as open source so you’re free to solder up your own like he does in the video below.

It’s certainly not the first dev module that can be directly soldered to a PCB, but we like the design and can see how it would simplify designs. [Sean] as shown us a lot of builds before, like this army of neural net robots, so he’ll no doubt put these modules to good use.

Analog-to-digital converters, or ADCs, are somewhat monolithic devices for most users, a black box that you ask nicely for the value on its input, and receive a number in return. For most readers, they will be built into whatever microcontroller is their platform of choice, and their resolution will be immutable, set by whatever circuitry is included upon the die. There are a few tricks that can be employed to get a bit more from a stock ADC though, and [Neris] has taken a look at a couple of them.

The first circuit doubles the resolution of an ADC, in this case, that of the Atmel chip in an Arduino, by converting its output from an integer to a signed integer. It performs this task with a precision rectifier, rectifying around a zero-crossing point half-way through the range of the analog value to be read and supplying a sign bit to the Arduino. The Arduino measures the rectified analog value to an integer, and applies the appropriate sign from the supplied bit value.

The second circuit takes a variation on the same technique but with two ADCs instead of one. A pair of PIC chips are used with their voltage references stacked one above the other, by taking both readings in combination a result with double the resolution can be derived.

You might ask why bother with these techniques. After all, there are plenty of higher-resolution ADCs on the market. But they’re useful techniques to know, should you ever need to extract the proverbial quart from a pint pot.

If ADCs are a mystery to you, you’re in luck. [Bil Herd] gave us a comprehensive introduction to the subject.

Connor Nishijima has come with a unique way to detect motion using an Arduino Uno. The active media developer is polling an ADC pin with a pair of wires twisted tightly together — one plugged into A3, another plugged into ground — and generating readings whenever a large living object (like his two cats) is nearby.

“The closest I have ever come to explaining this is capacitive coupling. So what it is is the antenna is leaching a little bit of electricity off you, and you are leaching a little bit of electricity from the antenna. The differential that happens when you move around is what the Arduino is picking up.”

He’s calling this effect “Capacitive Turbulence,” and so far he’s only got it work on the Arduino, no luck using other boards with ADCs. You can watch him explain this magical phenomenon in more detail below!

Mag
05

Playing with analog-to-digital converter on Arduino Due

ADC, arduino, arduino uno, ATmega328, ATSAM3X8E, duemilanove, microcontrollers Commenti disabilitati su Playing with analog-to-digital converter on Arduino Due 

adc_freerunning1-600x361

Piotr wrote a post on his blog about using some of advanced capabilities of ADC in Arduino Due:

Today I’m going to present some of more advanced capabilities of ADC built in ATSAM3X8E – the heart of Arduino Due.
I like the Arduino platform. It makes using complex microcontrollers much simpler and faster. Lets take for example the analog-to-digital converter. To configure it even on Atmega328 (Arduino Uno/Duemilanove) you must understand and set correct values in 4 registers. And it can be much more in complex device, like 14 in ATSAM3X8E (Arduino Due)!

Playing with analog-to-digital converter on Arduino Due – [Link]

Feb
06

Piconomic FW Library 0.4.2 released

ADC, arduino, arduino uno, ATmega328P, atmel, AVR, GPIO, i2c, Piconomic, SPI Commenti disabilitati su Piconomic FW Library 0.4.2 released 

tera_term_cli

by Pieter @ piconomic.co.za:

If you can beg, steal or borrow an Atmel ISP programmer, then you can use the Arduino environment to develop on the Atmel AVR Atmega328P Scorpion Board. An Arduino on Scorpion Board guide, Optiboot bootloader and example sketches have been added.

If you own an Arduino Uno board, you can now try out the Piconomic FW Library risk free without abandoning the creature comforts of the Arduino environment. You can use the existing Optiboot bootloader to upload code. I have added a getting started guide for the Arduino Uno. There are examples, including a CLI (Command Line Interpreter) Application that creates a “Linux Shell”-like environment running on the Arduino Uno so that you can experiment with GPIO, ADC, I2C and SPI using only Terminal software (for example Tera Term)… it is really cool!

Piconomic FW Library 0.4.2 released - [Link]



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook