Tag Archives: USB

Designing a USB power meter stick with ATmega328


This USB stick measures supply voltage, calculates power consumption and displays it on an OLED display.


There was a time when USB drives were only for transferring data. Not anymore. The interface is increasingly being used as a power supply and charging port for an assortment of gizmos and gadgets. Take this DIY USB line power meter stick from Electro-Labs, for example. The meter is capable of measuring the supply voltage of the devices connected to the USB port or charger, calculating its power consumption, and then displaying the reading on an integrated 0.5″ OLED screen.

DIY-USB-Line-Power-Meter-Stick-Connected-to-Laptop-620x503

The board itself is built around an ATmega328. In order to keep the circuit as small as possible and reduce the number of components, the MCU runs off its internal 8MHz clock. Meanwhile, the voltage and current are measured by its built-in 10-bit ADC.

To enhance the accuracy of the measurements, an external 2.5V voltage reference IC is included as well. The current is converted to voltage on a 0.01R sense resistor and precisely amplified by an LT6106 high side current sense amplifier before being sent to the AVR’s 10-bit analog port. The stick is capable of measuring up to 2.5A. Since the OLED display requires 3.3V supply voltage, a linear voltage regulator handles the 5V to 3.3V conversion.

DIY-USB-Line-Power-Meter-Stick-Bottom-620x505

“An external 2.5V voltage reference is used to get more accurate ADC readings. Since the ADC module of ATmega328 is 10-bit, the reading resolution is 2.44mV (2.5V/1024). It is quite enough for the purpose of the circuit,” Electro-Labs writes. “The 5V line of the USB port is passed through a voltage divider network including 14K and 10K resistors to extend the readable voltage up to 6V.”

The tiny OLED communicates via an SPI interface and is driven by the U8Glib library. An Arduino sketch reads the separate ADC inputs for the voltage and current, and reveals the measurements on the display. 10 samples from each channel are averaged to filter out the noise.

“After a simple V*I power calculation, it shows up the values on the display by using the U8Glib library. The measurement is repeated every one second. The software runs in an endless loop,” the Electro-Labs crew adds.

DIY-USB-Line-Power-Meter-Stick-Chargin-Cellphone-620x501

Intrigued? You can find a breakdown of entire project, including bill of materials and its necessary code, on its original page here.

Capacitive sensing with ancient keyboards



The Model M keyboard is a designation for a group of computer keyboards manufactured by IBM, Lexmark, Unicomp and MaxiSwitch, starting in 1984.

According to Wikipedia, the many variations of the keyboard have their own distinct characteristics, with the vast majority boasting a buckling spring key design and many having fully swappable keycaps.

As the venerable M keyboards are understandably ancient, there really is no easy method of connecting the device to a modern system. This unfortunate fact prompted a modder by the name of xwhatsit to ultimately build his own controller.

According to Hackaday’s Brian Benchoff, the beam spring keyboards use capacitive switches.

“With 122 keys, the usual method of reading capacitance – putting a capacitor in an oscillator – would be far too slow to be of any use in a keyboard. There is another method of reading capacitance: measuring the current going through the capacitive switch. This can easily be accomplished with an LM339 comparator,” he explained.

“xwhatsit‘s keyboard controller uses this capacitive sensing circuit to read the four rows of keys, with a few shift registers taking care of the columns. Atmel’s ATMega32u2 MCU is the brains of the outfit, running LUFA to translate the key presses to USB.”

Interested in learning more? Well, you’re in luck, because xwhatsit is selling Atmel based controllers for the Model M as well as the Model F using the same basic circuit.

ATmega32u4 MCU powers littleBits Arduino module



LittleBits has debuted a programmable ATmega32u4-powered Arduino at Heart Module. The new component will allow Makers to easily incorporate sketches into their littleBits circuits.

According to a LittleBits rep, the Arduino Module is capable of reading two types of input signals.

“The first is digital, which is a simple ‘on’ or ‘off’ signal. This is the type of signal you will get from a button or trigger. In the Arduino coding language, on is a HIGH signal and off is a LOW signal. All three inputs on the Arduino Module can read digital signals,” the rep explained.

“The other type of signal is an analog signal. Analog signals aren’t just ‘on’ or ‘off.’ They work like a dimmer switch or a volume knob. In the Arduino coding language, analog signals are given a value between 0 and 1023. If you connected a dimmer module to your Arduino and turn the knob up (clockwise), the value would slowly rise from 0 to 1023. The inputs on the Arduino module marked a0 and a1 both accept analog signals.”

As Engadget’s Jon Fingas notes, the programmable module gives Makers much more control over LittleBits’ existing modules, such as the oscillators in the Synth Kit.

“However, it also opens the door to interaction with your computer. Since the Arduino module has USB support built-in, you can create Etch-A-Sketches, Pong games and other programs that have LittleBits and your PC working in harmony,” said Fingas.

“[Plus], many existing Arduino projects should work with only a few slight tweaks to pin assignments.”

The stand-alone Arduino module can be snapped up for $36, although LittleBits is currently offering an $89 starter bundle that includes a total of 8 prototyping modules.

Interested in learning more? You can find additional information about the new LittleBits module here.

Adafruit’s Gemma has Atmel under the hood

Adafruit has debuted Gemma, a tiny wearable platform board packed in a 1″ diameter package. The device – powered by Atmel’s versatile Attiny85 – is easily programmable with an Arduino IDE over USB.

“We wanted to design a microcontroller board that was small enough to fit into any project, and low cost enough to use without hesitation,” Adafruit’s Limor Fried (aka LadyAda) explained in a recent blog post. “Gemma is perfect for when you don’t want to give up your Flora and aren’t willing to take apart the project you worked so hard to design. It’s our lowest-cost sewable controller!”

Fried described the Attiny85 as a “fun processor” because despite being so small, the device boasts 8K of flash and 5 I/O pins, including analog inputs and PWM ‘analog’ outputs.

“We designed a USB bootloader so you can plug it into any computer and reprogram it over a USB port just like an Arduino (it uses 2 of the 5 I/O pins, leaving you with 3),” Fried continued. “In fact we even made some simple modifications to the Arduino IDE so that it works like a mini-Flora. Perfect for small and simple projects – the Gemma will be your go-to wearable electronics platform.”

In addition to Atmel’s ATtiny85, key hardware specs include:

  • 1.1″ / 28mm diameter and 0.28″ / 7mm thick.
  • Easy-to-sew or solder pads for embedding in wearable projects.
  • 8K of flash, 512 byte of SRAM, 512 bytes of EEPROM.
  • Internal oscillator runs at 8MHz.
  • Ultra low power, only 9 mA while running.
  • USB bootloader with LED indicator programmable with the Arduino IDE
  • Mini-USB jack for power and/or USB uploading
  • Rugged and foolproof bootloader process
  • ~5.25K bytes available for use (2.75K taken for the bootloader)
  • On-board 3.3V or 5.0V power regulator with 150mA output capability and ultra-low dropout.
  • Up to 16V input, reverse-polarity protection, thermal and current-limit protection.
  • Power with either USB or external output (such as a battery) – it’ll automatically switch over
  • On-board green power LED and red pin #1 LED; reset button for entering the bootloader or restarting the program.
  • 3 GPIO – The 3 independent IO pins have 1 analog input and 2 PWM output as well.
  • Hardware I2C capability for breakout and sensor interfacing.

Interested in learning more about Adafruit’s Gemma? You can check out LadyAda’s detailed Gemma tutorial here.

A closer look at Atmel’s XMEGA-B1 Xplained

Atmel’s ATxmega128B1 is a low power, high performance 8/16-bit AVR microcontroller. The MCU boasts 128KB self-programming flash program memory, 8KB boot code section, 8KB SRAM, 2048-byte EEPROM, 2-channel DMA controller, 4-channel event system, USB (full speed), 4×40 segment LCD controller and up to 32 MIPS throughput at 32MHz.

xmegab1xplainedfull

The versatile device can be used to power a wide range of applications, including utility metering, home automation, climate control, industrial control, sports equipment, toys, eToken, medical, power tools and fire alarm systems.

To accelerate development with the ATxmega128B1, Atmel offers the XMEGA-B1 Xplained, a hardware-based platform that allows engineers to more easily evaluate the device.

Aside from the ATxmega128B1 microcontroller (MCU), key XMEGA-B1 Xplained specs include:

  • 4×40 transflective LCD module with backlight
  • Transfer data over the USB full/low speed device interface
  • Read a light sensor with the ADC
  • Read a temperature sensor with the ADC
  • Measure external voltage input with ADC
  • Measure potentiometer voltage with ADC
  • Read status of the 4 Atmel QTouch buttons from AT42QT1040 QTouch device
  • 4 LEDs to show status information
  • Read/write data to the 64Mbit Atmel DataFlash
  • Program the kit via USB bootloader or an Atmel programmer
  • Expand the board with Xplained top modules

The XMEGA-B1 Xplained can be ordered from Atmel’s official store here.

Designing in-home display units with Atmel tech

In-home display (IHD) units play a critical role in helping customers reduce their energy usage by providing relevant stats in real-time. Indeed, IHD units are typically designed to acquire and display information via a sensor with built-in RF and/or PLC. A more effective method? Transmitting information from a smart meter using a home area network.

“IHD units vary in complexity, from simple wall-mounted segment LCD displays, up to battery-operated products with color TFT displays and touchscreens,” an Atmel engineering rep told Bits & Pieces. “Advanced IHDs can display not only consumption information, but energy consumption advice from energy providers. They can also support a variety of additional functions such as home automation.”

To be sure, IHD units typically support displays, connectivity via USB and RF, as well as low power and touch buttons or screens for a fully interactive user interface (UI). And that is why Atmel offers a wide range of versatile microcontrollers (MCUs) for IHDs, from entry-level 8-bit AVRs to a sophisticated ARM9 core with embedded LCD graphics display controllers.

“In short, Atmel’s MCUs help facilitate flexible touch solutions, from buttons and wheels to sophisticated touch-screens, all providing support for a wide range of user interface features and capabilities,” the Atmel engineering rep explained.

“Meanwhile, power line communications (PLC) system-on-a-chip (SoC) solutions with full digital implementation deliver best-in-class sensitivity, high performance and high temperature stability. Plus, our CryptoAuthentication lineup provide a cost-effective, easy-to-implement security solution that is critical for wireless communication between meters and  IHD units.”

In terms of power efficiency, Atmel offers a number of advanced capabilities, including 1 µA watchdog and brown-out, picoPower tech for extended battery life, an event system to allow measurement while CPU is in SLEEP mode, support for true 1.6V operation, low-power RF transceivers for connectivity and the lowest power 32 kHz crystal oscillator (650nA RTC).

“In-house display units can range from a basic segment LCD to a more sophisticated color TFT. Depending on the display choice drivers and required  processing power, the primary microcontroller can be either an entry-level 8- or 32-bit MCU, scaling up to a more powerful embedded MPU with on-chip TFT LCD controller,” the engineering rep added.

“As products become more sophisticated, so will the UI. Atmel touch technology provides robust support for state of the art features such as capacitive touch buttons or a full touchscreen. The communications within the IHD depend on the implemented architecture of the HAN (typically RF or PLC). Of course, wireless connectivity can also be supported via Secure Digital Input Output (SDIO) cards.”

Interested in learning more about designing in-home display units with Atmel tech? Be sure to check out our extensive device breakdown here.

Capacity and performance characterize Atmel’s megaAVR

Our ongoing coverage of Atmel’s comprehensive AVR portfolio has taken readers on a detailed MCU (microcontroller) tour this month. First, Bits & Pieces dove into the guts of Atmel’s AVR UC3 which is built around high-performance 32-bit AVR architecture and optimized for highly integrated applications.

We then spent some time with Atmel’s AVR XMEGA, an MCU designed for real-time performance, high integration and ultra-low power. And today we want to properly acquaint our readers with Atmel’s megaAVR microcontroller, which is well known for both capacity and performance.

“When your designs need some extra muscle, you need the megaAVR. Ideal for applications requiring large amounts of code, the megaAVR offers substantial program and data memories with performance up to 20 MIPS, with picoPower technology minimizing power consumption,” an Atmel engineering rep told Bits & Pieces. “All megaAVRs offer self-programmability for fast, secure, cost-effective in-circuit upgrades. You can even upgrade the flash while running your application.”

Indeed, the megaAVR family offers Atmel’s widest selection of devices in terms of memories, pin counts and peripherals. Meaning, engineers can choose from general-purpose devices to models with specialized peripherals like USB, or LCD controllers, or CAN, LIN and Power Stage Controllers.

More specifically, Atmel’s megaAVR family is equipped with on-chip flash, SRAM, internal EEPROM, SPI, TWI, USART, USB, CAN, LIN, watchdog timer, a choice of internal or external precision oscillator and general purpose I/O pins.

In terms of analog functions, the megaAVR boasts advanced analog capabilities, such as ADC, DAC, built-in temperature sensor and internal voltage reference, brown out detector, a fast analog comparator and a programmable analog gain amplifier. Simply put, the high level of integration allows designs with fewer external analog components.

And last, but certainly not least, megaAVR microcontrollers help accelerate the development process with advanced in-system programming and on-chip debug, while in-system programming works to simplify production line programming and field upgrades.

Interested in learning more? A full breakdown of our AVR portfolio is available here.