Tag Archives: AVR microcontrollers

Make your houseplants smile with ATtiny85

This simple sensor can tell you exactly how your plants “feel.”

Faced with hectic schedules, it is often easy for us to forget to water our favorite plants. Typically the strong and silent type, plants likely won’t notify you when they are in need of a drink or some nutrients. However, that may all change after one Maker’s clever Atmel based design which now provides plant owners with a visual representation of just how their plant is feeling.


“Thanasisloi7” hooked an ATtiny85 to a soil hydrometer sensor that analyzes the current moisture within the plants soil. When the soil is properly watered, an LED matrix displays a happy face. Conversely, when the soil moisture falls below a specified level, the smiling face disappears. Thus, any plant owner with common sense can know when to replenish the pot’s water supply.


Though just a simple project, this quick design will make sure you never let your plants go thirsty again. As they say, a smile is worth a thousand words. Looking to build a better bond with your plants? Check out his official project page here.

This isn’t the first time once-ordinary objects have been transformed into “sentient beings.” Last summer, digital agency Soap Creative launched Cars That Feel, an interactive festival installation designed with Toyota. The project featured a number of cars, each of which boasted their own personality and connected with people via light projections, color and sound. The vehicles were equipped six internal BenQ projectors, Atmel powered controllers and high intensity LED light rigs. Meanwhile, a custom app was tasked with controlling internal projection mapping, lighting, sound and animation.

An open-source PLC to control the Internet of Things

Controllino is the first software open-source, Arduino-compatible PLC. 

Designed by the SG-Tronic team, the Controllino is an open-source programmable logic controller (PLC) built around Atmel’s ATmega328 and ATmega2560 microcontrollers (MCUs). Recently funded on Kickstarter, the Arduino-compatible PLC allows Makers to produce and control their next Internet of Things project, ranging from industrial to home automation applications.


“When I was at electronic school, I would have loved Arduino. But back then, microcontroller programming wasn’t that easy. When I became aware of Arduino, I thought… What a great idea for young people and those who are not hardcore microcontroller programmers,” creator Marco Riedesser explained. “The only problem with Arduino is [that] when you don’t really know so much about electronic hardware, driving more than a LED can become difficult. And using an Arduino board in a professional project or even a product that you want to sell is quasi impossible if you want to get certification.”

Now fully UL and CE-certified, Makers can begin creating and actually shipping gadgets such as drones, home appliances, or any other electronic project that comes to mind. The Atmel powered PLC is currently being presented in three models: Mini, Maxi and Mega.

“I had to repair the coffee machine for my brother-in-law. I thought it would be easy to use Arduino but there was nothing on the market that could handle switching high voltage and high current. So I thought I had to come forward with a product,” Riedesser revealed to TechCrunch earlier this year.


All Controllino PLCs are equipped with an internal RTC using SPI, which can be switched on/off and allow for the use of SPI for other purposes via pin header. With built-in processor contact, Makers have a direct link to a number of boards (like Arduino). All pins are also 4000V ESD protected. What’s more, both the Controllino Maxi and Mega let users select between internal RTC and Ethernet using SPI, as well as turn it off so they can use the SPI for other purposes via pin header.

The versatile device works in altitudes up to 2,000m above sea level, in temperatures ranging between 5°C to 55°C, and in maximum relative humidity 80% for temperatures up to 31°C decreasing linearly to 50% relative humidity at 55°C. Each Controllino features an automatic input voltage range selection. This internal function changes voltage dividers ratio on the processor input, and enables the use of one input for analog and digital and for 12V or 24V input voltage range without user action. In addition, the Controllino’s main supply voltage fluctuates up to ±10% of the nominal voltage


Key Mini specs:

  • MCU: ATmega328 MCU
  • RTC
  • Clock speed: 16 MHz
  • 1x RS232 interface
  • 1x SPI interface
  • 6x relay outputs (230V/6A)
  • 8x digital outputs (2A @12V or 24V)
  • 8x analog/digital inputs
  • 10A input current max


Key Maxi specs:

  • MCU: ATmega2560
  • RTC
  • Clock speed: 16 MHz
  • Ethernet connection
  • 2x RS232 interface
  • 1x RS485 interface
  • 1x I2C interface
  • 1x SPI interface
  • 10x relay outputs (230V/6A)
  • 12x digital outputs ( 2A @12V or 24V)
  • 12x analog/digital inputs
  • 20A input current max


Key Mega specs:

  • MCU: ATmega2560 MCU
  • RTC
  • Clock speed: 16 MHz
  • Ethernet connection
  • 2x RS232 interface
  • 1x RS485 interface
  • 1x I2C interface
  • 1x SPI interface
  • 16x relay outputs (230V/6A)
  • 24x analog/digital inputs
  • 12x digital outputs – high side switch (2A @12V or 24V)
  • 12x digital outputs – half-bridge (2A @12V or 24V)
  • 20A input current max

Interested in learning more? You can check out Controllino’s official page here. Those wishing to purchase the Mini, Maxi and Mega can now do so for € 119.00, € 199.00 and € 269.00, respectively.

Tutorial: Building cool projects with MCUs (Part 5)

I finally received the circuit boards! And, in this fifth and final part of the microcontroller tutorial, we are going to solder the components to the circuit board and program the MCU using the USB port of a computer.

Just to refresh our memories, so far we have learned:

Microcontroller PCB

I recently ordered the PCBs from Seeed Studio. In order to expedite their delivery, I used a more expensive shipping option from UPS. I did get the boards pretty fast – but I also got an unexpected bill from them because they had to take it through customs.

So, even though the boards were only $10, I ended up with paying about $60 in shipping and customs… But luckily, there exists a much cheaper shipping option (about $3-4) – you just have to wait a little bit longer for the boards to arrive.

Let’s solder the board!

I wanted to make this circuit in such a way that it was possible to make it at home. To solder the circuit, I’m going to use my old Ersa soldering iron and some standard solder wire. The tip of the iron is a bit thick, so it’s really not ideal for this job. However, I know many people only have a simple soldering iron like this lying around the house – so it’s the perfect test to see if this is something that anyone can build from the comfort of your home.

Ersa30 Soldering Iron

The first thing we’re going to solder is the MCU chip. This is also the hardest part to solder. I have to admit – when I looked at my soldering iron, then looked at the chip – I was a bit worried that it was going to be hard. But the main trick here was to be patient!

To solder the surface mount components, we can use the techniques described in this smd soldering article.

First, we solder one corner pin of the chip. When we have managed to solder this one pin correctly – and all the pins are aligned over their pads – we move on to the corner on the other side. With two corners soldered properly, all we need to do is to add a tiny bit of solder to all the other pins and pads.

MCU chip soldered

Don’t rush it. Take your time. Inspect the pins closely to see if they are soldered and that they don’t have a “solder bridges” to their neighbors. And, don’t worry if it looks a bit like a war-zone with solder all over – just look at mine above – it still works!

Now, safe to say that the worst part is over. The other components are pretty straightforward to solder. Just make sure the LED and the polarized capacitor is placed in the correct direction.

Microcontroller circuit board

Programming the circuit

Once we are confident that the components are soldered properly, it’s time to test it! First, we need to check if the USB interface works. Otherwise, we won’t be able to program the circuit. To test the USB interface, all we need to do is to connect a USB cable and connect the circuit to our computer. From there, we can just check if it pops up as a USB device on the computer.

And… it does!

So, let’s program the MCU. A simple way of testing it is to make an LED-blink program. This is a simple program that, well, makes our LED blink. It looks like this:

#define F_CPU 1000000 // The chip runs at 1 MHz as default (even if you are using a 8MHz crystal)


int main(void)
DDRC = (1<<PC7); //Sets the direction of the PC7 to output
PORTC = (1<<PC7); //Sets PC7 high

_delay_ms(500); //Wait 500 milliseconds
PORTC &= ~(1<<PC7); //Turn LED off

_delay_ms(500); //Wait 500 milliseconds
PORTC |= (1<<PC7); //Turn LED on

return 0;

We save this code in a file called led-blink.c

Compiling our code

The first thing we need to do is to compile our code into machine code that the MCU can read. One way of doing this is through Atmel Studio. But, since I am a big fan of using the Linux terminal, I’ll show you how to compile and upload a program using Ubuntu.

First, install avr-gcc with the command:

sudo apt-get install avr-gcc

Then, compile the code and make it into the right format with the following commands:

avr-gcc -mmcu=atmega32u2 -Os blink-led.c -o blink-led.out
avr-objcopy -j .text -j .data -O ihex blink-led.out blink-led.hex

The resulting file – blink-led.hex – can now be uploaded to the microcontroller. You can find more information on the commands here.

Uploading the code to the MCU

Time to upload the program and see if it works. One way to do this is by using Atmel’s FLIP software. But, once again, let’s see how we can do it with the Linux terminal.

Install dfu-programmer with the command:

sudo apt-get install dfu-programmer

Then, erase the old flash memory on the MCU and upload the compiled .hex file:

sudo dfu-programmer atmega32u2 erase
sudo dfu-programmer atmega32u2 flash blink-led.hex

Unplug the circuit from your computer, then plug it in again. And what do you know, the LED starts to blink!

Blink LED microcontroller circuit

Making something cool

Now that we’ve got it working, we’re ready to make something cool. There are so many cool things you can make with a microcontroller. For example, you can connect it to this Wi-Fi module and make the LED blink every time @AtmelMakes posts a new tweet.

Or, how about connecting it to this sound module and this motion sensor, and make it play a Christmas song every time someone goes near your Christmas tree? As Atmel always says, the possibilities are truly endless.

If you missed any of the previous parts of this tutorial – you can find them here:

Paying homage to the “Father of Video Games” Maker style

Sadly, the “Father of Video Games” has passed away at the age of 92. Ralph Baer was a prolific inventor who earned more than 150 patents in his lifetime, in addition to having created the precursor to both Pong and the electronic memory game Simon. The true pioneer went on to develop the Magnavox Odyssey in 1972. Credited as the the first home gaming console, the Odyssey was battery powered, and featured a controller with two knobs to move horizontally and vertically.


A Maker in every sense of the word, the Father of Video Games’ legacy has surely inspired countless others to pursue their ideas. In fact, we have decided to pay tribute to Baer by compiling some of our favorite video game-inspired DIY projects…

Turning a storefront into a arcade game


Competing in the world’s largest online Mastermind game


Saying goodbye to thumb cramps on 3DS


Playing Tetris on your t-shirt


Modding a speech-controlled Game Boy Advance


Retro gaming with the Magpi


Configuring an 8x8x8 LED cube as a Space Invaders game


Recreating the retro game of Pong


Playing Tekken on a piano


Devising a dead-icated Splatterhouse arcade game


Gaming it up on Gameduino 2


Drawing actual blood every time your character bleeds


Hacking 8-bit chiptunes with this DIY instrument


Playing Doom on a hacked printer


Turning your Moto 360 into a classic 007 smartwatch


Reliving the days of 8-bit gaming with Uzebox


Wearing Tetris on your wrist


Making your own credit-card sized gaming console


Ralph, you will certainly be missed!


8- or 32-bit, that is the question…

Writing for Electronic DesignAtmel’s Ingar Fredriksen and Paal Kastnes recently explored the latest market trends for both 8- and 32-bit microcontrollers (MCUs). While the 32-bit MCU devices continue to rise in popularity throughout the embedded community, 8-bit MCUs are still experiencing a CAGR close to that of their bigger cousins.

These 32-bit, function-rich devices suit an array of different applications, which explains why many embedded developers select them for their next designs. Designers recognize that such complex devices offer everything they need in terms of raw compute power, a rich peripheral set, and easy access to a wide range of development tools and libraries.

Many of these 32-bit devices — which are members of the Atmel | SMART family — are based on the highly-successful ARM cores. Thus, developers feel confident in having access to second source devices and a comprehensive set of development, test and validation tools being available in the market.

However, taking a closer look at recent MCU market trends has revealed that 32-bit devices aren’t the only ones experiencing strong growth. The surging 8-bit MCU market boasts a CAGR (6.4%) close to that of 32-bit (6.9%). Meanwhile, a number of other industry analysts forecast identical growth rates for 8- and 32-bit microcontrollers.

The upswing in 8-bit devices, like the incredibly popular Atmel AVR lineup, clearly highlights that there must be some compelling reasons to use an 8-bit device in place of a 32-bit MCU. The recently-published Electronic Design article looks to shed some insight as to why 8-bit devices are retaining market share.

Essential Differences

The principle differences between 8- and 32-bit MCUs are cost and price structure, CPU performance, ease of use, efficiency in hardware near functions, and static power consumption. When embarking on a new design, developers need to carefully scope out the requirements for an MCU based on the amount of processing capability required, the degree of interfacing needed, and, for battery-powered designs, the all-important power consumption profiles. There’s no doubt that a 32-bit MCU delivers higher performance than an 8-bit device, but the engineer faces the traditional decision of choosing between the best available device in the market versus an application’s actual needs.


Of course, these decisions will greatly influence the likely bill of materials (BOM) cost. With a lower gate count, a less complex 8-bit device will certainly be cheaper than a 32-bit device. When comparing 8- and 32-bit MCUs from leading vendors, each with a similar amount of flash memory, pin-out etc., 8-bit devices typically cost about 20% less. But this is only the first of many considerations. Another aspect relates to the ease in setting up for a new development.

Ease of Development

MCU suppliers tend to add more features and functionality to their 32-bit devices as opposed to 8-bit products. Consequently, far more setup considerations emerge with a more complex device. While some 32-bit MCUs can run with a limited setup similar to that of an 8-bit device, you’re unable to take advantage of the more powerful device’s additional features.

For example, a typical 32-bit ARM device will have independent clock settings for the core itself, the AHB bus, the APBA bus, and the APBB bus. They all can be set to different frequencies. Typically, you will also have to switch to the clock you want to use because it’s set in software, not in hardware like most 8-bit parts. Furthermore, changing the clock means you must set up the wait states for flash, possibly predicated on measured VCCvoltage.

Such a setup can be much simpler with an 8-bit MCU, though. For example, Atmel’stinyAVR and megaAVR products only require initialization of the stack pointer, which typically takes four lines of code, prior to coding the application. The choice of clock, brownout detector, reset pin function, etc., is all pre-programmed into the device.

The architecture is also much more straightforward than a 32-bit device with internal registers, peripherals, and SRAM all mapped on the same data bus. The peripherals and CPU would normally run at the same frequency, so no peripheral bus configuration is necessary. Moreover, designers can avoid being concerned about latency in synchronizing between different clock domains.


When it comes to desired CPU performance, the engineer should consider all use cases. The reality is that many embedded designs don’t have high compute requirements. Often, very little manipulation of data is required, so balancing those needs against power-consumption and peripheral-interfacing requirements becomes crucial.

For instance, a simple thermostat application will spend most of its life in a sleep mode. Every so often, it will wake up and measure the temperature and then make a decision to turn a relay on/off or send an instruction to a host controller. Then it will resume sleep. The compute and interface requirements of this application are small, but many other applications such as fire detectors, power tools, flow meters, and appliance controls have a similar use profile, too.

Efficiency of Hardware Near Functions

Many modern microcontrollers incorporate some hardware functions that serve to help the CPU operate as efficiently as possible. In Atmel’s case, both the 8-bit AVR and 32-bit ARM-based MCU families feature the Peripheral Event System. An event system is a set of hardware-based features that allows peripherals to interact without intervention from the CPU. It allows peripherals to send signals directly to other peripherals, ensuring a short and 100% predictable response time.

When fully using the capabilities of the event system, the chip can be configured to do complex operations with very little intervention from the CPU, saving both valuable program memory and execution time. In the case of detecting a hardware event, it’s important to first detect the event and then switch control to the desired interrupt service routine (ISR).

In these situations, CPU speed isn’t the single determining factor. It’s a question of how long, in terms of cycles, does it take to respond to the interrupt, run the ISR, and return. As the following example will show, 8-bit devices can be more efficient in handling hardware near actions.


Consider receiving one byte on the SPI, using an interrupt to detect it, and then running a simple ISR routine to read the byte from the SPI peripheral and store it in SRAM. Using this scenario, table above draws comparisons between an Atmel 8-bit AVR device and an Atmel ARM Cortex M0+based 32-bit MCU. Calculated with information available, the results are based on minimum implementations. However, engineers should check with their own applications since the interrupt detection and return from interrupt could take more cycles than shown in the table. Requiring 12 cycles versus 33 cycles equates to having a theoretical maximum SPI bandwidth of 1.67 MB/s for the 8-bit CPU and a 606 kB/s bandwidth for a 32-bit CPU when running at 20 MHz.

The degree of numeric processing can also have an impact on the stack and required memory. Applying the Fibonacci algorithm is one particularly good method for testing memory requirements. Since it only uses a local variable, everything needs to be pushed to the stack.

When making a comparison between an 8-bit AVR and an ARM 32-bit CM0+-based device, and using a recursive 15-stage Fibonacci algorithm, the AVR uses a total of 70 bytes of stack, including 30 for return stack (15 calls deep). The ARM-based device uses 192 bytes (60 should be return stack). This means the CSTACK is more than three times the size of the 8-bit solution. In typical C code, more of the variables on the stack often come in a packed format, so this is an extreme corner. However, saying 1.5 to 3 times more SRAM is needed for the same 8-bit-centric application on a 32-bit (versus a native 8-bit) device is a fair estimation.

Power Consumption

No MCU article would be complete without investigating static power consumption. This alone may be a key factor in choosing between an 8- or 32-bit device, especially for battery-powered applications. The table below illustrates power-consumption differences between 8- and 32-bit devices in both active and static modes.


Aggressive manufacturing technologies increase transistor leakage current, which roughly doubles with each process generation, and is proportional to the number of gates. Leakage current increases exponentially at higher temperatures, which can be easily overlooked when designing a consumer design. Mobile phones and personal media players are transported everywhere, and as we have all found out, temperatures experienced during the summer inside a car can easily climb above 40°C.

The amount of time the microcontroller will spend in active mode versus static mode contributes significantly to the overall application power budget.

Naturally, the ratio between active and static modes will vary depending on the application requirements. Taking the previous SPI interrupt example (second table from above) and assuming a SPI data bandwidth of 80 kb/s, the 8-bit CPU will spend 1.2% of its time in active mode compared to that of the 32-bit, which will spend 3.3% in active mode (table below).



Contemplating whether to use an 8- or 32-bit microcontroller for a future design may involve an Internet of things (IoT) application. How IoT actually takes shape provokes lots of debate, but it will certainly challenge engineers to make a detailed appraisal of the MCU requirement. Wireless connectivity, especially ZigBee, will also be an essential component, but that doesn’t automatically mean that it will need a higher power device.

A number of available 8-bit microcontroller products satisfy the need for low levels of processing and wireless connectivity. One such example is the Atmel ATmegaRFR2 series, which provides an IEEE 802.15.4-compliant, single-chip, 2.4-GHz wireless microcontroller solution that suits battery-powered, low-cost IoT designs.

Interested in reading more? Be sure to check out the original article from Electronic Design here.

Could the 8-bit MCU be experiencing a renaissance?

So, is the 8-bit MCU experiencing a renaissance? According to Electronics Weekly, it’s rather possible. A recent article notes that despite the rise of ARM architecture and widespread adoption of 32-bit microcontrollers (MCUs), a number of suppliers like Atmel are “more committed to their 8-bit chips than ever before.”


In fact, the publication points out that companies are now adding higher performance peripherals and extending development tools for their highly-popular 8-bit lineups.

“Atmel is another supplier which continues to invest in its range of megaAVR MCUs. Now in their third generation, the MCUs are attracting growing interest in hobbyist/professional crossover applications as a result of being designed into the Arduino low cost embedded computing platform.”

Since its initial launch in 2002, the megaAVR family has become the go-to choice of Makers and engineers alike. The MCUs, which include the stalwart ATmega328 to ATmega32U4, can be found at the heart of millions of gadgets and gizmos, including an entire lineup of Arduino boards, 3D printers such as RepRap and MakerBot, as well as a number of innovative DIY platforms.

“This family of 8-bit megaAVR MCUs has been highly recognized by a variety of communities from the professional designers using our Atmel Studio ecosystem to the hobbyist and Maker in the AVR Freaks and Arduino communities,” explained Oyvind Strom, Senior Director of Marketing for Atmel’s MCU Business Unit.

These MCUs run single-cycle instructions with performance of 1MIPS per MHz, while on-chip flash memory spans from 4KB to 16KB. These new devices provide next-gen enhancements including analog functionality and features for the latest low-power hungry consumer, industrial and IoT applications.


As Electronics Weekly notes, the burgeoning Maker Movement combined with the low-cost embedded board phenomenon has created a new playground for 8-bit devices. This “new relevance” has never been more apparent than with Arduino’s adoption of AVR MCUs, which can be found in its wildly-popular Uno (ATmega328), Leonardo (ATmega32U4) and Mega (ATmega2560) to name just a few.

The primary attraction of 8-bit MCUs is not only affordable performance, but with 8, 14 and 20-pin packages, they also are affordable and easier to use than their 32-bit counterparts.

Development tools are also matching the increasing range of higher performance applications for these MCUs as well. Take Atmel’s Xplained Mini 8-bit development platform for instance, which not only costs less than $9 but are also designed with an optional Arduino header for expandability.


The article goes on to reference IAR Systems, who recently updated its high-performance development tools for 8-bit MCUs. Just a few weeks back, IAR Systems and Atmel announced an extension of their ongoing partnership would include over 1,400 example projects in IAR Systems’ development tools to support Atmel’s entire portfolio. This allows designers using microcontrollers, like the 8-bit AVR, to leverage the Embedded Workbench C/C++ compiler and debugger toolchain with new example projects to bring their products to market faster.

Interested in reading more? You can access the entire article here. Meanwhile, you can also browse through our extensive lineup of 8-bit microcontrollers here.

Using the power of two MCUs on an Arduino board

While the latest batch of Arduino and Arduino-compatible boards either have a chip capable of USB or rely on a V-USB implementation, did you know earlier Uno and Mega boards actually have two microcontrollers?


Writing for Hackaday, Brian Benchoff notes that “an ATmega16U2 takes care of the USB connection, while the standard ‘328 or ‘2560 takes care of all ‘duino tasks. Wouldn’t it be great is you could also use the ’16U2 on the Uno or Mega for some additional functionality to your Arduino sketch?”

That’s now a reality thanks to a Maker by the name of NicoHood. Both the [Atmel based] Uno and Mega boards possess a pair of MCUs, of which the ’16U2 is generally used for USB-Serial translation. Meanwhile, it can serve as standalone AVR MCU with (or without) USB functions as well.

Using what NicoHood calls “HoodLoader2,” Makers now have the option of reprogramming the ‘16U2 of an Arduino Uno/Mega R3 with custom sketches, and using its seven (sometimes overlooked) I/O pins.


“This means you can use the ’16U2 as a normal USB AVR like a Leonardo,” NicoHood adds.

With a fully-compatible USB-HID core and CDC serial, HootLoader2 is a real bootloader for the ’16U2 — not a firmware. It can replace the DFU bootloader with a CDC bootloader and USB serial function. This enables new USB functions like an HID keyboard, mouse, media keys and a gamepad, the addition of extra sensors or LEDs, or pretty much anything else you can do with a normal Arduino, Benchoff explains.

“The great thing about this is that you actually have two fully Arduino-compatible microcontrollers in one Arduino Uno/Mega board – the board most of you already own. Your main MCU (328/2560) is still reprogrammable if you enter bootloader mode. All you need for this is a normal Arduino Uno/Mega R3 and some cables to install the new HoodLoader2.”

You can read all about the HootLoader2 on NicoHood’s official page here.