09. Embedded programming

This week’s assignment was to read a micro controller datasheet and programming the board with as many different languages and environments as possible to do a certain task.

Reading a Datasheet

What is a Datasheet of a microcontroller?

Datasheets are instruction manuals for electronic components. They explain exactly what a component does and how to use it.

Below is the datasheet of the ATTiny 24/44/84 microcontroller which is used in the board designed by me in the Electronics Design week.

Datasheet of ATTiny 24/44/84

Ref: Reading a datasheet

These are the most imporatnt things that need to be read and understood at this stage.

Since this document contains more than 280 pages, it is very difficult to remember or even refer to it. Luckily, there is a summarised version with all the important and more commonly used data of about 22 pages.

Summarised Datasheet of ATTiny 24/44/48

This summarised data sheet is divided in 10 sections:

  1. Features
  2. Pin Configurations
  3. Overview
  4. General Informations
  5. Register Summary
  6. Instruction Set Summary
  7. Ordering Information
  8. Packaging Information
  9. Errata
  10. Datasheet Revision History

All this information gave me a fair idea about the kind of projects I can use ATTiny in and what are the advantages and limitations of the chip.

Programming using ATMega328p

(Note: Do not use the Windows app as it gives an error while programming)

datasheet

datasheet

and find the ATTinycore by Spence Konde and install the latest version.
datasheet

(Note : Make sure you have the schematic of the board you’re programming on hand)

datasheet

Thi board diagram can be referred from below image:

datasheet

datasheet

datasheet

datasheet

datasheet

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(100);                       // wait for a second
digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
delay(100);                       // wait for a second
}
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
}

Programming the button

Below is the code for it, with explaination for what each line does.

#include <SoftwareSerial.h>   // Include the software serial library

SoftwareSerial mySerial(5,6); // Defining the RX, TX Pins
int led = 3;      // LED Pin
int bt = 2;       // Button Pin
int button = 0;   // Button variable

void setup()      // Initialize digital pin
{
mySerial.begin(9600);

pinMode(led, OUTPUT); 
pinMode(bt, INPUT);   // Defining Input and Output

}

void loop() // This function starts a never ending loop of functions
{
  button = digitalRead(bt);           // Initialize the reading of input
  mySerial.println("BT value : ");  // Prints 'BT Value'
  mySerial.println(button);         // Prints the value of BT
  if (button == HIGH)               // Sets the condition for output
    {
      digitalWrite(led,HIGH); // Function to perform if the condition is fulfilled
      delay(100);             // Sets delay
      digitalWrite(led,LOW);  // Function to perform if the condition is fulfilled
      delay(100);             // Sets delay
    }

}

The video

Progamming the button to toggle the LED On/Off

int stateNow = 0;
int stateBefore = 0;
int i = 0;
int j = 0;

void setup() 
{
pinMode (2, INPUT);
p inMode (3, OUTPUT);
}

void loop() 
{
stateNow = digitalRead(2);
if (stateNow != stateBefore) 
{
if (stateNow==HIGH and i==0) 
{
digitalWrite (3, HIGH);
j=1;
}

else if (stateNow==LOW and j==1) 
{
i=1;
}

else if (stateNow==HIGH and i==1) 
{
digitalWrite (3, LOW);
j=0;
}

else if (stateNow==LOW and j==0) 
{
i=0;
}

}
stateBefore=stateNow;
}

The Video

Thus, we’ve programmed the button on the board. We’ll move to adding more inputs and output in the boards and adding more complex programming.

All the files for this week are attached here

Group Work

The Group Assignment was to compare the performance and development workflows for other architectures. The group page can be found here