Week 8: Embedded Programming

Lecture Neil 16/03/2016

Tutorial Bas 18/03/2016 at FabLab Reykjavik

Assignment: read a microcontroller data sheet and program your board to do something with as many different programming languages and environments as possible.

 

Thumbnail Image 1

1

I have to say I was totally overwhelmed by all information we got to chew on this week. What I did understood was on the practical side we were going to focus on AVRs because they were designed from the ground up for modern compilers, and the GCC tool chain to compile programs to run on the AVRs, every instruction taking about 1 cycle.

Thumbnail Image 1

2

What I also understood is that Arduino code is C, the difference between working with the Arduino IDE and programming plain C being the use of extensive libraries instead of programming the few lines one might need from that library directly in C. Since the ATtiny series have limited amount of memory the latter of course is often better. We looked into the difference between an Arduino and ATtiny, for instance the bootloader that is already built-in in the Arduino's ATMega chip.

 

Thumbnail Image 1

3

As far as the ATtiny data sheet is concerned: we looked at lot of things during the instruction session, for instance at fuses (comparable to jumpers) and how to calculate settings with the help of this calculator. We also looked into the meaning of pull up in "pull up resistor", built in and software controlled in the AVR.

 

Thumbnail Image 1

4

When we started programming our controller (for which we used the ISP-board and the LED board we made in the previous weeks) it became more and more clear to me how to use a data sheet to look up pieces of information needed in the C code.

Thumbnail Image 1

5

For instance in line 192 and 193 the clock divider is set to 1.

 

Thumbnail Image 1

6

Information about this CLKPR (Clock Prescaler Register) can be found then in the data sheet in chapter 6.3.

 

Thumbnail Image 1

7

 

Apart from information needed to understand the controller in order to use and program it, there is also very practical information in the data sheet, like this information about different packages the ATtiny85 comes in and the Ordering Code (chapter 25.3) that suppliers like Farnell and DigiKey use in their ordering systems too. (Note that not all ATtiny types are available in all packages. For instance: the ATtiny85 is not available in TQFP package, I found out recently when trying to order these).

Thumbnail Image 1

8

Before we could start programming the board it had to be hooked up properly to the computer and the ISP programmer. How to do that was clearly visible in this document. The code we programmed our boards with was this hello.ftdi.44.echo.c code and how to do that was clearly described in the document too.

 

Thumbnail Image 1

9

If all was done properly, we should be able to get the desired result: text (plain ASCII) typed on the keyboard should be echoed back to the screen. To see this happen I used Coolterm. Important lesson learned: this doesn't work if you forget to put the baud rate for communication in the Connection Options on 115200 baud!

 

Thumbnail Image 1

 

10

Once this issue was corrected, I could conclude the board was properly programmed and the connections were properly set up, because when characters were typed on the keyboard first the LED flashed ....

Thumbnail Image 1

11

..... and then characters were echoed to the screen, The lights at the bottom of the Coolterm window allowed to follow the communication patters between the computer and the board, which I really enjoyed watching for some time. Last step was to change the code to make the behaviour of the board a little bit different. I used Notepad ++ to make the LED flash three times after receiving data and I changed "you typed" into the Dutch equivalent.

 

Thumbnail Image 1

 

12

As far as other programming environments are concerned, I looked at this page at the highlowtech.org website where it is explained how to use the Arduino board and the Arduino IDE for programming ATtiny controllers.

 

Thumbnail Image 1

13

For some soft circuits I made in the context of Fabricademy 2017 I used both the Arduino board and environment for programming ATtiny controllers. In the example above an ATtiny is used to make the heart of this handpuppet blink.

Thumbnail Image 1

14

One step further was to knit a resistor from conductive wool (never imagined this knitting technique I learned at kindergarten would come in handy when doing electronics so many decades later!) and use it as a stretch sensor.

 

Thumbnail Image 1

15

A programmed ATtiny was attached to this stretch sensor to control the effect of the stretching on the brightness of the LED. I showed the result in the review of the e-Textile classes. The video of my presentation (starting at 59:15) can be watched here.

 

FILES: All files of this week can be found here.

 
© Inger Le GuĂ©, Reykjavik 2016