Microcontroller Tutorials and Tips
Microcontrollers made Simple
A bunch of resources, articles, tutorials and guides to get you up and running with your microcontroller projects. This site focusses on sharing my learning with other electronics hobbyists, makers, enthusiasts and (dare I say it) engineers. Welcome!
Toadstools and Caps
The Toadstool is a modular platform that lets you quickly and easily build microcontroller projects. It’s ideal for makers wanting to move beyond the Arduino ecosystem, or for experienced enthusiasts and professionals wanting to speed up prototyping. What makes it special?
- Includes microcontrollers from multiple manufacturers
- Small-form caps allow for quick connection of SPI/I2C/Serial modules
- Connects straight onto your breadboard
- More flexibility than you’re used to!
We’ve included some details and images from the first prototype, and are currently tightening up a few features before heading to the final prototype. What do you think?
Goodbye Arduino, Hello AVR
You’ve been using an Arduino for a couple of years, and are now hungry to expand your horizons. You feel like you know the Arduino UNO inside-out, and you want to start building custom projects that are more flexible and not restricted by the physical dimensions of the Arduino UNO. This series of articles in Nuts and Volts magazine take you on a journey from Arduino to AVR (using the ATmega328P), including:
- Building your own breadboard Arduino
- Moving onto an IDE with more features
- Working with digital I/O
- Using the Analaog Digital Converter to read analog inputs
- Serial communication over the UART
- Using Interrupts
A Bit More Detail
!Crash-Bang Prototyping was started off the back of our own learning, to help smooth our iterative development processes. We focus on the development of open source hardware kits and tools, and providing resources and value to electronics enthusiasts, hobbyists, and small startups.
Why Atmel and TI microcontrollers?
Out initial focus was on the Atmel series of AVR microcontrollers, as they’re a natural progression from the world of Arduino. We then continued to look for other good value MCUs and decided on the Texas Instruments’ MSP430 controllers – primarily because of their low-power claims and 16-bit architecture, but also as we felt they deserved more hobbyist attention given their Launchpad programme. Of course there are loads of other microcontrollers out there – almost too many to choose from – so we’ve put our stake in the ground and are working with these.
We believe that being open is best – open source, open to suggestion and input, and open with anyone who follows us. So please jump in with your feedback, input and suggestions.
How Ya Doin’
I am really interested in your Beyond Arduino articles. I purchased a FDTI, a Pocket Programmer (had trouble) and finally an Atmel ICE programmer. (You said you were going to buy one) I figured if you are going to use the Atmel 6 studio why not use one of their own programmers. They talk way over my head! I am going on to 68 years old and have little knowledge of using micro-controllers. Following your suggestion I realize programming AVR devices with less complicated programs would be a lot cheaper than using a BS2, Arduino Uno or a Parallax Propeller only using a small part of memory for what I want to do. There is little information about the ICE other than their setup which has a lot of acronyms which I can not understand so if it would be possible could you explain the setup (maybe on the Nuts and Volt forums so everybody could use it) so I can keep up.
Casey (My real name is Clayton but only my grandmother called me that) Johnson
Great to hear from you, pleased you’re enjoying the series. I like your suggestion – to be honest it took me a little time to get the Ice working myself, so I’m sure a number of readers would benefit!
Let me put my mind to it, and try to find some time.
Thanks for the feedback, please keep it coming – it’s really great to meet with people who are moving onto raw Microcontrollers.
I am in Uganda, Africa and has been following your articles (beyond arduino).
I wasn’t able to upload to my arduino using ftdi that you suggested.
I installed the ftdi drivers, and connected the recieve /transmit without
any problems. When uploading from arduino an error of STK500
appears, is it because of the current arduino version?
I expect you to cover projects on frequency meter on LCD, seven
segment displays -thermostat, while covering timers and interrupt
Welcome – good to meet a fellow African! I am based in South Africa.
I will contact you by e-mail as it will be easier to go through the troubleshooting steps.
All the best
Will be waiting
Hi Muhammed – that’s odd, I sent you a mail. Have re-sent; otherwise contact me at info(at)crash-bang(dot)com
Thanks for the advice on aploading through FTDI, I did go to “file ” then preference and checked the verbose out put, in the device manager the ftdi is given virtual port 6.
I still got the following error :
Avr dude :ser_recv ():programmer is not responding
Avr dude :stk 500 _recv ():programmer is not responding
Avr dude :stk 500 _getsync ()attempt 9 of 10 :not in sync :resp =0x01
Avr dude :send :0 [20 ]
I think this will be a tough one to troubleshoot using a comments page. Can you send me an e-mail?
I’d also recommend spending some time on Google – there are many people who have had this similar problem, and some ideas on how they solved it.
UART tutorial in nuts and volts
Hi Andrew, am sorry I have a lot of problems,
In your tutorial I use Avr studio 6.2, and the programmer I use is AVR isp mkii, whenever I program my Atmega 168, and use Hyperterminal for windows, I don’t get any thing on display.
After I have set same baud rate 9600, as in the code, and setting hardware option to none.
I also realized my fuse settings are set to divide by 8 by default, when I manually try to change it, it goes back.
I tried to use and set prescale to divide by 1, but hyperterminal then keeps writing garbage.
I also read Elliot’s make: Avr programing -he’s a good writer but put most of the functions in header files, it becomes difficult to follow, while you are doing the right thing by writing functions in the programs.
I request that when developing a topic, say Timer 0, try to start with simple code to turn on LEDs, then take us from there.
I request also in the future to use Mr. Fleury’s LCD library to run Hitachi hd44780 if possible, I downloaded it but can’t apply.
Thanks for all the comments and discussion. Perhaps check that your F_CPU is set to your correct clock speed – a simple way to check this is to use the _delay_ms function to blink an LED at, say, 5 second intervals – and then time it with an accurate watch.
If all the settings are correct, then suggest you check your FTDI drivers etc.
Elliot William’s book is a great resource – longer term I do recommend moving to using header files.
Thanks for the suggestion on examples in the articles, and on the LCD.
Hi Adrew thanks for the reply, I set my F_CPU to 16000000ul, but nothing over the hyperterminal.
The blink looks right but let me try timing and see.
Thank you very much for including me in your newsletter. Your site is one I check regularly because there is so much information to sift through. It is summer in Pennsylvania now so between the garden, cutting the grass (my wife makes me) and playing in my machine shop I am still working on last months article. There are a lot of acronyms in “C” so I have started a list to help me out. The simple (for you) program for temperature you asked us to write is still way over my head, but, if I study the programs and what you have written I know I will figure it out. I run around the house with the last three issues of Nuts and Volts rolled up underneath my arm. Keep up the good work.
Thanks Casey! Pleased you’re enjoying the articles. Should I do a step-by-step through the “challenge” project as I saw it, or should I leave it as a challenge?
Regarding your newsletter where you talked about pcbs layout programs, I left a exuberant note about finally drawing a schematic with KiCad under OS X. Now I’m not so sure.
Suggestion: Tell readers what platform you are using and what version of KiCad, and if any problems.
OS X is my preferred platform but the OS X versions of KiCad are “experimental” (although I can no longer find where this is stated). I should have noticed this when downloading but either did not or ignored it.
Going through an online tutorial using only a resistor and LED, and using a June 2015 version, I could draw a schematic but never save a file associating footprints with schematic symbols. Downloading and installing the latest nightly build solved that problem. But then trying to get a pcb resulted in a kernel crash.
Then tried the latest KiCad version on Windows 8.1 (like my Mac, I’m not seeing erratic or crashing behavior using Atmel Studio, Excel, Word, TeraTerm, …). Went through to generate a pcb and got a hard freeze, requiring a reboot.
So, no luck so far in generating even a trivial pcb with two components.
I may switch to the free version of Eagle and try in on OS X.
That’s extremely frustrating – and I feel responsible for wasting your time by not indicating that that KiCad is under active development. Your suggestion is a good one, and I’ve amended the post.
However, I’m surprised by your issues – they are fundamental, and given the active development they should have been resolved. I haven’t come across them before. You probably don’t feel like spending any more time on KiCad, but if you could report the issues you’re experiencing it will help the developers and other users: https://bugs.launchpad.net/kicad/+filebug
I’d also suggest you give it one final go on the forums if you have the inclination: https://forum.kicad.info/
I do hope you come right, it really is a good tool.
For the record, I never blame other people for the decisions I make; you are in no way responsible for my wasted time.
And, it was time well spent in successfully getting a schematic drawn and learning some things about a Cad program. I suspect that many of the Cad programs are quite similar in the way the user does things.
I don’t have Windows 7 so cannot try that. But I will give KiCad another shot on both OS X 10.10.4 (Yosemite) and Windows 10 later this month.
As an old guy who has hand soldered BIG components for years, I know I have to change and learn how to generate a pcb. But, also as an old guy, the learning curve is tough.
Please keep up the informative and interesting articles and newsletter. I appreciate a good source of information.
Andrew I’ve been following your articles on N&V and was encouraged to try my hand and step up from Arduino. I’ve installed Studio 6.2 (several times) and bought ‘ICE’. I can’t get programs such as Blink to load after successful compilation. My system is Windows 7 (with all upgrades), Norton Anti-Virus and Studio 6.2. I’ve reloaded Studio and WinDriver several times. Still the same error keeps coming up when I try to load the 168A. the message is:
Failed to launch program
Error: Failed to start programming session before chip erase with eeprom preserve:Failed to enter programming mode, ispEnterProgMode: Error status received: Got 0xcc, expected 0x00 (Unknown status message).
I’m stymied. I’ve tried everything I can think of and have been working on this for a month. any help would be greatly appreciated as I can’t find anything on many sites, including Atmel.
Please restart your projects with N&V.
Don B NH USA
Thanks for taking the time to flag the challenges you’re encountering – I’ve also experienced a few bumps with the ICE. Can I drop you a mail in the next day with some thoughts, as I find it easier to troubleshoot over mail. We can then post a solution back for others to learn from.
I wanted to post this message telling everyone that you solved my problem as stated above. And in less than 24 hours of my original post. The answer lies in http://www.avrfreaks.net/forum/unable-isp-program-attiny48-atmel-studio-62-start-without-debugging-atmel-ice and http://www.avrfreaks.net/forum/avrisp-mkii-atmel-studio-another-problem-isp-clock-speed as emailed by you. Everything is great now ! Thank you !!!!! Please hurry back to N&V
How Ya Doin’
I just downloaded, saved and printed out my free cheat sheet. What a wonderful idea you have come up with! I printed out a copy of the one in the datasheet, but every time I look at it I get a headache. Yours has nice little blocks evenly spaced and is even color coordinated. You even have color coordinated explanations in boxes that give meanings to the acronyms.
It is still summer here and between the garden, my wife’s habit of wanting the grass cut and the hedges trimmed and rebuilding the snowblower for the front of the wheel horse ( Does it snow down there? ) I have fallen behind with your instructions, but I will not quit. Keep up the good work.
That’s awesome – I’m really pleased that you found it helpful! Thanks for letting me know – I use it all the time (although I did jazz it up a little before uploading).
I’m sorry to hear that the garden and weather has taken you away from your experimentation with microcontrollers – perhaps find an application that helps with the garden – that’s how my irrigation controller was born!
Good luck carrying on with the learnings – the nice thing about a magazine in your hand is that it’s always going to be there when you’re ready for the next edition.
Cheers from a sunny South Africa (where we never see “real” snow)
I also think the Atmega cheat sheet is outstanding.
Excellent – thanks so much Don! Pleased my efforts were worth it!
I am enjoying your articles as each builds on the prior one. I had no problems with the FTDI buiid of the blink.c program. I acquired the Pololu AVR Programmer and have been able to get successful compile, load, flash and verify using Atmel Studio 7.0. The Pololu leds (3 of them) all indicate a successful transfer. However, the led on pin 14 does not flash. I have checked and rechecked the electronics including all appropriate voltages. Pololu tech support told me that the AVRdude.exe external code was not necessary. I realize that it is tough to troubleshoot remotely, but I am out of ideas.
Thanks for the comment – pleased you’re enjoying the articles!
I haven’t used this programmer before – it looks like it emulates the STK500, so should work without AVRDude as Atmel Studio supports the STK500. If the code is uploaded and verified correctly, then I must admit I’m also a little confused – if I were to troubleshoot I’d:
1. check the LED lights up if you connect it directly to the power source
2. try an alternative pin
3. Test with another ATmega328 chip
4. test the connectivity on all the jumpers/breadboard connections (I’ve had bad connections in the past that tripped me up)
The AREF pin shouldn’t affect this project – only really if using the ADC. Do you power your project using the programmer or from a separate source? Try disconnecting the programmer.
As you say, it’s tough to troubleshoot remotely – so I don’t think I’ve been able to help much. Good luck, and let me know how it turns out!
I have gone through your list and have tried three different ATMega 328P chips. I switched to pin PB1 and put a more powerful WART on for more power. The code listin is shown below.
Once again, I’m out of ideas.
* Beyond Arduino 2 – 1 Blink.c
* Nuts & Volts – Beyond Arduino #2
* Blinks an LED on PB0, illustrating register
* usage and bitwise operations
* Author: Andrew Retallack
#define F_CPU 16000000UL //Clock running at 16MHz. Need to define this prior to including “delay.h”
#include //Standard support for AVR I/O registers
#include //Library to handle delays
DDRB = DDRB | (1<<DDB1); //Set PB0 as output – same as pinMode(x, OUTPUT)
//Turn LED on
PORTB = PORTB | (1<<1); //Set PB1 high – same as digitalWrite(x, HIGH)
_delay_ms(1000); //Delay for 1 second – same as delay(1000)
//Turn LED off
PORTB = PORTB & (~ (1<<1)); //Set PB1 low – same as digitalWrite(x, LOW)
_delay_ms(1000); //Delay for 1 second – same as delay(1000)
I slowed the clock speed down to get a good device ID read and checked the configuration. In your article, you say to connect power after disconnecting the AVR Programmer. We obviously have power to get the code to load, so I have been disconnecting and reconnecting after disconnecting the AVR Programmer. Anything wrong here?
I see that I made an error and changed the code to set port PB! as output as follows:
DDRB = DDRB | 0b00000010; //Set PB1 as output – same as pinMode(x, OUTPUT)
With this changed, it compiled and everything seemed to work except that the led still does not blink. I did fine that one of the 22 pf capacitors on the crystal was out of tolerance and changed it before the last test. No change in the result.
Apologies a bit slow on picking up on your comments. I’ll pop you a mail as it may be easier to troubleshoot that way – attachments etc.
The only discrepancy that I found was while the circuit picture and schematic called for a +5 volt on the AREF port, the ATMEL Studio Component slider showed it at 0 volts. When I tried to slide it above 0 it automatically returned to zero.
I replied to a comment on T&L Publications and wonder what you think:
How Ya Doin’
I used the Toadstool and the ICE programmer. (328P)
I have a cheap Radio Shack multi-meter so here is what I got.
Readings at 5 volts:
0- 40 mA (average because meter moved from 38 to 42)
1- 36 mA (average for around the same reason)
2- 21.46 (correct reading I suppose because meter staid at same reading)
4- Read Below
Readings at 3.3 volts:
0- 24 mA (average)
1- 23 mA (average)
I also started out with a new 9 volt battery. My old one failed half way through the experiments. My readings are a little higher than yours Agg, maybe Andrew can explain why.
Thanks so much for letting me know – have posted a response.
Having read thiѕ I thought it was really enlightening. I apprecіate you spending
ѕome time and effort to put thiѕ article togetɦer. I once aǥain find myself personally spending way too much tіme
both reading and lᥱaving commentѕ. But so what, it was still worthwhile!
In your sixth Beyond article are you using Eagle for your schematics? If so how does one find the MCP7940 part? I’m new to Eagle because Fritzing wasn’t doing it for me. Soon, maybe, I’ll have an OSHPark contribution to make based on your work. Thanks again for the series. I continue to explore them for skills development. Really well written.
Thanks for the kind words – pleased you enjoy the series, I actually used KiCad which I prefer to Eagle for a number reasons – take a read of http://www.crash-bang.com/how-to-choose-a-pcb-design-tool/ where I explained these – things have moved on since the article 18 months ago of course.
I couldn’t find an existing MCP7940 part, so used a standard 8-pin part with the right footprint and modified it – it takes a little time to get your head around, but is a useful skill if you want to carry on with any CAD tool – there are many parts that aren’t in the standard libraries. Of course you could also search for a part on the internet, but then your schematics start not to look standard as each part is designed by different people with different standards – comes down to how pedantic you are 🙂
Thanks, Andrew. I will spin up KiCad and give it a go next time. I did use Eagle and did as you said by using a standard part to make my own MCP7940 package. It worked! The good folks at OSHPark sent me the boards. After soldering, it all worked! I did get the silkscreen for the LM34/35 upside down, however. Boy, they get hot if wired in reverse!
Now I’m off to convert your NV series to work with the newer Atmega328PB chip and spending lots of time in both the PB and P datasheets. (For your blog followers, a PB upgrade requires, at a minimum, the insertion of a zero for TWI registers, i.e. TWBR becomes TWBR0.) I’m still fighting the TW_STATUS definition, however. Your NV articles have been a tremendous aid and have been a constant companion for the last year and a half. Thanks again for writing these.
The book “Getting Started in 3 Easy Steps” is very helpful. I was expecting a repeat of some of the Nuts Volts articles. Matter of fact, I wish I read this before the NV articles for the review of hardware and IDE’s. Soon I hope to engage the resources mentioned in the closing chapter. The price for the on-line book is deceiving as it doesn’t come close to the high value of the content. Hopefully folks contribute more than the ‘minimum’ price in support of your advocacy for MCU education. I did.
**** Edited ****
The book “Getting Started in 3 Easy Steps” is very helpful. I was expecting a repeat of some of the Nuts Volts articles – but there was none. Matter of fact, I wish I read this before the NV articles for the review of hardware and IDE’s. Soon I hope to engage the resources mentioned in the closing chapter. The price for the on-line book is deceiving as it doesn’t come close to the high value of the content. Hopefully folks contribute more than the ‘minimum’ price in support of your advocacy for MCU education. I did.