Week 9 - Embedded programming

Week 9 - Embedded programming

home

Group assignment

compare the performance and development workflows for other architectures.

Here is a link to our lab's page which includes links to all our group assignments.

Assignment tasks for this week

Individual assignment: read a microcontroller data sheet program your board to do something, with as many different programming languages and programming environments as possible.

Assignment summary

what I achieved/learned this week:

Reading the microcontroller datasheet

Reading the microcontroller datasheet has been a sporadic process this week. It's certainly not been a 'cover to cover' exercise, but more of a 'dipping in and out' exercise. The main thing I've learned as I dip in and out is how much I don't know about these chips, but also about electronics in general. That said, every time I do look into it, I learn something new.

At first I was quite mistified about why certain capacitors and resistors were needed on the boards, the datasheet actually tells you what to include!

Firstly, with the ATmega16U4-32U4 microprocessor (used in my fab leo boards used in input-output weeks and in my final project), here are the key resistor/capacitor requirements/suggestions:

Adjusting LED brightness programme in Arduino

So the first basic test was to see if I could get the LED to change brightness, rather than simply turn on/off. This is a very straight forward process, where instead of pushing the output voltage to HIGH, you simply give the LED a scale value controlling the amount of PWM from 0 (always off) to 255 (always on), so e.g. 127 is half brightness. So I adjusted the programme having 1 second full on (255), 1 second half on (127), 1 second low (68), and 1 second off (0). The thinking here is that I can then use this to create a simple analagous programme to replicate a typical heating cycle I will need for my final project. Here's the code for the brightness adjusting programme.

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

// the loop function runs over and over again forever
void loop() {

  analogWrite(7, 255);   // turn the LED on full whack  
  delay(1000);                       // wait for a second
  analogWrite(7, 126);    // turn the LED on middle brightness
  delay(1000);                       // wait for a second
  analogWrite(7, 68);    // turn the LED on low brightness
  delay(1000);                       // wait for a second
  analogWrite(7, 0);    // turn the LED off
  delay(1000);                       // wait for a second
}

here is the LED fade.ino code to download

Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. Once the sketch has been saved, you need to make sure that the correct board is selected.

Then you need to make sure that the correct port (where your board is connected) is selected.

Creating an analogous curing cycle for my final project with a basic LED stepping programme in Arduino

Here is a typical pre-preg carbon fibre curing cycle that I want to replicate in my final project.

And here is the time-temperature data that I will use as input to show the analogy between time (mins) and temperature (deg C), using this as an analogy with time (milliseconds) and brightness (in the equivalent brightness scale.

Here is the code

/* 
  Blink with fade

  Turns an LED on in various levels of brightness which simulates the temperature of a curing cycle for a carbon fibre curing oven
  modified 17 March 2017
  by Derek Covill
  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  The original code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/
int temperature=0;
int timer=0;

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

// the loop function runs over and over again forever
void loop() {
  timer=0;
  delay(2000);                   // have a 2 second break before the cycle starts each time
  
while (timer<=50) {
  analogWrite(7, temperature);   // turn the LED on with the temperature/brightness increasing at 1deg/min (note we have equated 1min=1millisecond)
  timer=timer+5;
  temperature=temperature+5;
}
while (timer<=410) {
  analogWrite(7, temperature);   // turn the LED on with the temperature/brightness soaking at 70 degs for 6 hours. 
  timer=timer+5;
  }
while (timer<=435) {
  analogWrite(7, temperature);   // turn the LED on with the temperature/brightness  increasing at 2deg/min up to 120 deg C
  timer=timer+5;
  temperature=temperature+10;
}
while (timer<=495) {
  analogWrite(7, temperature);   // turn the LED on with the temperature/brightness soaking at 120 deg for 1 hour
  timer=timer+5;
}
while (timer<=555) {
  analogWrite(7, temperature);   // turn the LED on with the temperature/brightness decreasing at 1.67 degs per min
  timer=timer+5;
  temperature=temperature-(10/6*5);
}

}

here is the TEMP-step-calculation.ino code to download

And here's a video showing the programme working on a board that I made:

It's worth noting here that I did this input devices exercise using the board that I came back and redid this embedded programming exercise using the board that I made (and documented) in the input devices week.

Creating a basic LED flashing programme in Python

As part of our class activity we spend some time together using a Raspberry Pi to replicate the blinking LED programme. Here's the Raspberry pi setup with keyboard and mouse plugged into the USB ports and the monitor plugged in to the HDMI. The LED was plugged into the GPIO pin. Here's the setup.

And here's the code

Here was the very first test code we wrote, just to get the hang of the syntax and the structure, and the types of variables.

print ("happy birthday Luiz!")
name = "string vest" #note that "means a string by default"
boolean = True #could also False
integer = 9
floating = 3.2

print(name)
print("Hello "+ name)
print("Hello " + str(integer))

int(name)

here is the basic_first_programme.py to download

            

Creating basic LED flashing programme in C

Originally I set out to also try to code the same basic blinking LED programme using C, and got as far as finding this example set of code from ericevenchick on Github, but haven't got round to testing or adapting the code yet.

Back to top