9. Embedded programming

Objectives of this week are:

1- To read the data sheet of the microcontroller ATtiny44.

2- To program our boards to do something, with as many different programming languages and programming environments as possible.

3- To work as group to compare the performance and development workflows for other architectures.

Group Assignment

We have started this week by working on the group assignment. There were many of microcontrollers/development boards available in the lab. To test as many as we can, each student has taken a specific circuit to work with. For me, I chose to work on Bluefruit nRF52832 Feather. This is because I have not worked with this module before, so learning about it throught this assignment will be a great outcome.

To get started with the module, I have visited the adafruit site. Through the site, I learned what this chip is, it features, pins and assembly methods. Then, to set-up and test the board, I have followed the instructions that are written in the site as well. Firstly, for the setup, I have installed the board support package in the Arduino IDE following these steps:

1- I deleted the old version of the Arduino IDE installed in my laptop and I downloaded the new one ARDUINO 1.8.9.

2- Next, I opened the IDE and added the Adafruit nRF52 package.

3- By clicking on the File > Preferences. This window will appear.

4- In the Additional Board Manager URL section I added this linked “https://www.adafruit.com/package_adafruit_index.json”.

5- Finally, from Tools > board > board manager, I installed the “Adafruit nRF52 by Adafruit”.

Moving to the next part which is testing, I tried to blink the LED that is located next to the USB port. This was a simple test just to check that my board is working. Here are th steps:

1- I plugged the board into my PC through the USB port.

2- From Tools > Boards, I chose my board to be “Adafruit Bluefruit nRF52832 Feather”.

3- I have updated the bootloader by clicking on the Tools > Burn Bootloader.

4- Then, port COM9 selected.

5- The Bootloader updated again.

6- Finally, I uploaded this code and the LED start blinking.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

To examine the functionalities of the board even further, I did another test called BLE UART: Controller Example. In this test I have used Bluefruit LE app to send some data to my nRF52 module. The example and the details of it also available in adafruit site. by following the instructions in the site I succeed in transferring data and here are the steps:

1- I downloaded the Adafruit Bluefruit LE Connect app in my phone.

2- I uploaded the controller example sketch in the Arduino IDE.

3- I opened the serial monitor by clicking on the following icon.

4- I changed the baud to 115200 to match what is written in the program (code).

5- Return back to the app, I connected it to the target “Bluefruit52”.

6- Then, I clicked on the controller > color picker.

7- I was choosing different colors, selected them, then the codes of those colors were appearing in the serial monitor of the Arduino IDE.

To view the full group assignment, check this link.

Individual assignment

I have started by reading the datasheet of ATtiny44. I found that it has the following features:

  • High Performance, Low Power AVR® 8-Bit Microcontroller
  • 4KB program memory size.
  • 32 x 8 General Purpose Working Registers (R0 to R31).
  • 256 Bytes of In-System Programmable EEPROM.
  • 256 Bytes of Internal SRAM.
  • 10-bit ADC (Analog to Digital Convertor)
  • Operating voltage of 1.8 – 5.5V.
  • 14 pins in total.

The complete datasheet is available here

Programming using FabISP & Arduino IDE.

I used the FabISP and Arduino IDE to program my echo-hello-world board. When we press on the button the LED turn on and when the button is not pressed, the LED turn off. Since I have connected my push button to ground, I have used the pull-up example from Arduino website. Here is the code and steps of programming.

1- Do the connection.

A- Connect the FabISP to your PC.

B- Using ribbon cable, connect the FabISP to echo-hello-world circuit headers.

C- Using FTDI cable connect the echo-hello-world circuit to your PC.

2- From tools, change the settings to the following.

3- Write the following code.

Code

void setup() {
  pinMode(PA3, INPUT_PULLUP); //button as input, connected to PA3
  pinMode(PA7, OUTPUT); //LED as output, connected to PA7
}

void loop() {
  //read the pushbutton value into a variable
  int sensorVal = digitalRead(PA3); //save the reading in the varibale called sensorVal
  if (sensorVal == HIGH) {
    digitalWrite(PA7, LOW); //LED is low (off)
  } else {
    digitalWrite(PA7, HIGH); //LED is high (on)
  }
}

4- Upload your code.

5- Your circuit is programmed!

Programming using AVRISP & Atmel atmel studio.

The second IDE I have used is Atmel Studio. I used Atmel Studio to blink the LED of my echo-hello-world circuit using c language. I found this site very helpful and I was following their steps.

1- Download Atmel Studio (The full package with all toolchain).

2- Connect the AVRISP to your PC and to your board headers.

3- Open Atmel Studio > New Project > click on GCC C Executable Project > choose the name and location > OK.

4- In the Device Selection window, Choose the device family ATtiny > ATtiny44 > OK.

5- In the main window, delete the example code and write the following code.

Code

#define F_CPU 20000000    // AVR clock frequency in Hz, used by util/delay.h
#include <avr/io.h>
#include <util/delay.h>

int main() {

    DDRA |= (1<<PA7);          // set LED pin to output
    while (1) {
        PORTA |= (1<<PA7);   // LED high
        _delay_ms(500);         // delay 500 ms
        PORTA &= ~(1<<PA7);  // LED low
        _delay_ms(1000);         // delay 1 s
    }
}

6- After that, from the toolbar click on build solution or press F7. You will get the following output.

7- Next, click on tools > device programming. Change the settings to the following.

8- You will see that your LED is blinking!