9. Embedded programming¶
Assignment
group assignment : compare the performance and development workflows for other architectures
individual assignment : read the data sheet for your microcontroller, use your programmer to program your board to do something
extra credit: try other programming languages and development environments
Board programing¶
Here is the board created a week before with LED and button. |
TinkerCad simulation ¶
TinkerCad can be used to draw circuits with cards like Arduino’s one and to simulate your program scribed with C/C++ or blocs. Here I can’t use my own card because it doesn’t exist in the TinkerCad library.
TinkerCad menu for circuits. |
LED and Button connected on an Arduino UNO with program scribed in C++/INO. |
LED and Button connected on an Arduino UNO with the same program than before scribed in C. Simulation in progress. You can see the LED is lighting. |
Program scribed in C :
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRB = 0b00010000; // the number of the LED pin
while (1) {
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (PINB & (1<<3)) {
// turn LED on:
PORTB = 0b00010000; // PORTX envoie du courant. PINX pour lire
} else {
// turn LED off:
PORTB = 0b00000000;
}
}
return(0);
}
Program scribed with Arduino library :
const int buttonPin = 3;
const int ledPin = 4;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Now I have two programs tested on computer.
Pushing program with Arduino ¶
I use Arduino application to push my program on the card I have built during week07. I use my own programmer I built during week05 to program this board.
Boards connections :
From left to right : programmer plugged on the computer, connected to the board with LED and button, connected to the computer for energy. |
How to push the program :
I open the program on Arduino application. I use to compile the program.
I have to click on Tools > Type of card
and select the micro controller I program and Tools > Port
to select the port connected with the card.
After that I use to send the program to the board.
Board programmed :
I also can use microship studio to do that :
Workflows comparison ¶
Comparison between program C and program Arduino ¶
Program scribed with C on arduino application. |
Program scribed with Arduino library on arduino application. |
Left : .hex generated by arduino from C program. Right : .hex generated by arduino from C++ program. |
C program transfered. |
Arduino program transfered. |
We can see that for the same result, program scribed with arduino’s language is heavier and it takes more time to transfer it.
Comparison between arduino and avrdude to generate .hex ¶
Comparison between two different microcontroller ¶
We choose to compare reaction between two micro programmed with the same program. We play on the bow and observed time between signal received and signal sent to the computer. We compare two cards : Arduino UNO and Arduino MEGA
We observe that signal go 4x faster with Arduino UNO than with Arduino MEGA.
(compare data sheet)