Home About Me Weekly Projects Final Project

Embedded Programing


COUNTDOWN





Embedded Programing





Assignments

For this week we had two assignment:



Individual Assignment

Before starting anything, I had to read the datasheet of the microcontroller I would be using so I can base my design accordingly. The one I was to use was the ATtiny44, the Datasheet would have a detailed explanation of all the components and possibilities of this microcontroller as well as the specs and dimensions that would be used in designing the PCB. It also explains the functions that it could handle and provide as well as some code examples. Also the limitations of the ATtiny44 are explained. Below are some of the information I want to highlight would be considered essentials for the task at hand.



For the individual Assignment I was only able to program my board using two languages, C-language and the Arduino. What I came to understand was that even the Arduino language is actually based on the C language. In the end all languages are translated into a binary code, it is a matter of which is more user friendly, and more efficient. I preferred the C language because it showed me what really is going on 'under the hood' and that actually makes understanding the languages much better, and learning new languages would make more sense.

As for my board, I originally designed the PCB to have a button and LED. Now with the programming I did it in a way where when the button is pressed once, the letter 'G' is flashed in morse code. And when the button is double clicked, the LED would flash 'FabAcademy' in morse code. Now this was with the Arduino code, I couldn't figure out how to do it with the C language so I just made it as when the button is pressed, 'FabAcademy' would be flashed in morse code.

It is true that Arduino code is much more simplified and more efficient in terms of development, but knowing the C language, not only will you be learning the basis of the Arduino language and how it is structured, but it might even give more freedom in terms of programming.




Programing with the Arduino:


  1. First we need to connect the Arduino to the PC
  2. Then we need to download the Microcontroller file in boad manager, (Attiny44) in this case.


  3. Arduino-PCB

  4. Then select the board the tool tab.


  5. Arduino-PCB

  6. Select which Attiny Processor. (Attiny 44)


  7. Arduino-PCB

  8. Select the Clock (Crystal SMD Frequency, 20 Mhz in this case)


  9. Arduino-PCB

  10. Now under tools, select Arduino as ISP in order to program our new PCB


  11. Arduino-PCB

  12. Now under examples, we need to upload the ISP code to the Arduino


  13. Arduino-PCB

  14. Now that the Arduino is serving as an ISP, it is time to connect our PCB to the Arduino
  15. Now under the tools tab, Burn Bootloader


  16. Arduino-PCB

  17. Now it is time to write the code on the Arduino IDEthat the the PCB is going to execute.



  18. int LED= 7; int BTN= 3; int ButtonState= 0; int ButtonCount= 0; int ButtonLast= 0; void setup() { // put your setup code here, to run once: pinMode (LED, OUTPUT); pinMode (BTN, INPUT); } void loop() { // put your main code here, to run repeatedly: ButtonState= digitalRead(BTN); if (ButtonState == HIGH) { delay(200); ButtonState= digitalRead(BTN); if (ButtonState == HIGH) { digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(300); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); }else if (ButtonState == LOW) {digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(300); digitalWrite (LED, LOW); delay(150); digitalWrite (LED, HIGH); delay(100); digitalWrite (LED, LOW); delay(150); } } }




  19. I have deigned this code to do two similar tasks based on the input. Since it is my first time programming an arduino I went with something simple and basic yet made the most out of it. Since I had one Button and one LED, I made the LED to flash different Morse codes.
  20. Then Check the Code and Upload it to the PCB through the Arduino Software


  21. Arduino-PCB

  22. Upload the code using the 'Upload using programmer' tool under 'Sketch'


  23. Arduino Upload

  24. Once everything is set you could just plug in the VCC and the GND and your PCB is ready







Programing with the C-Language:


  1. First we need to create the C-file, this code can either be written and uploaded through the Arduino, or could be written in a text file and uploaded through the FabISP through the terminal on Lynux where the latter is the case shown below
  2. There are 4 crucial files that are needed in every C-code program flashing and they are as follows
  3. Now you need to install the necessary libraries through the Lynux terminal and install them, shown below


  4. sudo abt-get install flex byacc bison gcc libusb-dev avrdude

    sudo apt-get install gcc-avr

    sudo apt-get install avr-libc

    sudo apt-get install libc6-dev

    libraries

  5. Next you need the MakeFile
  6. Next you need the Hex File
  7. Next you need the Out File
  8. And finally type in the command 'make program-usbtiny' and the program is uploaded onto the PCB


  9. makeprog



And these are the two languges and techniques I used to upload the program to my PCB.








Group Assignment



When it comes to comparing the performance and development workflow of the different approaches one can take to program a PCB, there are a lot of factors that should be taken into consideration. I cannot say for all but as for the ones I used here is my assessment and comparison:






Downloads



Make sure to open files using text

MakeFile


C code


Hex File


Out File


Python Code


Arduino Code


Make file source