Week 9:

Embedded programming:

on week 7 I did my PCB with push button and LED and in this week , is the time to program it , so I started to read the datasheet and understand some staff, like the FTDI drive installation and the correct connection for it, by using this website digikey

by using this tutorial I figure out how should I set my options and connect the Arduino Pinout and learn some Arduino commands.
So I started to setup my Arduino software , file by choosing the board that I will use, and the attiny44 that I choose . after reading the microcontroller datasheet

I started to do all the setups that I need upon the tutorial .by choosing the chip that I will use and the programmer as shown on the pictures below:

after connecting my PCB to my laptop , I started with a basic program called Blink , so I can understand how the program and the commands is going , however after that I search in the Arduino website for some commands and statements that will help me with my desired program .

so after trying some commands and statements finally I found out exactly what I need , this are my statements and commands that I used to program my PCB :


  /*
    Button

    Turns on and off a light emitting diode(LED) connected to digital pin 13,
    when pressing a pushbutton attached to pin 2.

    The circuit:
    - LED attached from pin 13 to ground
    - pushbutton attached to pin 2 from +5V
    - 10K resistor attached to pin 2 from ground

    - Note: on most Arduinos there is already an LED on the board
      attached to pin 13.

    created 2005
    by DojoDave <http://www.0j0.org>
    modified 30 Aug 2011
    by Tom Igoe

    This example code is in the public domain.

    http://www.arduino.cc/en/Tutorial/Button
  ``
  http://www.arduino.cc/en/Tutorial/Button
*/
// modified by abdulla al hamad , i changed the pins according to my design .
// buttonpin is connected to pin 2
// ledpin is connected to pin 7
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin = 7;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an pull up input:
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
  // turn LED on:
  digitalWrite(ledPin, LOW);
} else {
  // turn LED off:
  digitalWrite(ledPin, HIGH);
}
}

So when I press the switch the LED will go on and if I press it again it will turn off.

ARDUBLOCK:

I tried ardublock as a different programming language , to see if it is easier and faster so first I download the java script , then i followed the instraction of installation from this website,after I did the installation I started to see some tutorial’s, however I choose BLINK tutorial to try .

So I opened the ARDUBLOCK by opening Arduino then go to tool menu > ARDUBLOCK .

After opening the ARDUBLOCK it is empty page and there are tools menu on the left side of the screen that will help to choose the features that I need , to do my program . however I started by opening a loop ,
and on the loop I choose to set the digital pin which is my LED from the Pins menu

after choosing the pin I typed the pin number that I will use , however from the UTILITIES menu I choose the delay.

However ever I used to pins so the LED will go on and off , and I set one of them on HIGH and the other on LOW . now my program is ready and I Uploaded to Arduino by pressing the Upload button .

IT was easy to deal with ARDUBLOCK , but from my side I prefer to use the normal coding , which I believe that it is helping me to understand my program more and I identify the errors easily.

PYTHON:

so as a second programming language I chose to try python , after I looked on some tutorials , I found that it is easy to understand , and some how it is similar to Arduino coding , However all what I did is to program my board to control the LED on or off , I used this tutorial , to understand the basic ,

first of all I had to download the python and pyserial

after downloading, I started to write my Arduino code to uploaded to my board , it is the same board that I used in my final project,

then I opened the python GUI to start putting my codes ,

it will open a window called shell , so I have to start I new file , to start writing as the following pictures:

I started to write the code that when I type 5 it means the LED off , and when I type 8 the LED will be on , however I choose COM11 as my serial port , it will allow it to communicate with my board through this serial , as shown :

so after finishing the code it is time to run the program , but first i should upload my Arduino code to the board , and read the serial , to make sure that the board is working .

so now I am sure that the board is working , so I will run the python program ,

you can see how is the program is running in this video :

My Files :

You will find my Arduino files on this Zip Folder You will find my PYTHON files on this Zip Folder