1.8 Embedded programming

The assigment:

Read a microcontroller datasheet and program it in several languages.


Hello Microcontroller / Atmel AVR ATtiny44A datasheet

A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. It is different from a microprocessor in that a microcontroller includes a CPU, a fixed amount of RAM, ROM and other peripherals all embedded on a single chip.

I am using the Atmel AVR ATtiny44A in the Electronics Design assignment and its datasheet is on this document (.pdf). There is a curious think about the real meaning of the AVR acronym, read on Wikipedia

There is a guide of the pins from the High-Low Tech Group at the Media Lab:

I also found really interesting this guide because explains in a simple way how microcontrollers work Beginning Embedded Electronics - 1 / Lecture 1 - Background and Power Supply

Ingredients

Physical stuff (Atoms)

  • Hello echo world 0.2 (Modified at Electronics Design)
  • USB TTL Serial Cable. 6 way, 0.1" pitch single inline connector
  • FabISP Fabable In-System-Programmer (made on Electronics Production)
  • 6-Pin DIL Ribbon Cable, 3 Inch
  • USB Mini-B Cable - 6 Foot
  • Digital stuff (Bits)

    Instructions to program in C using GNU Make and avrdude

    Steps

  • Step 0: Connect the physical components. Result: Circuit connected
  • It is necesary to conect all the components as indicated on the diagram.

  • Step 1: Configure the microcontroller to run at 20 MHz. Result: Microcontroller @20Mhz
  • Run the following command on the terminal: sudo make -f hello.ftdi.44.echo.c.make program-usbtiny-fuses

    Observation: In case you are using the AVR ISP mkII, then the command is sudo make -f hello.ftdi.44.echo.c.make program-avrisp2-fuses

    There is an error on the line 216 of the C source code, it must be added the const as on the image.

    The program will respond with a Fuses OK. Thats the signal that everything went fine. If not, check your board first.

  • Step 2: Program the microcontroller with the C code using the makefile. Result: Microcontroller programmed.
  • sudo make -f hello.ftdi.44.echo.c.make program-usbtiny if you are using the FabISP

    sudo make -f hello.ftdi.44.echo.c.make program-avrisp2 if you are using the AVR ISP mkII

  • Step 3: Open a serial monitor (in GNU/Linux there is a Serial port terminal or use the Arduino IDE). Configure the port connection to your USB port (in case of GNU/Linux could be /dev/ttyUSB0 or /dev/ttyACM0, check using: ls /dev/tty* on your terminal) and configure the baud rate to 115200. Result: Program ready to read the serial port
  • Step 4: Type some characters using the keyboard and over the serial monitor program (or the program you are using). Result: The microcontroller will reflex every character inputted.
  • Instructions to program the microcontroller with the Arduino IDE

    Steps

  • Step 0: Connect the physical components. Result: Circuit connected
  • It is necesary to conect all the components as indicated on the diagram.

  • Step 1: Install the ATtiny libraries for Arduino IDE previously downloaded from Github . Result: Arduino IDE capable of programming the ATtiny microcontroller
  • Inside your sketchbook folder create a new one called hardware and decompress all the content of the master.zip file:

  • Step 2: Set some parameters on your Arduino IDE. Result: IDE ready to program the microcontroller inside the circuit board.
  • Tools-->Board-->ATtiny44 (external 20Mhz)

    Tools-->Serial Port-->/dev/ttyUSB0 (Depends on your operating system, on GNU/Linux use ls /dev/tty* to discover your port list and select accordingly)

    Tools-->Programmer-->AVRISP mkII (depends on the ISP used)

  • Step 3: Load, verify and upload your source code from the Arduino IDE to the microcontroller's circuit board. Result: Source code loaded in the microcontroller.
  • In GNU/Linux, after you try to upload the code to the microcontroller sometimes is required some aditional activities.

    First create a rule inside /etc/udev/rules.d/, it can be named: 10-usbtinyisp.rules and is necesary to add this line only: SUBSYSTEM=="usb", ATTR{product}=="USBtiny", ATTR{idProduct}=="0c9f", ATTRS{idVendor}=="1781", MODE="0660", GROUP="dialout"

    After that, execute the following command on the terminal: sudo udevadm trigger (this forum provides more related information)

  • Step 3: Be sure that your source code was uploaded correctly from the Arduino IDE to the microcontroller's circuit board. Result: Source code loaded in the microcontroller.
  • The message area from the Arduino IDE will display: Done uploading.

    Done uploading message

    Because of the code loaded, every time the button is pushed, the LED will change it state from ON to OFF and viceversa.

    LED Off LED On

    Results:

    The board previously designed was programmed. The microcontroller now has a code inside that makes that every input read over the serial port will be returned to the computer using the same port.


    Inspirations from HTMAA

    Full visual journey

    Back to top