Skip to content

9. Embedded programming

Group Assignment

You can find our group assignment in this link.

For the group assignment I chose to try working on Arduino 101. At first I read about it in First steps with Arduino 101 & Arduino 101 guide

Performance & Architecture

Arduino 101 combine the ease-of-use of the classic boards with the latest technologies. The board recognises gestures, and features a six-axis accelerometer and gyroscope. A learning and development board that delivers the performance and low-power consumption of the Intel® Curie™ Module with the simplicity of Arduino at an entry-level price.
It keeps the same robust form factor and peripheral list of the UNO with the addition of onboard Bluetooth LE capabilities and a 6-axis accelerometer/gyro to help you easily expand your creativity into the connected world.

The module contains two tiny cores, an x86 (Quark) and a 32-bit ARC architecture core, both clocked at 32MHz. The Intel toolchain compiles your Arduino sketches optimally across both cores to accomplish the most demanding tasks.
The Real-Time Operating Systems (RTOS) and framework developed by Intel is open sourced.

The Arduino core communicates with the RTOS via static mailboxes to accomplish a predefined list of tasks (interface with PC using USB, program the sketch into flash, expose Bluetooth LE functionality to sketch, perform PWM).

The 101 comes with 14 digital input/output pins (of which 4 can be used as PWM outputs), 6 analog inputs, a USB connector for serial communication and sketch upload, a power jack, an ICSP header with SPI signals and I2C dedicated pins. The board operating voltage and I/O is 3.3V but all pins are protected against 5V overvoltage.
The Arduino 101 and the Genuino 101 boards have been designed in collaboration with Intel®.

Specicications:

  • Microcontroller: Intel Curie

  • Operating Voltage: 3.3V (5V tolerant I/O)

  • Input Voltage (recommended): 7-12V

  • Input Voltage (limit): 7-17V

  • Digital I/O Pins: 14 (of which 4 provide PWM output)

  • PWM Digital I/O Pins: 4

  • Analog Input Pins: 6

  • DC Current per I/O Pin: 20 mA

  • Flash Memory: 196 kB

  • SRAM: 24 kB

  • Clock Speed: 32MHz

  • LED_BUILTIN: 13

  • Features: Bluetooth LE, 6-axis accelerometer/gyro

Programming

I downloaded Arduino IDE from this link

Then, I added the Intel Curie Core to it. Selectd board type and port from Tools select the Board Arduino/Genuinio 101 and then the Port that is labeled with the same name.

a1

Went to File on the Arduino Software (IDE) and opened the Examples tree; selected 01. Basic and then Blink

Uploading the code to the board can be done by pressing the second round icon from left on the top bar of the Arduino Software (IDE) or press Ctrl+U or select the menu Sketch and then Upload.

Got an error at first, so I tried the IDE suggestion to click on Master reset button.

a2 a3

Blink code

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
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
}

Then, I tried the Fade code, but I needed to connect the Arduino board to breadboard. At first, it didn’t work because I didn’t connect the board in the right way but when I modified them, it worked.

Then I tried an example to fade an LED

a5

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Fade
*/

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

Then I tried to modify the code to use a different pin. I changed it to pin 5 & changed the connection to Arduino board & it worked.

a5

int led = 5;           // the PWM pin the LED is attached to

After that, I added one more LED & modified the code to make them fade at the same time. At first it didn’t work because of wrong connection but after doing some adjustment it worked.

a6

int led = 9;           // the PWM pin the LED is attached to
int led2 = 6;           // the PWM pin the LED2 is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 & 6 to be an output:
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9 & 6:
  analogWrite(led, brightness);
  analogWrite(led2, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

I tried to make LED sequencer by modifying this example

a8 a9 a12

sequence

int led = 9;           // the PWM pin the LED is attached to
int led2 = 10;           // the PWM pin the LED2 is attached to
int led3 = 12;           // the PWM pin the LED2 is attached to
void setup() {
   // declare pin 9 & 6 to be an output:
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

void loop() {
digitalWrite(led, HIGH);  
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  delay(300);      

  digitalWrite(led, LOW);  
  digitalWrite(led2, HIGH);
  digitalWrite(led3, LOW);
  delay(300); 

  digitalWrite(led, LOW);  
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);
  delay(300);

}

Then, tried to turns on the built-in LED when pressing the button.

a13 a14

/*
  Button

  Turns on and off a light emitting diode(LED) connected to digital pin 13,
  when pressing a pushbutton attached to pin 2.

  The circuit:
  - LED attached from pin 13 to ground
  - pushbutton attached to pin 2 from +5V
  - 10K resistor attached to pin 2 from ground

  - Note: on most Arduinos there is already an LED on the board
    attached to pin 13.

  created 2005
  by DojoDave <http://www.0j0.org>
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Modified the code a bit to make the LED flashes twice when the button is pressed

flashes

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // LED flashes:
    digitalWrite(ledPin, HIGH);
    delay(200);
    digitalWrite(ledPin, LOW);
    delay(200); 
    digitalWrite(ledPin, HIGH);
    delay(200); 


  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Programming my board

At first I had problems with programming using my programmer because it turned output that the programming was not successful. Therefore, I had to reprogram it. The steps are in this link.

Datasheet

There are lots of usefull information in the datasheet like it has 4KB program memory size. The following screenshot shows the Microcontroller pins configurations which will usefull to know for circuit design & programming.

d1

Also, this screenshot shows the operating voltage (1.8 – 5.5V), peripheral features like the 10-bit ADC (Analog to Digital Convertor) & PWM channels, & other information.

d2

I would like to know more about how to utilise the information in datasheet & get the most out of it & learn about the differences between different microcontrollers.

Also, the datasheet helped me in input week assignment. Since the accelorometer has a 3-axis with digital I2C & SPI interface. I had to check if Attiny44 supports it. I found that it has Digital Communication Peripherals:1-SPI, 1-I2C from this link. From datasheet: SCL: Two-wire mode Serial Clock for USI Two-wire mode.

d1 d2

The datasheet helped me in output week assignment. I have connected the motor the header where I connected the accelorometer & other times to the ISP header. I have connected the signal pin to PA6.

d1

The ATtiny processors allow you to generate an analogue output using Pulse Width Modulation (PWM). One or more counters in the chip allow you to generate a constant-frequency square wave and specify the proportion of the time it’s off and on.

Arduino

install the ATtiny support using the built-in boards manager.

Open the preferences dialog in the Arduino software. Find the “Additional Boards Manager URLs” field near the bottom of the dialog. Paste the following URL into the field (use a comma to separate it from any URLs you’ve already added): https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

a0

Click the OK button to save your updated preferences.

I have installed this repo that contains a set of “cores” which adds support for some members of the Atmel AVR ATtiny family of microcontroller like ATtiny 44 (14 pin) & ATtiny 84 (14 pin) to the Arduino IDE. By going to Tools> Board> Boards Manager & search for ATtiny & install it.

a15

Then ATtiny appeared in the “Tools > Board” menu.

I tried modifying previous code I used to program Arduino board to make it work on my board.

ar1

With these settings:

  • Board: “ATtiny24/44/84”

  • Processor: “ATtiny44”

  • Clock: “External 20 MHz”

ar2

However, without pressing the button the LED was on because my circuit design was made to give the pin power when the button is not pressed. So, I made some changes to the code to reverse the condition & it worked.

ar3 ar4 ar5

Tried different code for blinking program & it worked

const int buttonPin = PA3;     // the number of the pushbutton pin
const int ledPin =  PA7;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is LOW accourding to my circuit design:
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Made more modifications to make the LED blink four times when the button is pressed.

int theButton = PA3;
int theLED =  PA7;      

int buttonState = 0;         

void setup() {

  pinMode(theLED, OUTPUT);

  pinMode(theButton, INPUT);
}

void loop() {

  buttonState = digitalRead(theButton);

  if (buttonState == LOW) {
    for(int x=0;x<=3;x++){
    digitalWrite(theLED, HIGH);
    delay(300);
    digitalWrite(theLED, LOW);
    delay(300);
    }
  } else {
    // turn LED off:
    digitalWrite(theLED, LOW);
  }
}

Atmel

I tried programming using Atmel software using C language. I tried an LED blinking program. I have connect the AVRISP to my laptop and to my board headers. Then, Open Atmel Studio > New Project > click on GCC C Executable Project > choose the name and location > OK

at3

In the Device Selection window, Choose the device family ATtiny > ATtiny44 > OK. Ater that, writing this 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(2000);         // delay 2 s
        PORTA &= ~(1<<PA7);  // LED low
        _delay_ms(1000);         // delay 1 s
    }
}

Then, I clicked on the start icon & this screen showed up. I have selected AVRISP mkll & interface as ISP.

at4

Next, clicked on tools > device programming. Changed the settings to the following.

at5

Finally, clicked on program button.

at6

atmel