Tag Archives: AVR microcontroller

Cross-board and cross-vendor embedded development with PlatformIO

Ivan Kravets, PhD, Researcher and Software Architect, explains how PlatformIO is a cross-platform code builder and the missing library manager.

We live in a time where the wall between the hobbyist and microcontroller (MCU) world has been completely broken. Just a few years ago, no one could have imagined that MCUs would go on to become popular with people who are not familiar with electronics. Nowadays, you don’t need to have deep knowledge in PCB design, assembly language or become buried under MCU application notes to get your first experience with embedded world.

Moreover, vendors have realized that there is a need to decrease entrance threshold and to propose alternatives to existing professional development kits. It was at this point when popular prototype boards (like the Atmel based Arduino) were conceived. Comfortable board form-factor, rich peripheral and huge community of enthusiasts gave rise to a new trend, which can be called “Embedded Boards for Everybody.”

Still, there is a problem related to programming instruments. It’s excellent that MCU vendors have spent quite a bit of efforts to create rich HDKs/SDKs and comfortable IDEs which allow the performing of hardware debugging and tracing. However, all of these features are of interest mostly for those who have already decided which specific MCU they will use for the project. So, at this point the market has generated another demand: to make cross-MCU development easy. This is where Arduino and its burgeoning community have played an important part: cross-platform processing-based Arduino IDE; simple and easy-to-use wiring-based framework with high-level API; incredible count of shields (sensors, actuators, etc.), and a lot of different libraries which cover significant part of hobbyist tasks. These have all made embedded development much easier. Yet, while Arduino enables development for varying MCUs, it is still a commercial product. As a result, it is inherently restricted to Arduino boards.

Saving time for the task in hand

It doesn’t come as a big surprise today when an interesting embedded project is invented by people who have not had any earlier professional experience with MCUs. I feel that this phenomenon can easily be explained with my motto: “Creativity comes from talent and never from knowledge.” Talented people and those with ideas are interested in quick prototype instruments which don’t require big efforts to use them. Many of these people prefer to concentrate on the task in hand, and don’t want to install too much of additional software, play with confused manual or get used to new additional IDE… So far so good, as many of vendor IDEs do address these issues.

However, what if for your next project, you need some board or MCU which aren’t supported by your favorite vendor? With devices becoming increasingly smaller, wireless and battery-powered, this is occurring more frequently. Then, all of a sudden, you have a problem: development platforms from the different vendors tend to recommend their own IDEs and approaches. Subsequently, you’re likely to have several IDEs installed, each with its own requirements (to make things worse, these requirements sometimes conflict with each other), and with an ongoing switching back and forth. Ouch! It’s not before long that this quickly becomes a major headache, and ironically, headache is exactly what these development platforms aim to avoid.

Developer, meet PlatformIO. PlatformIO, meet developer.

Here is where PlatformIO comes in, an open-source cross-platform code builder and library manager (available on GitHub). After many months of development, we have finally released PlatformIO 1.0 which has been recommended for production use.

I admit that, as one of the authors behind PlatformIO, I cannot be 100% objective when speaking about it, but I’ll try.

PlatformIO allows users to:

  • Decide which operation system they want to run development process on (You can even use one OS at home and another at work.)
  • Choose which editor to use for writing the code (It can be pretty simple editor or powerful favorite IDE.)
  • Focus on the code development, significantly simplifying support for the different development platforms, boards and MCUs.

Cross-platform code builder


PlatformIO is independent from the platform, in which it is running. In fact, the only requirement is Python, which exists pretty much everywhere. What this means is that PlatformIO projects can be easily moved from one computer to another, as well as that PlatformIO allows for the easy sharing of projects between team members, regardless of operating system they prefer to work with. Beyond that, PlatformIO can be run not only on commonly used desktops/laptops but also on the servers without X Window System. While PlatformIO itself is a console application, it can be used in combination with one’s favorite IDE or text editor such as Arduino IDE, Eclipse, Visual Studio, Vim or Sublime Text.

Alright, so PlatformIO can run on different operating systems. But more importantly, from development perspective at least, is a list of supported boards and MCUs. To keep things short: PlatformIO supports over 100 embedded boards (all boards which are supported by Arduino IDE) and all major development platforms including Atmel AVR and Atmel | SMART, among many others.

How it works

Without going too deep into PlatformIO implementation details, work cycle of the project developed using PlatformIO is as follows:

  • Users choose board(s) interested in project configuration file – “platformio.ini.”
  • Based on this list of boards, PlatformIO downloads required toolchains and installs them automatically.
  • Users develop code and PlatformIO makes sure that it is compiled, prepared and uploaded to all the boards of interest.

Cross-board code and continuous integration

As aforementioned, PlatformIO supports cross-board code development: multiple boards can be selected in a single project, and PlatformIO will apply all respective environments and will compile the code against each of boards within the project. And for the icing on the cake, this feature can be easily integrated with Continuous Integration System (such Jenkins, Travis CI and Circle CI). It should help to ensure that, at any point, a code at least compiles on all target boards, thereby eliminating costly, time-consuming and error-prone process of fixing these cross-platform issues at later stages, when your team members have already forgotten what the code was about.

The missing library manager


With an overall trend heading towards open-source, embedded development is no exception. Indeed, there are countless embedded libraries already available today, such as high-level communication with sensors, actuators or even full-fledged IoT implementations. Nevertheless, every time you need something like it, there is a big underlying question around where to finding this specific library, and how to make it work with your environment.

To address this problem, PlatformIO Library Manager provides an ecosystem for library writers and library users. Using library manifest file (library.json), writers have an ability to describe library. This manifest is not only about such things as authors, description, keywords, and version, but first and foremost about technical information, ranging from location of source code and examples to CVS repository and dependencies. This manifest file is generic enough to be used by other library managers (if somebody else wants to write them).

For the library users (aka developers), PlatformIO provides two ways for searching for libraries. The first way is via Command Line Interface, the other is Web 2.0 Library Search with functionality such as library categories, different framework and platform filters, and advanced search syntax with boolean operations.

PlatformIO Library Manager can be integrated into the most popular IDEs and is capable of extending their functionality, including all-important automated updates of installed libraries. For instance, Arduino IDE benefits of using PlatformIO Library Manager are summarized in the following table:



As noted above, as an author, I cannot be objective when speaking about PlatformIO. However, I am sure that for any kind of cross-board and cross-MCU development PlatformIO provides substantial benefits. PlatformIO takes the hassle out of installing all the tool chains you need, and allows you to build your code for many boards with a single command. PlatformIO Library Manager not only helps you to find and install libraries, but has an option to keep them up to date as well.

And as PlatformIO is an open-source project, you shouldn’t care about price or vendor lock-in. So, what are you waiting for? Give it a try (and if you don’t like it, you’ll get back that zero bucks you’ve paid for it, some restrictions apply, batteries not included).

UPDATE: PlatformIO 1.2.0 is now available. To explore the release history, you can head here.

This ‘ICONIC’ coffee table book is powered by AVR

Just in time for the holiday season, Jonathan Zufi’s coffee table book entitled “ICONIC: A Photographic Tribute to Apple Innovation” recounts the past 30 years of Apple design, exploring some of the most visually appealing and significant products ever created by the Cupertino-based company. The book — which features a number of new photos paying special attention to original prototypes — dons an updated look and comes in a few special editions.


Most notably, the Ultimate Edition includes a special white clamshell case along with a custom PCB designed to pulse embedded LEDs like that of a sleeping older generation Apple notebook when moved.

According to its description, “The circuit is powered by the high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller which combines 1KB ISP flash memory, 32B SRAM, 4 general purpose I/O lines, 16 general purpose working registers, a 16-bit timer/counter with two PWM channels, internal and external interrupts, programmable watchdog timer with internal oscillator, an internal calibrated oscillator, and 4 software selectable power saving modes.”


“The board and clamshell were designed to make removal of the board easy for the purpose of enabling and replacing the battery. The battery is a standard watch cell CR2032. Based on our calculations, the LED should pulse approximately 9,000 times during the life of an average CR2032. Since the LED pulses three times on each movement cycle, that means that it unless you plan on picking up the book more than 3000 times, the battery should last a long time. But because it’s so cool, we think that you might actually reach that number — so we made it very easy to swap out the battery.”

An ideal gift for any Apple buff, those interested in learning more or buying the AVR powered book for a loved one can do so here.

Superman freefalls from space

It’s a bird… It’s a plane… It’s Superman! While we may have seen record-breaking freefalls from daredevils Felix Baumgartner and most recently, Alan Eustace, none may compare to the latest project from a group of RS DesignSpark engineers which was brought to our attention during Electronica 2014.


Earlier this summer, Mattel launched an Extreme Toys Travel Campaign that took their action figures to exotic and extreme locations all around the globe. Inspired by the latest attempts of falling from the edge of space, the toy company asked RS if they would be able to replicate these jumps with one of its new Superman action figures.

RS teamed up with Rlab, a peer run community hackspace, card modeller Jude Pullen, and high altitude balloonist Dave Akerman, to send Superman to space and back in a custom-built capsule. After a couple of planning sessions, the team comprised of Makers, hackers and engineers went right to work. In early September, the group then got together for a long weekend at RLab to bring it all together and prepare for launch.


The team attached the specially-designed capsule to a weather balloon filled with hydrogen gas, which transported the toy Superman approximately 24 miles into the sky to the edge of space. Once the optimal altitude was achieved, Superman “jumped” from the capsule, safely falling back down to Earth’s surface. During the flight, mission data, HD video and pictures were captured, while both Superman and the capsule itself were tracked throughout the flight using a low power radio link and GPS.

Prior to launch, the group designed a chassis in RS Components’ DesignSpark mechanical tool to house the electronics, which was then 3D-printed using a SAM3X8E Cortex-M3 powered RepRap Pro Ormerod.

photo 1

The capsule featured a Raspberry Pi to capture mission data, as well as a customized Atmel ATxmega128A4U based tracking unit to locate and retrieve Superman. In total, the team had utilized five trackers located on the heroic Superman and his accompanying capsule. Not only did the trackers send GPS positions in real-time, but took and transmitted snapshots back down to the land-dwellers as well.

photo 2

Additionally, the RS DesignSpark innovators selected radio modules (were on the 433 mhz band) and receivers tuned to the frequencies of the trackers on Superman and his capsule. Once the Mattel toy jumped out using a “low-tech ejection mechanism,” the team hopped into their cars and continued to follow along with its signal.


So did he make it? Yes, indeed! It took the embedded Superman just under an hour (50 minutes) to reach the ground — where it coincidentally landed at the end of Hope Lane. (For those who may not know, Superman’s “S” isn’t a letter, but rather the Kryptonian symbol for hope.)

Perhaps you have an extra action figure (or even a Barbie) lying around and interested in creating your own high-altitude tracker. If so, fly on over to RS DesignSpark’s step-by-step breakdown here.

Tutorial: Building cool projects with MCUs (Part 2)

I’ve always found microcontrollers really cool. After learning how to use MCUs, along with a few other electronics skills – I can’t really think of anything I am NOT able to build.

Okay, maybe not a time machine…

But when it comes to the electronics part of a project, knowing microcontrollers gives you the ability to build A LOT of different things.

Microcontroller circuit

In the previous part of this tutorial, we looked into the basics, and we established that a microcontroller is kind of like a tiny computer. You can connect things like a display, buttons or Wi-Fi, not to mention put programs onto it and run them.

In this segment, we are going to choose the microcontroller to use in our circuit. There are a gazillion options, so we’re going to use a tool to make things easier. But first, we need to figure out our requirements. Choosing a microcontroller becomes much easier once we know what we actually need.

Differences Between Microcontrollers

8-bit, 16-bit and 32-bit

A microcontroller comes in several bit sizes. You can find microcontrollers with 8-, 16- and 32-bit. This size refers to the size of the databus. With a larger databus, you can do more heavy calculations. In the hobbyist world, the 8-bit microcontroller is probably the most common of them all.

Usually, the 8-bit MCUs have fewer pins, and is therefore easier to solder onto a circuit board. In this microcontroller tutorial series, we’ll be keeping it as simple as possible, so we’re going to use an 8-bit.

Memory, Pins and Peripherals

Even an 8-bit microcontroller comes in a lot of different versions. Some have more memory. Some have more input and output pins. Some have USB interface. Some have analog to digital conversion. Some have SPI communication.

These extra functions – like USB or SPI – are called peripherals.

Chip on finger

Finding a Microcontroller for Our Circuit

My goal with this tutorial is to show you how to build a super simple microcontroller circuit.

One thing that affects how simple it is going to be is the programming method. How are we going to get the program we make onto the chip?

Often times, people use an external programmer or debugger that they connect to their microcontroller circuit, but I don’t want you to have to buy an extra tool for this. I want us to be able to just connect the circuit to a USB port on a computer and program it directly.

This leaves us with the following requirements:

  • Can be programmed through USB
  • Few components necessary
  • Possible to solder at home

We can make our circuit programmable through USB in a few different ways. For example, we can do this by adding a USB-to-serial chip onto our circuit – like they do on some of the Arduino boards.

However, since this will increase the number of components, a better solution is to find an MCU with USB interface included. It would also need a bootloader that can accept programming through USB.

Conveniently, some of Atmel’s microcontrollers come pre-loaded with a bootloader called USB DFU Bootloader.

To be able to solder the circuit at home, we want a chip with few pins. The fewer pins a microcontroller has, the easier it is to solder it. So let’s look for a chip with as few pins as possible.

The Microcontroller Selector

With our requirements in place, we can start looking for the perfect microcontroller. The Microcontroller Selector is a very useful tool that Atmel made to help you choose a microcontroller.

Using this tool, we can select what we need from our microcontroller, and it will show us which models that fit our criteria.

Using the Microcontroller Selector

We decided earlier to use an 8-bit MCU, so we select «8-bit AVR» under the «CPU» option.

Also, we want a USB interface. Specifically, we want a USB device interface. So under «USB» we select all the options that include «device».

Since we also want as few pins as possible, we’ll sort the results by number of pins.

Microcontroller Selector Tool

Doing this leaves us with five options that have 32 pins. No microcontroller matching our criteria has fewer than 32 pins., while a few options have more than 32 pins, so we can discard those.

One more criteria we are seeking is if the chip comes preloaded with the DFU bootloader. Unfortunately, we can’t select this criteria in the tool; yet, by looking into the documentation for the DFU bootloader, we can find a list of which microcontrollers are preloaded with this feature.

Here, we can see that one of our options, the ATmega8U2, does not have the bootloader. That leaves us with 4 options:

All of these match our requirements, so let’s just choose the one with the most amount of flash. The more flash we have, the bigger programs we can load onto the chip.

So, we’ll choose the ATmega32U2.

Designing the Circuit

Next, we will be designing the circuit. With the chip selected, I believe this will be pretty straightforward. Not too many components are necessary. Nevertheless, I am writing this as I am doing it – and I’ve never used this chip before – so there is always a chance of some surprises..

Stay tuned for Parts 3-5 in the coming days…

ATmega328 is under the hood of this sweet candy sorting machine

If you’re like most people when it comes to Skittles, chances are you love red and purple, tolerate green and orange, and strongly dislike yellow. Sound familiar? Instead of tediously sifting through bowls full of candy, a Maker by the name of Torsten has created a slick sorting machine that arranges sweets by color. Essentially, the machine separates different colored Skittles (and M&Ms, too) and puts them into their respective individual cups.

According to the project’s official Wiki page, the fully-automated platform is capable of sorting an entire 1.5kg/56oz bag in approximately five minutes. Powered by an ATmega328 microcontroller (Arduino Uno), the candy sorting machine also features an RGB color sensor, IR distance sensor, two servos, plastic frame tubes and a few custom designed 3D-printed parts.

“The processing is structured around pseudo-realtime programming which makes the system responsive and keeps it running smoothly. Each process in the system is designed around the notion of event driven finite-state machine (FSM) execution,” Torsten explained.

“Central in the system is Atmel’s ATmega328 AVR MCU — integrated nicely on an Arduino Uno platform. All the sensors and servo actuators connect to this board. An external 9V power supply keeps the system running. 5V and 3V3 power for the servos and board is supplied by the 5V power supply. The programming mimics a real time system where each of the four processes are state driven, which means only a short instruction performed before the system jumps to the next process.”

The machine is equipped with a pair of GWS servos for loading and sorting the pieces, while a continuous rotation servo with a variable rotation speed loads pieces into predefined slots in the feed wheel. After the pieces are placed in individual slots, a white LED illuminates the piece and an ADJD-S311-CR999 CMOS IC with integrated RGB filters captures three color profiles at different angles.

“For the piece to be successfully identified and pass control, at least two profiles have be within three standard deviation (three-sigma rule) of the pre-calibrated data set for Skittles or M&Ms. A RGB LED next to the feed wheel will illuminate to give a visual indication of the detected color,” Torsten continued. “The feed wheel rotation is governed by a QRE1113 IR distance sensor which detects the slot depth change. This transition is used to change process state and start the color analysis at the right moment.”

When the color has been identified, the piece is dropped from the feed wheel and onto a 360-degree servo with a feeding tube attachment which guides the piece into the right cup. The piece is release from the feeding wheel just before the feeding tube is within range of the cup.

“This [method offers] increased performance as the system does not need to hang around and can move to the next cup straight away. This is done by timing the expected rotational velocity and no feedback is provided by the servo,” Torsten added.

Interested in learning more about the Atmel powered candy sorter? Check out the sweet project’s official Wiki page here. 

Hacking a 30-year-old printer back to life with megaAVR

Many engineers out there likely have an ever-increasing collection of old hardware that they promise to restore or use one day. Sound familiar? After coming across an old Radio Shack TRS-80 TP-10 thermal printer in one of his boxes of old gear, a Maker by the name of Danny Chouinard decided to give this vintage printer a brain transplant.


Back in 1984 the TP-10 was the crème de la crème. “It was relatively low cost at around $100 and was whisper-quiet,” Chouinard notes. As a result, the Maker had elected to keep it around hoping to get it in service one day.

Chouinard wanted to find new paper for the printer, however only had one half of a 30-year-old roll remaining. Cognizant of the fact that he would could go out and purchase thermal paper for fax machines, he soon realized that it would be too wide at 8.5 inches. Fortunately, the Maker was able to get his hands on a neighbor’s saw to trim the paper down to the right size. In fact, the new fax paper actually looked better than the old stuff!


To make this printer useful in the modern day, Chouinard wanted to increase the 32 characters per line limit and speed up the printing process a bit. First, he needed to understand exactly how the old printer worked. As Hackaday points out, if Chouinard was going to replace the CPU, he was going to need to know exactly how it functioned. He started by looking at the PCB to determine the various primary functions of the printer. He needed to know which functions were controlled by which CPU pins. After searching around, the Maker was able to locate an original manual for the machine, which also included the schematic for the circuit.


With that out of the way, the Maker decided to build a logic analyzer out of an Atmel ATmega664 and two static ram SPI chips. With a full investigation of the printer’s inner workings complete, Chouinard set out to finish his logic analyzer. Upon completion he tells, “It can sample 8 signals every 3 micro-seconds, 6 samples every 6, 24 every 10. With only 64KB it can fill its memory in about a fifth of a second, but can be tuned slower at run time.”

After some serious logging and exploration, Chouinard acquired a solid understanding of how the aging thermal printer operated. He knew he could increase the character limit with a full-fledged transplant of the printer’s brain. So, he repurposed another ATmega MCU and got the new firmware to crank out up to 80 characters a line — nearly double its original amount. And just like that, it is alive!

Chouinard has provided an incredibly detailed log of how he brought this printer up to modern speed on his website.

Deadline for Simply AVR Design Contest extended

Back in March, Atmel launched the second stage of its Simply AVR Design Contest, which challenged Makers, designers and engineers to develop clever, ground-breaking microcontroller-based designs using its popular AVR MCUs. After seeing a number of amazing designs come through over the last few months, we have decided to extend the deadline by two weeks — giving Makers inspired from Maker Faire New York and Rome a final chance to submit their 8-bit ideas!


The Simply AVR first prize winner will receive $1,500 in cash, as well as some social media stardom across each of Atmel’s industry-leading channels. Each of the four runner-ups will claim a $500 cash prize, along with some coverage as well. Not too shabby!

So, why AVR? Atmel’s 8-bit microcontrollers offer Makers ease-of-use, low power consumption, and high level of integration all at their fingertips. Based on a single-cycle RISC engine that combines a rich instruction set, the incredibly-popular MCUs deliver close to 1 MIPS per megahertz and are optimized for minimum code size and maximum computing performance. Ideal for a broad range of applications — including industrial control, ZigBee and RF, medical and utility metering, communication gateways, sensor control, white goods and portable battery-powered products — AVR accelerates the time it takes to bring an idea to life.

Looking for some last-minute inspiration? This video from Analog Aficionado Paul Rako may help do the trick.

Whether you’re in the process of completing or still brainstorming your next design, don’t forget to enter your project today! Deadline is October 17, 2014.

ATmega328 controls this hot plate’s temperature in the lab

In a laboratory setting, precision is essential. When heating up liquids, being even a degree off could spell ruin for an experiment. Therefore, Maker BrittLiv developed a DIY programmable heating pad that can run intricate temperature ramps – for only $100!


As a chemical and biological engineering student, BrittLiv was priced out of the market for most laboratory quality heating devices; though, when making her own she did not want to sacrifice quality or functionality. “When you try to develop catalysts for chemical processes, the temperature program and exact temperature control is crucial. You probably do not want to stay in the lab for 16 hours to manually adapt your temperature,” she notes.

With a hot plate and a series of electronic components including a LCD screen, a few solid-state relays, and an Atmel ATmega328 gathered, BrittLiv was ready to assemble her contraption. She began by linking the hot plate and the input device. “It is very advisable to use a ground fault circuit interrupter adapter or a safety socket when working on and with the device,” the Maker advises. The embedded AVR microcontroller monitors the heating process, with temperatures up to 338°F, via an MAX6675 thermocouple interface board.


From there, she programmed her electronics to read temperature scales from an SD card. BrittLiv stressed the importance of scales by saying, “It is not enough to simply hold something at a certain temperature, but the rate at which something is heated and for how long is just as important.”

Once her entire unit was soldered and linked, she placed a heat safe wooden case around the input device and sprayed it with heat-resistant paint.

For a full tutorial on how to build your own programmable heating pad, check out BrittLiv’s original Instructables post here.

ATmega8 powers this pool cleaning robot

Pools are great, especially in these summer months. Cleaning them, however, not so much. A Maker by the name of David Gironi has simplified this process by powering an automated pool cleaner with an Atmel ATmega8-controlled timer.


James Hobson over at Hackaday alerted us to Gironi’s Atmel-powered cleaning unit. After the Maker’s store-bought pool cleaning unit failed, in true DIY fashion he decided to employ some technology to fix the robot on his own. The project is broken down into two parts, the ATmega8-based timer and the underwater cleaning robot.


According to the Maker, the ATMega8-powered timer alternates between a “working” and “pause” periods. As a result, Gironi can run the robot at a predetermined interval of days, for any designated time period, i.e. 30 minutes. The out-of-water timer is responsible for converting 220VAC to low voltage DC for the robot. Apart from the timer, the robot itself features two motors. One of the motors pumps the water through the unit to filter it, the other to maneuver the cleaner under the surface.

To delve deeper in the Maker’s design, head over to his in-depth blog piece here.

Devising a dead-icated Splatterhouse arcade game

Just in time for Halloween, Maker Clay Cowgill has devised a killer, interactive cabinet for the Splatterhouse Namco arcade machine he co-owns.

“I like video games, Halloween, and making ‘stuff,’ so this year I combined all three and created a ‘Dead-icated’ Splatterhouse arcade game,” Cowgill explains.

As the Hackaday crew reports, the Maker kicked off his Splatterhouse cabinet project by salvaging an old Williams Defender and coating the sides with a cocktail of drywall compound, sand and paint to achieve a stone texture.

Cowgill then fashioned some pink insulation foam into a tattered “wooden” frame for use as a monitor bezel, while strips of latex were molded to resemble torn flesh and placed along the boards.

“The control panel is yet another work of art: Clay 3D printed a life-size human femur for the game’s joystick, and converted the buttons to look like eyeballs,” .

The Maker decided to go beyond just the cosmetics and tapped into the game’s CPU with a customized daughterboard that detects a variety of game ‘state’ changes, such as player health, number of lives, game level and credits remaining.


Indeed, the cabinet is equipped with an ATmega165 microcontroller (MCU) which reacts to these various in-game events and can be “software modulated for different effects if necessary” using four PWM outputs. For example, if a player takes heavy damage, red lights flash around the monitor, while inserting a coin or dying in the game causes a different set of LEDs behind the marquee to blink excitedly.

A serial port from the AVR MCU also streams the status of the in-game variables for debugging, Cowgill adds.


Want to learn more? Check out all the details of this Cowgill’s Splatterhouse project here.