Blog

Easy-to-use Atmel Studio project for Arduino + programming the Arduino from Python

Posted by on Sep 29, 2012 in Arduino, C++, Electronics, Programming | 3 comments

In this article you will find an example project for Atmel Studio that you can use with Arduino. I have also included two Python files to easily upload the code to your board.

+

Arduino, pro’s and con’s

There are many reasons to like the Arduino, to name a few:

  • Many libraries available and lots of example code on the web.
  • Uploading code to your board with one click
  • Portability of libraries
  • Integrated serial monitor

But there are also many things that drive seasoned programmers away from the Arduino environment:

  • The IDE has about as many features as Windows Notepad.
    • No auto-completion or any other assistance that modern IDE’s offer to let you program faster
    • No debugging
    • Very unhelpful error messages
    • No ability to jump to the line of the error
  • Although all Arduino files are open source, it’s almost impossible to jump into a file to see for example what digitalWrite() actually does. The Arduino documentation is very basic and doesn’t even link to the source files.

Basically Arduino is a collection of great libraries with a shitty IDE. So this article will tell you how to ditch the shitty IDE and still use the libraries.

Enter Atmel Studio

Atmel Studio, especially since version 6, is an awesome IDE. It has the Visual Studio 2010 shell, which is a joy to use. If you try it once, you will never move back to the Arduino IDE.

The reason I moved to Atmel Studio in the first place is that I wanted to use in-circuit-debugging: setting breakpoints on the device. Say you are debugging a rotary encoder that uses interrupts. The only thing the Arduino environment offers you is to write something to the serial port. With in-circuit-debugging, you can set a breakpoint in the interrupt, turn the encoder, and get the following information:

  • You can see the value of all your variables.
  • You can see all your registers: are the interrupts configured correctly? What triggered the interrupt?
  • You can step through your code line by line to see where it takes a wrong turn.

If you want to use in-circuit-debugging, you will need a debugger like the AVR Dragon. I also recommend to get the Arduino Leonardo, which has JTAG. It’s a lot faster than debugWire, which is the only option for all other Arduino’s.

My example project

The guides I have found on using Arduino’s with Atmel Studio all involve many steps and usually require manual editing of a makefile. I wanted to make things simpler and wanted to be able to use the toolchain settings in Atmel Studio. I am also using the avr-gcc toolchain that comes with Atmel Studio instead of the Arduino toolchain.

My example project is hosted on GitHub. You can download it with the ‘Clone in Windows’ button, or the ‘ZIP’ button.

I used the non-blocking example from my ShiftPWM library. If you don’t have the ShiftPWM library on your computer, you can get it here. Git it a try, it can give you up to 768 PWM outputs on one Arduino.

To get the project to compile on your computer, you only have to take the following steps:

  1. Open the solution file
  2. In the project properties –> AVR/GNU C++ Compiler –> Directories, change the 3 directories to your point to your local Arduino directory. Also add the path for any other libraries you are using
  3. If you are not using a 16MHz Arduino, change F_CPU under AVR/GNU C++ Compiler –> Symbols
  4. In ArduinoFunctions.cpp, uncomment/include any .cpp files that you are using from the Arduino directories.

That’s it.

Programming your Arduino with Python

One of the benefits of the Arduino environment is that you can compile and upload your program to your Arduino with one button click. If you are compiling your code Atmel Studio, you will have to use avrdude from the command line. This can be complicated.

To make it a easier for you, I have include two Python files. You only have to edit a few lines in this file to have one click uploading without the Arduino IDE. Well, two button presses: F7 to compile in Atmel Studio. And F7 again in Python/Sublime text to upload your code.

The Python script will automatically get the right settings for your Arduino from boards.txt, reset your Arduino and upload a hex file with avrdude.

And what about the serial monitor?

Allright, the one thing we will still use from the Arduino IDE is the serial window. You don’t have to have any files open, just click the serial monitor button to use Arduino’s serial window.

So there you have it, the best of both worlds: awesome libraries AND an awesome IDE.

ShiftPWM: Updated documentation and the shop is online!

Posted by on Aug 9, 2012 in Uncategorized | 0 comments

I finally finished building my web shop 🙂

From now on, you can buy ShiftPWM compatible LED driver boards from my web shop.

I also completely rewrote the documentation to include:

  • A calculator to estimate the interrupt load
  • A detailed function reference
  • Schematics for regular RGB LED’s
  • Schematics for high power LED’s
  • Schematics for LED strips

Next thing on the agenda is getting the matrix version up to par with the normal ShiftPWM library, so I can officially release it.

UberFridge, the first results are in!

Posted by on Feb 16, 2012 in Beer, UberFridge | 3 comments

It has been a while since I have published UberFridge and this update is long overdue. Now I’d like to finally share the first results with you and you can download my paper on UberFridge for a more scientific and condensed write-up of this project.  I have brewed two beers so far:

Hoppy Hefe:

  • 3kg Wheat Dry Extract (8,0 EBC)
  • 30,00 gm Hallertauer Perle [6,90%] (30 min) Hops 14,2 IBU
  • 30,00 gm Hallertauer Perle [6,90%] (15 min) Hops 9,2 IBU
  • 120,00 gm Hallertauer Hersbrucker [2,90%] (Dry Hop 5 days)
  • 1 Pkgs Weihenstephan Weizen (Wyeast Labs #3068) [Starter 1500 ml]

Hoppy Hefe fermented around 15 degrees. When fermentation started to slow down, I slowly raised the temperature to keep it going. The OG was 1.064 and the SG 1.014, which makes 6.5% ABV.

Hoppy Hefe was a bit of an experiment: a hefe with lots of hops. It tasted quite good, but the typical hefe flavors (banana, clove) didn’t mix well with the bitterness and freshness of the hops. The flavors blended better after 4 weeks bottle conditioning, which is quite long for a hefe.

Here are some pictures:

A healthy layer of krausen :)

Dry hopping with two 60g hop bags

Hopping Bock

  • 1.8kg Wheat Dry Extract (8,0 EBC)
  • 1.2kg Amber Dry Extract (18 EBC)
  • 60,00 gm Hallertauer Perle [6,90%] (15 min) Hops 20,8 IBU
  • 30,00 gm Hallertauer Perle [6,90%] (30 min) Hops 16,1 IBU
  • 1 teaspoon of Irish Moss
  • 1500 ml stir plate starter, from scooped off krausen from Hoppy Hefe
  • 1 Hoppy Hefe yeast cake

This weizenbock was delicious. It started at 1.090, dropped to 1044 in 2 days and finished at 1.023. The ABV was 8.9%. I fermented this beer at 17 degrees, and increased the temperature at the end to boost fermentation. Here is a graph of the temperature during fermentation:

 

Temperature profile for Hopping Bock

I don’t have a wort cooler yet, so I throw some sanitized 1.5L soda bottles filled with water in the freezer the day before I brew. When I have to cool the wort, I cut them open and drop the 1.5L ice cubes in the wort. The wort temperature was still a bit higher than I wanted, but UberFridge brought the temperature down quickly to 17 degrees.

When fermentation had stopped, I dropped the temperature to 15 degrees to let some of the yeast suspend. Close-ups of the temperature graph can be found in my UberFridge paper.

I really like the taste of Hopping Bock: it is very malty, a bit sweet and has a bit of banana and clove. I added a lot of yeast to this beer, but it is still sweet enough.

Here are some more pictures:

Ice Bottle ready to cool my wort

siphoning beer

Siphoning the wort from brew pot to fermentation bucket

Cheers!

Paper on UberFridge

More details on UberFridge (schematics, algorithms, results, etc.) can be found in my UberFridge Paper.

I still don’t have a name for my brewery and no inspiration either… If you have a suggestion, let me know!

 

Hardware fix for the F-lock key on my Microsoft Natural Ergonomic 4000 keyboard :)

Posted by on Jan 6, 2012 in Electronics, hacks | 7 comments

For some reason, Microsoft has equipped their keyboards with an annoying F-lock key. If you hit this key by accident, the F1-F12 keys change their function in things like Undo, Redo, New, Open, etc. Those are all actions that already have shortcuts.

The dreaded F-lock key

I think this keyboard is broken by design, so I decided to fix it. When I disable F-lock now, it is automatically re-enabled after 3 seconds by a little piece of hardware in the keyboard itself.

(more…)

UberFridge hardware and schematics

Posted by on Jan 4, 2012 in Arduino, Beer, Electronics, UberFridge | 40 comments

I have grouped all the circuits used in my UberFridge project in this article. Schematics, a board layout and pictures.

A top view of the electronics in UberFridge. My fridge has an on/off button on the top, which made it very easy to reroute it via a relay. The boards at the bottom were already in the fridge.

(more…)

Controlling fridge and beer temperature with a predictive on/off algorithm and PID

Posted by on Jan 4, 2012 in Arduino, Beer, C++, Electronics, Programming, UberFridge | 5 comments

UberFridge is capable of controlling the temperature of a fermenting beer with 0.1° C accuracy. It can also be set to keep the fridge temperature within a -0.5 to +0.5 °C range. How this is done in an energy efficient manner is explained in this article.

(more…)

How to build an electronics casing from an Ikea box lid

Posted by on Jan 4, 2012 in Electronics, UberFridge | 0 comments

The casing I ordered for my UberFridge project was to small too fit the OLED screen. Not wanting to wait on a new order, I went down to my basement to see what I had lying around. I came across a lid from a plywood PRÄNT Ikea box, which was perfect. In this article I’ll show the steps to transform the box lid into a custom size electronics casing.

(more…)

Programming my Arduino over WiFi

Posted by on Jan 2, 2012 in Arduino, Electronics, PHP, Programming, UberFridge | 8 comments

My Arduino is embedded in my fridge, so having to take it out every time I want to change something in the software would be very annoying. But luckily the Arduino is plugged into a router, which is running Linux.

I set out to get avrdude running on the router, so that I could upload new firmware to the router and have the router reprogram the Arduino. This article gives a step-by-step guide to set this up. (more…)

Getting my fridge to follow a temperature profile from a Google spreadsheet

Posted by on Jan 2, 2012 in JavaScript, PHP, Programming, Python, UberFridge | 0 comments

I wanted an easy way to set temperature profiles that my fermentation fridge would follow. This would enable me to:

  • Start a fermentation on a lower/higher temperature and gradually bring it to a normal fermentation temperature.
  • Slowly raise the temperature near the end of fermentation to boost attenuation

Google spreadsheets turned out to be a nice way to do this: (more…)