Final project
 Project management
 Computer-aided design
 Computer-controlled cutting
 Electronics production
 3D scanning and printing
 Electronics design
 Molding and casting
 Embedded programming
 Computer-controlled machining
 Input devices
 Composites
 Interface and application programming
 Output devices
 Networking and communications
 Mechanical design, machine design
 Applications and implications
 Invention, intellectual property, and income
 Project development
 Final project presentations
 About me
 
    Embedded programming
   

Assignment
   read a microcontroller data sheet (ATtiny24A/44A).
   program your Hello button + led board to do something, with as many different programming languages and programming environments as possible.

1.- Programming in Arduino IDE

a.- Install the Software
We need install:
- Arduino IDE software. You can download here.
-  ATtiny Board Files. You can download here.
- FTDI Drivers. You can download here

Installing ATtiny support in Arduino
Locate your Arduino sketchbook folder File > Preferences menu




Create a new sub-folder called "hardware" in the sketchbook folder.
Copy the attiny folder from inside the attiny-master.zip to the hardware folder.
Start the Arduino development environment.
You should see ATtiny entries in the Tools > Board menu.





b.- Power and connect the boards

We need to provide power to the ATtiny, the FabISP(programmer) and connect them with each other.
Connect the 6-pin programming header in the FabISP and the LED-Button board with a cable
Connect the FabISP to the computer with an USB cable
Connect the LED + Button board to the computer with an FTDI cable.



c.- Burn the Bootloader

To burn the Bootloader go to Tools > Burn Bootloader menu.
This configures the fuse bits of the microcontroller so it runs at 8 MHz.
If you are sucessful, you will see this message.


d.- Modify the "Button" example

After open the Button sketch from the examples menu File > Examples > Digital > Button. I have change the pin numbers from the LED and the button because the pinouts on the ATtiny 44A microcontroller are not the same numbers that in the Arduino code.



Arduino pin numbers
buttonPin = 2
ledPin =  13

ATtiny 44A pin numbers
buttonPin = 3
ledPin =  7




I verified the code before I upload the sketch.



To upload the button sketch to the board, click the arrow button.



The led is glowing on the board and when I press the button the led turn off


Now I modified the code to detect when the button changes from off to on and on to off.
I count the number of button presses and I see if the number is odd or even.
If it is odd the led blinks, if it is even the led fade in and fade out.

Arduino code:

const int  buttonPin = 3;
const int ledPin = 7;      

int buttonPushCounter = 0;  
int buttonState = 0;    
int lastButtonState = 0;  
int brightness = 0;  
int fadeAmount = 5; 

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
}
}

lastButtonState = buttonState;

  if (buttonPushCounter <= 1) {  
digitalWrite(ledPin, LOW);   
}
else if (buttonPushCounter % 2 == 0) {
digitalWrite(ledPin, HIGH);  
delay(100);              
digitalWrite(ledPin, LOW);   
delay(100
}
else {
analogWrite(ledPin, brightness);   
brightness = brightness + fadeAmount;
delay(10);
if ( brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}    
delay(50);         
}
}

hello_led_4.ino

 




 

2.- Echo keyboard input using C

I followed this tutorial:
http://www.as220.org/fabacademy/tutorials/hello_echo_c.php

I used the serial monitor, in the Arduino IDE, to verify that the board was working.
The program stores the character you type and then echo to the serial monitor.
The program will store each character and repeat the series back to you each time.
When you get the maximum number of characters, the program overwrite the first values.


3.- Programming in C

Finally I decided to learn programming in C.
After reading this tutorial
I began to edit the blinkOnButton.c file by Travis Rich.

 After some changes I was able to turn on the LEDs when I pushed the button.

C code:

#define led_port PORTA
#define led_direction DDRA
#define led_pin (1 << PA7)
#define button_port PORTA
#define button_direction DDRA
#define button_pin (1 << PA3)
#define button_pins PINA

int main(void) {
clear(led_port, led_pin);
output(led_direction, led_pin);
clear(button_port, button_pin);
input(button_direction, button_pin);

while (1) {
if (0 != pin_test(button_pins,button_pin))
{
clear(led_port, led_pin); 
led_delay();
}
set(led_port, led_pin);
}
}
 


botonencender.c





 
   
   
Epifanio L. Cueva © 2013