Category Archives: Design Tips & Tricks

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)

#include
#include

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

while(1)
{
_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:

Good electronics videos and articles

My buddy Rob Bowers over at Brocade told me about this video channel for home made (aka Maker) electronics projects. It’s produced by Alan “W2AEW” Wolke. You can see by his nickname and video channel name, he is a Ham radio enthusiast. I never got that bug, my projects were more like a wire wrapped around a nail to make an electromagnet.

The video above is what got my buddy Rob excited. He enthused, “Wow electronics for everybody! There may be hope for me. I watched the one on completing the noise source on the Ham It Up! convertor. He builds it, tests the basics, and the shows a simple use case. I feel .031% less stupid. I wanted to know if I should purchase the noise source parts. ‘Yes’ is the answer, after watching this.”

This is the cool thing about the Maker Movement. Rob is not an engineer. He did software QA in the past and now works at Brocade in the IT department. He is technical, but not formally trained. But the Maker movement is about the fun stuff, and the dreary classrooms and boring lectures are dispensed with in favor of learning with a specific objective in mind. It’s all the fun of engineering without the tedium. We invented computers. They can do the tedium, and the math, for that matter.

Alan-W2AEW-Wolke

Electronics enthusiast Alan Wolke at his bench.

You can see from Alan’s bench the passion he has for radio and electronics in general. Any person with a Metcal soldering iron and a Simpson 260 analog voltmeter is OK by me. The extended CRT (cathode ray tube) housing on that scope makes me think it is the 400MHz Tek 2467B, the fast glitch capture version of the Tektronix 2465B. The CRT is longer to add the plates needed for persistence.

Another cool tip from Rob was about Brocade where he works. He told me the labs have vending machines with cables and mice and other day-to-day engineering essentials. The engineers can just swipe their badge into the vending machine, pick out the cable and be on their way, no requisition forms or hassle. What a class outfit.

The good electronics article tip comes from a fellow eFlea attendee. I saw him at the Roasted Bean in Cupertino and he showed me the latest issue of Nuts and Volts magazine.

Arduino-101-article-Joe-Pardue

Nuts and Volts magazine has a ton of good articles about electronics.

Knowing I worked at Atmel, my pal wanted to point out the above article about Arduino by Joe Pardue. Nuts and Volts is a subscription magazine, so you have pay 27 bucks a year for print and digital, or only 20 bucks a year if you don’t want the print magazine.

Even without subscribing, you can download the code samples for the Arduino 101 article, and if you upgrade to the mysterious un-priced “preferred subscriber network” you get access to all the old issues of Nuts and Volts. This is a great complement to Circuit Cellar magazine, which is also a subscription magazine, but for $250 they can also give you a memory stick with every single article they have ever done. I recommend both these magazines since they are aimed at system design. The trade press, where I have worked, is fine to learn about the latest chip or test method. But Circuit Cellar and Nuts and Volts both show you how to hook up the chips, and do the code and everything else to get a working product. They even touch on 3-D printing and the stuff to put your gizmo in an enclosure. No wonder they can charge for a subscription. All they lack is articles about FCC, CE, and UL approvals, and those might happen one day for all I know.

So keep watching those YouTube videos and reading articles, but more importantly, keep hacking on circuits and code. That is the fun stuff that gives real satisfaction and happiness.

Tutorial: Building cool projects with MCUs (Part 4)

I still remember the first time I created my own circuit board. It was such an amazing feeling to be able to see it working. It was actually also a microcontroller circuit. But it couldn’t be programmed through USB, you needed a JTAG programmer. That’s why I’m really excited about the circuit we are building in this tutorial – no programmer or debugger required!

But before we begin, let’s recap: In part one we covered the basics of microcontrollers. Then, in part two we chose a microcontroller for our purpose. Later in part three, we selected which other components we needed, and designed a circuit diagram.

Now, in part four, we are ready to create a circuit board.

How to Create Your Own Circuit Board

The basic process for creating a circuit board is as follows:

  • Design schematics
  • Design board layout
  • Create a board from your layout by etching, CNC milling or using a board manufacturer

We need some design software to do this. There are many available alternatives, but in this post we’re going to use Cadsoft Eagle, which is available for Windows, Mac and Linux. And, another bonus, it’s available as a free version for hobbyists.

Creating Schematics in Eagle

In the previous post, we decided which components to use, and how to connect them. Here is the result:

ATmega32U2 circuit diagram

Now, we need to decide if we want through-hole components or surface mount components, then create a schematic diagram in Eagle.

Through-hole components are easier to solder, but surface mount devices takes less space. Also, they don’t require any drilling, which simplifies the manual work that needs to be done if the board is etched.

I decided to go for mostly large SMD components and a few through-hole components.

Some of the components were not available in Eagle’s default component library; the ATmega32U2 and the USB connector. Instead of spending time making custom versions of these, I did some Googling and found a USB connector in the Sparkfun Eagle library. And I also found a library with the ATmega32U2 chip.

We place all the components in the schematics view of Eagle, and connect them according to the image above.

Designing The Circuit Board

When we have our circuit ready in the schematics view of Eagle, all we have to do is to click the «Board» button on the toolbar to create a board layout from the schematics.

Getting from scheamtics to board layout in Eagle

If you want to learn the exact steps on how to design your own circuit boards from scratch, I’ve written a lot of tutorials on PCB design on my personal blog.

Let’s start by setting our board size. I chose 5cm x 5cm (1.9685 in x 1.9685 in). Why? Because I know it’s possible to find really cheap prototype boards that are this size.

Next, we move all the components onto the board. Since everything is designed around the MCU, we’ll place the MCU in the middle. If we want to etch or CNC mill a board, it’s easier if everything is on one side. Therefore, we’ll stay on the top layer of the board on this design.

Circuit board layout for ATmega32U2 circuit tutorial

You can download the Eagle and gerber files here: Microcontroller-tutorial-files.zip

Getting The Circuit Board Design Made

Now, with a board design ready, we need to make this into a physical board. There are several ways to go about doing this — it can be done through etching, CNC milling or by ordering from a prototype manufacturer.

I usually order prototypes from a PCB manufacturer. This is just so easy and you don’t have to worry about manually drilling holes or inserting vias into your board. Everything is just taken care of. And usually with much better precision than you can expect from etching or CNC milling.

Many people think it’s expensive to order prototypes from prototype manufacturer, but this is not the case. Many offer prices as low as $9.99 for 10 boards. That’s 99 cents per board! And if you choose the cheapest shipping option it will only cost a few dollars.

A great tool for finding the best price is pcbshopper.com. Here you can enter board size and other requirements, along with your country – and you’ll find the best price and delivery option for you.

Ordering Components

It’s not much fun with a circuit board without any components; so, the last step we’re going to do today is ordering the components. There are many available shops online that sells components, including digikey.com, farnell.com, jameco.com and mouser.com.

Most of the components we have used in this tutorial are available everywhere. The only component that might not be in stock everywhere is the ATmega32U2. But Atmel has a great tool to check the inventory of several online shops.

Here are the components used for this board:

Part Description Value Package
C1 Capacitor 1µF SMD 1206
C2, C3 Capacitor 12-22pF SMD 1206
C4 Capacitor Polarized 10µF Through-hole
JP1 USB Connector USB Type B Receptacle Through-hole
JP2, JP3 Header 8 pin Through-hole
LED1 Light Emitting Diode 1.8V Through-hole
Q1 Crystal 8 MHz SMD C49UP
R1, R2 Resistor 22 Ohm SMD 1206
R3 Resistor 200 Ohm SMD 1206
R4 Resistor 10k Ohm SMD 1206
S1 Momentary Switch Through-hole
U1 Microcontroller ATmega32U2 TQFP-32

Next Steps

When we have ordered everything we need, it’s time to sit back and relax! Hopefully it won’t take too long before the components arrive at our door. I am already super excited to start soldering the circuit. However, there is no guarantee it’ll work – we will just have to wait and see in the next (and last) part of this tutorial.

Stay tuned for Part 5 in the coming days…

How far can you take the ATtiny10?



Atmel’s stalwart tinyAVR lineup has been a Maker favorite for years, with the microcontrollers powering a wide-range of devices and platforms.

c57b1f48465b91ffda007158d190b710

Recently, a Maker by the name of Tim (aka cpldcpu) decided to find out just how far he could take the versatile ATtiny10 with his µ-Wire project.

“I previously used the ATtiny10 in the TinyTouchbutton, a touchbutton controlled light with WS2812 LEDs. This time I aimed higher: Is it possible to turn the ATtiny10 into a USB compatible device?” Tim wrote in a recent blog post.

“My goal was to implement a subset of the little-wire functionality to control a WS2812 LED by USB. This takes 3 I/O lines, which is exactly the number of free pins on the ATtiny10.”

As Tim notes, little-wire supports a number of functions to control WS2812 LEDs on arbitrary I/O ports. However, he simplified this approach by only supporting a single LED on a specific pin, while still retaining protocol compatibility. Meaning, all the little-wire host programs were still functional, with the finished device fully capable of being used as an RGB indicator LED similar to the Blink1.

“The V-USB USB interface requires more than 1.5kb of flash in its smallest implementation and uses more than 50 bytes of RAM, including stack usage,” he explained. 

”Additional code is required to implement the little-wire interface and to write to the WS2812. The ATtiny10 has 1kb of flash, 32 bytes of SRAM and 16 instead of 32 registers. So this ended up as a nice exercise in cutting down V-USB to its bare essentials – and further.”

One critical step towards reducing the memory footprint, Tim admits, was adopting an interrupt-free implementation of V-USB, as developed for micronucleus. This allowed him to lower the SRAM footprint by omitting register saving on the stack and avoiding double buffering — all while facilitating the reduction of program size.

Further measures to reduce code size include clocking the controller at 12 MHz (using the internal RC oscillator), manually remapping numerous registers in V-USB to avoid collisions with the GCC, removing all handling of the reset signal on the USB-Bus and altering the code to support replies from the SRAM.

Final stats?

  • 

Flash: 988 of 1024 bytes used (96.4%)
  • SRAM: 28 (variables)+2 (stack) of 32 bytes used (93.8%)

“This is most likely the most complex firmware ever loaded into an ATtiny10,” Tim added. “[Plus], it also works with the new 8mm WS2812 LEDs.”

Interested in learning more? You can check out the relevant files on Github, as well as read Tim’s detailed blog post here.

Don’t be an “ID-IoT”


Authentication may just be the “sine qua non” of the Internet of Things. 


Let’s just come out and say it: Not using the most robust security to protect your digital ID, passwords, secret keys and other important items is a really, really bad idea. That is particularly true with the coming explosion of the Internet of Things (IoT).

Hacker

The identity (i.e. “ID”) of an IoT node must be authenticated and trusted if the IoT is ever to become widely adopted. Simply stated, the IoT without authenticated ID is just not smart. This is what we mean when we say don’t be an ID-IoT.

It seems that every day new and increasingly dangerous viruses are infecting digital systems. Viruses — such as Heartbleed, Shellshock, Poodle, and Bad USB — have put innocent people at risk in 2014 and beyond. A perfect case in point is that Russian Cyber gangs (a.k.a. “CyberVor”) have exposed over a billion user passwords and IDs — so far. What’s scary is that the attacks are targeted at the very security mechanisms that are meant to provide protection.

If you think about it, that is somewhat analogous to how the HIV/AIDS virus attacks the very immune system that is supposed to protect the host organism. Because the digital protection mechanisms themselves have become targets, they must be hardened. This has become increasingly important now that the digital universe is going through its own Big Bang with the explosion of the IoT. This trend of constant connectivity will result in billions of little sensing and communicating processors being distributed over the earth, like dust. According to Gartner, processing, communicating and sensing semiconductors (which comprise the IoT) will grow at a rate of over 36% in 2015, dwarfing the overall semiconductor market growth of 5.7%. Big Bang. Big growth. Big opportunity.

The IoT will multiply the number of points for infection that hackers can attack by many orders of magnitude. It is not hard to see that trust in the data communicated via an ubiquitous (and nosey) IoT will be necessary for it to be widely adopted. Without trust, the IoT will fail to launch. It’s as simple as that. In fact, the recognized inventor of the Internet, Vint Cerf, completely agrees saying that the Internet of Things requires strong authentication. In other words, no security? No IoT for you!

BxLpafwIcAAMcG0

There is much more to the story behind why the IoT needs strong security. Because the world has become hyper-connected, financial and other sensitive transactions have become almost exclusively electronic. For example, physical checks don’t need to be collected and cancelled any more — just a scanned electronic picture does the job. Indeed, the September 11th terror attacks on the U.S. that froze air travel and the delivery of paper checks accelerated the move to using images to clear checks to keep the economy moving.

Money now is simply electronic data, so everyone and every company are at risk of financial losses stemming directly from data breaches. See?  Data banks are where the money is now kept, so data is what criminals attack. While breaches are, in fact, being publicized, there has not been much open talk about their leading to significant corporate financial liability. That liability, however, is real and growing. CEOs should not be the least bit surprised when they start to be challenged by significant shareholder and class action lawsuits stemming from security breaches.

lawsuits

Although inadvertent, companies are exposing identities and sensitive financial information of millions of customers, and unfortunately, may not be taking all the necessary measures to ensure the security and safety of their products, data, and systems. Both exposure of personal data and risk of product cloning can translate to financial damages. Damages translate to legal action.

The logic of tort and securities lawyers is that if proven methods to secure against hacking and cloning already exist, then it is the fiduciary duty of the leaders of corporations (i.e. the C-suite occupants) to embrace such protection mechanisms (like hardware-based key storage), and more importantly, not doing so could possibly be argued as being negligent. Agree or not, that line of argumentation is viable, logical, and likely.

A few CEOs have already started to equip their systems and products with strong hardware-based security devices… but they are doing it quietly and not telling their competitors. This also gives them a competitive edge, besides protecting against litigation.

Software, Hardware, and Hackers

hacker_inside_intel

Why is it that hackers are able to penetrate systems and steal passwords, digital IDs, intellectual property, financial data, and other secrets? It’s because until now, only software has been used to protect software from hackers. Hackers love software. It is where they live.

Rogue

The problem is that rogue software can see into system memory, so it is not a great place to store important things such as passwords, digital IDs, security keys, and other valuable things. The bottom line is that all software is vulnerable because software has bugs despite the best efforts of developers to eliminate them. So, what about storing important things in hardware?

Hardware is better, but standard integrated circuits can be physically probed to read what is on the circuit. Also, power analysis can quickly extract secrets from hardware. Fortunately, there is something that can be done.

Several generations of hardware key storage devices have already been deployed to protect keys with physical barriers and cryptographic countermeasures that ward off even the most aggressive attacks. Once keys are securely locked away in protected hardware, attackers cannot see them and they cannot attack what they cannot see. Secure hardware key storage devices — most notably Atmel CryptoAuthentication — employ both cryptographic algorithms and a tamper-hardened hardware boundary to keep attackers from getting at the cryptographic keys and other sensitive data.

tamper

The basic idea behind such protection is that cryptographic security depends on how securely the cryptographic keys are stored. But, of course it is of no use if the keys are simply locked away. There needs to be a mechanism to use the keys without exposing them — that is the other part of the CryptoAuthentication equation, namely crypto engines that run cryptographic processes and algorithms. A simple way to access the secret key without exposing it is by using challenges (usually random numbers), secret keys, and cryptographic algorithms to create unique and irreversible signatures that provide security without anyone being able to see the protected secret key.

Crypto engines make running complex mathematical functions easy while at the same time keeping secret keys secret inside robust, protected hardware. The hardware key storage + crypto engine combination is the formula to keeping secrets, while being easy-to-use, available, ultra-secure, tiny, and inexpensive.

hash

While the engineering that goes into hardware-based security is sophisticated, Atmel does all the crypto engineering so there is no need to become a crypto expert. Get started by entering for your chance to take home a free CryptoAuthentication development tool.

Tutorial: Building cool projects with MCUs (Part 3)

As we proceed onto the third portion of this microcontroller tutorial, let’s first revisit what we have accomplished thus far.

In Part 1, we defined what a microcontroller actually was. I wanted to get everybody on-board (no pun intended) for this, so I started from scratch. Feel free to jump back there if you need a refresher.

Then in Part 2, we looked at the various types of MCUs. And, it turns out that there were a lot! However, by using Atmel’s selection tool, we managed to narrow it down to a few different ones, before choosing a winner — an ATmega32U2. Why? Mainly because it can be programmed through the USB interface without any extra components or tools, and since it did not have too many pins – so we should be able to solder it at home.

Now, the time has come for us to design the circuit diagram. We’ll start with outlining what we need, then we’ll dive into the datasheet to figure out exactly how we can do this.

Microcontroller in a circuit

What Components Do We Need?

If you’ve never done it before, putting all the necessary components onto the circuit diagram is not a super easy task. Well, the process is not that hard; but until you know how to do it, it will seem a bit difficult. So, let me take you through my thought process:

We need to power the chip somehow. There are some pins on the microcontroller that need power. We have to figure out which pins that need power, and what voltage they need.

We also want to program the chip trough USB, so we need a USB connector and learn how to connect it to the chip.

Then, there is extra stuff. Like maybe an LED to play around with, and definitely some connection pins that we can connect other stuff to later when we want to experiment.

So, we need to figure out:

  • How to power the circuit
  • How to connect the USB part
  • How to connect pins to the chip

Using the Datasheet to Find the Details of Our Circuit

The datasheet for the ATmega32U2 is a must when we are designing our circuit. Here, we can find all the necessary technical details.

We don’t have to read it from beginning to end; instead, we simply look up the parts we are curious about, and study them in more depth. We can find a table of contents at the end of the document.

For instance, if we wanted to use the timer of the MCU, we’d look up the part about timers. If we wanted to use the SPI communication part, we would look that up.

Connecting Power and USB

As you probably know, USB devices can be powered through, well, USB. By doing this, we simplify our circuit and require less components. So, let’s do this.

To figure out exactly HOW we can do this, we’re going to read the datasheet. By going to the table of contents, we find that the section that describes the USB part of the microcontroller is on page 186.

Here, there are different images showing how to connect the USB connector to the microcontroller to make it a USB powered device. For our circuit, we’ll use the bus-powered 5V version:

How to setup the MCU as a USB-powered device

Under Design Guidelines on page 189, we find the exact values we need for the resistors. It’s also there that we learn it’s highly recommended to use a 10µF capacitor on the VBUS, so let’s add that too.

Adding a Crystal

Another interesting thing to note from the image of how to connect the USB, is that there is also a crystal and a couple of capacitors connected to the XTAL1 and XTAL2 pins. This gives us the idea that we probably need a crystal too. But why?

Microcontrollers rely on clock signals to work. Every time the clock signal gives a pulse, something will happen in the processor. Most MCUs come with an internal RC-oscillator that can create this clock signal; however, the USB part of the microcontroller cannot operate from this internal clock — it needs a crystal oscillator to work.

To create a crystal oscillator, we need to connect a crystal and two capacitors to XTAL1 and XTAL2. By looking up “Crystal Oscillator” in the datasheet on page 36, we can also identify exactly what crystal and which capacitors are required.

Connecting an LED And Some Pins

By now, we have everything we need for the microcontroller circuit to work. But, we won’t be able to have much fun with it if we don’t add some connections to the input and output pins. And, it’s also good to add an LED. Everything gets better with an LED!

The LED needs to be connected through a resistor. We call this a current limiting resistor — this is to control the amount of current going through it.

From there, we will need a few physical pins that we can use to connect other stuff to our circuit. There are 22 I/O pins on the ATmega32U2, yet some of the pins are used for other purposes (like XTAL2), so we can’t use them all. For this circuit, we’ll add 16 I/O pins, as it’s a nice and round number.

What Else Do We Need?

On MCU circuits, it’s very common to include a RESET button. This makes it possible to reset the MCU without removing the power connection. This will add a couple of more components to our circuit and isn’t necessary to make it work, but it’s very handy, so let’s add it.

In the datasheet, we can see that pin 24 on the chip is the reset signal. It has a line over itself, which means that it’s activated when pulled low.

To make the reset signal stay in a high-state when the button is not pushed, we’ll add a pull-up resistor. This is a resistor up to VCC. And, we connect the button so that it will pull the reset-pin to ground when pushed.

The pull-up resistor should have a value of around 10k Ohm. For reference, SparkFun has a good article on how to choose a pull-up value.

Our Microcontroller Circuit Diagram

Now that we have figured out the different pieces of the circuit, it’s time to put them all into one circuit diagram. By adding everything into one circuit diagram, we end up with this:

Complete microcontroller circuit

Next, we need to create a circuit board out of this. Creating a circuit board does not have to be very complicated. In the subsequent part of the microcontroller tutorial series, we’ll design and make the circuit board.

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

Video: Vegard Wollan reflects on life and innovation

In the final segment of my interview with AVR microcontroller creator Vegard Wollan, I asked about his background and innovation at Atmel.

In response to my question of how he views his expertise, Vegard noted that he started out as a computer architect and digital designer. It’s simple to see the ease-of-use DNA in the AVR product line when Vegard then noted that he soon saw himself as someone that could make life easy for embedded designers. I think this focus on the customer pervades all of Atmel to this day.

Vegard-Wollen_innovation-at-Atmel

Vegard Wollan reflects on his history of innovation at Atmel.

I went on to ask Vegard what he does in his spare time. His response? Exercising and boating off the beautiful, dramatic Norwegian coastline. I think physical activity is a key thing. In fact, I wish someone had warned me as a young man that engineering has an occupational hazard. You can make a good living sitting at a desk. This was less true when I was an automotive engineer, as I had to go the experimental garage and walk around Ford’s giant complex in Dearborn, Michigan. Nowadays, we all seem chained to a computer, and stuck in a chair all daylong. So, exercise and boating sounds like a great way to stay active and balance our lives a little bit!

As I pictured Vegard sailing around Norway looking at beautiful sunsets, I wondered if that was inspired him to be so innovative. He responded that the primary source of innovation at Atmel is working with a team of creative innovative people. I think this is true in most human endeavors. When I asked my dad why some restaurants had really good service, he noted that good people like to work with other good people. That is why Vegard is spot-on, and quite humble in noting that innovation comes from a team, not any single person.

Want to learn more about the backstory of AVR? You can tune-in to the entire 14-part series 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…

Tutorial: Building cool projects with MCUs (Part 1)

I don’t remember exactly when I learned programming, but I played around with computers from an early age. I remember that it was such an amazing thing to be able to make my own programs. I made games and I made websites. And, it was so fun. When I was around 14 years old, I also started playing with electronic circuits. I made simple circuits of blinking lights and such. Also, a lot of fun.

Then at one point, I discovered microcontrollers. Oh, my God. I realized that by using microcontrollers I could combine programming and electronics to build robots, music players and what-not. It was a shockingly cool discovery. Wow!

electronics-project-with-dev-board-and-7-segment-1024x682

But understanding how to use a microcontroller wasn’t straightforward. There were programmers, EEPROM’s, debuggers, integrated development environments and a lot of different types of microcontrollers. It took me a few years before I started building projects using microcontrollers. Not because it took that long to learn it – but because the whole thing felt so overwhelming. And, I didn’t know where to start. But once I committed to just figure it out, it was actually quite fast to get up and running.

In this five-part microcontroller tutorial series, I will take you from knowing nothing – to being able to build and program a microcontroller circuit from home. To make sure we have everybody on board – let’s start from scratch by taking a look at what a microcontroller is.

Like a Tiny Computer

A microcontroller is somewhat like a tiny little computer. And, simiar to a computer, you can hook up things like a display, a motor, buttons and much more to it. Then, you put programs onto it and run them to make it do something.

OLYMPUS DIGITAL CAMERA

The things you can use a microcontroller for are endless! Among the countless possibilities include building robots, flying quadcopters, music players, or even smartphones.

Learning how to use microcontrollers opens so many opportunities for building new cool projects. Throughout this microcontroller tutorial, you will learn all you need to know, step-by-step, in order to get started with MCUs.

Getting Started With Microcontrollers

Let’s start by taking a closer look at the microcontroller chip. The chip has several pins, most of them input and output pins. The microcontroller uses these pins to interact with the outside world.

Atmel-microcontroller-pinout

However, a microcontroller doesn’t really do anything without getting any instructions. So to make it do something, you need to write a program and load the program onto the chip. This process is often called programming the microcontroller.

In the program, you use code to read from input pins, and to control output pins. By connecting something, such as a light-emitting diode (LED) to an output pin, you will be able to switch the light on and off from your program. If you connect a push-button to an input pin, you can use code to read the pin and see if the button is pushed or not.

Then, you can create code that turns the light on when the button is pushed, and turns the light off when it is not pushed. Not a very exciting example, I agree, but a very good place to get started. Think of it as the “Hello World” of microcontrollers.

We could easily turn this into a much more interesting application.

Connect a temperature sensor to an input pin instead of the button. And keep the LED on the output. Create a program that reads the temperature and if the temperature is above a certain level, start blinking the light.

Now, attach this to your beer, and a light will start flashing to warn you that your beer is getting warm. Now that’s useful!

Programming a Microcontroller

Okay, so how do we get from having this idea of what to make, into actually creating it? First of all, we have to create a circuit, then we need to program the microcontroller.

Creating the circuit is a matter of creating a schematic with the components we need, then turning this into a circuit board. I’ll show you how to do this later in this tutorial.

When you have your circuit ready, you need to program your microcontroller. I found this a bit confusing in the beginning. There are many ways of doing this, and not all methods work on all microcontrollers.

The steps you need to go through in order to get your program onto the microcontroller can be divided into the following:

1. Create program code
2. Compile the code into machine code
3. Upload the machine code onto your microcontroller

These steps will be different for different types of microcontrollers. When we get to the programming part of this tutorial, I will show you exactly how to do it for the microcontroller we choose.

But choosing a microcontroller can be a very overwhelming task, especially if you are just starting out. In the next part, I’ll show you what is going through my head when I choose a microcontroller – so that you’ll know how to choose one for your next project.

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

Video: Vegard Wollan addresses Internet of Things security

In this video segment from my interview with Vegard Wollan, the co-inventor of the AVR microcontroller, we explore in detail the security problems you need to address as an embedded designer.

Let’s face it, it is obvious that security is a way of thinking. You have to assume bad people are going to try and hack your products. With the oncoming revolution in the Internet of Things, it is important you design the security within, rather than try to tack something on after an exploit.

Vegard-Wollen_security-at-Atmel

The co-inventor of the AVR architecture notes that security is essential in embedded systems.

The key thing you have to know is that nothing beats hardware security. This is where the security system is implemented in silicon, storing a secret key, hash algorithms and random-number generator (RNG). Atmel makes both standalone security chips and incorporates the security circuits into some of our microcontrollers including Atmel | SMART ARM-based chips used for smart energy meters. The chips are more sophisticated than a simple IP block. In fact, there are extra layers of metal in the die so that hackers cannot probe the chip without ruining it. Many of the chips also dither the supply current, so a hacker cannot infer the code it is running by observing the tiny variations in supply current as it runs.

Atmel makes symmetrical security chips, where both the chip and the microcontroller code know the secret key, and also asymmetrical security chips, which work like that public and private keys systems you might be familiar with such as PGP and RSA security. And, note that you can uses Atmel’s tiny inexpensive security chips with any microcontroller, 8-bit, 16-bit or 32-bit, including all the micros made by Atmel’s honored competitors.

Interested in more? You can watch the entire 1:1 interview with Vegard here.