Learning outcomes:


  1. Identify relevant information in a microcontroller datasheet.
  2. Implement programming protocols.

Stages:


  1. Reading the Datasheet
  2. Program the controller







This is the circuit i've used Atmega328 in it, Let's start programming.




Get an Arduino and connect it with the board, VCC connected to 5V and GND connected to GND.

Slave reset: 10
MOSI: 11
MISO: 12
SCK: 13



Connect 10uf capacitor to reset and GND to prevent the arduino from resetting after burnining the code(find the full details in the tutorial above)

Prepare my own board by burn on it the bootloader to be ready for programming




Importatnt:Make this step when you open a new and empty window of Arduino

Uploaded Arduino ISP code on the Arduino board to make it a programmer.





Then I've uploaded my code on board


#include 
#include 
#include 

#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"
#define trigpin 7
#define trigopin 8

TMRpcm tmrpcm;

void setup(){
  pinMode (trigpin,INPUT_PULLUP);
  pinMode (trigopin,INPUT_PULLUP);
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}


}
int flag=0;
int flag1=0;

void loop(){ 
  int sp;
  int sp1;
  sp=digitalRead(trigpin);
    sp1=digitalRead(trigopin);
      if (sp==LOW&&flag==0) {
     tmrpcm.setVolume(5);
tmrpcm.play("diags.wav");    
delay (5000);
flag=1;
  }
  else if (sp1==LOW&&flag1==0) {
     tmrpcm.setVolume(5);
tmrpcm.play("Africa.wav");
delay (5000);
flag1=1;
  }
  else if (sp==HIGH&&sp1==HIGH){
    flag=0;
    flag1=0;
    delay (500);
    }
  
  }


Now lets test it



Arduino code source



Let's try another programming enviroment


python



It was a good experience for me to try a new programming enviroments and how to deal with it, Where python is very user friendly language and east to learn it's principles.


I've started with this tutorial, It's simple and easy to follow and organized well to learn from


I will control the LED by sending a signal number.

Installing Pyserial Windows to handle and adding the libraries to python


First, i will write Python code on Python IDLE


Writing python code on python IDLE
From Run menu, First check the module then run module

This window will appear directly after running to send the signal through it like the Arduino serial monitor
By writing 1 or 0 the press Enter, you can control the LED

python code:


           import serial #Serial imported for Serial communication
import time #Required to use delay functions
 
ArduinoSerial = serial.Serial('com18',9600) #Create Serial port object called arduinoSerialData
time.sleep(2) #wait for 2 secounds for the communication to get established

print ArduinoSerial.readline() #read the serial data and print it as line
print ("Enter 1 to turn ON LED and 0 to turn OFF LED")

 
while 1: #Do this forever

    var = raw_input() #get input from user
    print "you entered", var #print the intput for confirmation
    
    if (var == '1'): #if the value is 1
        ArduinoSerial.write('1') #send 1
        print ("LED turned ON")
        time.sleep(1)
    
    if (var == '0'): #if the value is 0
        ArduinoSerial.write('0') #send 0
        print ("LED turned OFF")
        time.sleep(1)

	
           

Testing video:



Now the Arduino step and it's testing video that i've made to test the code before



Write the code first on Arduino and compile it (to make sure it's valid)
Done and it's valid

Uploading the code to the Arduino
Open Serial monitor

The message will appear and let's control the LED
Make sure you chose the right COM Number of your Arduino, and save it for late will need it in python code.

Arduino code

           	void setup() { 
  Serial.begin(9600); //initialize serial COM at 9600 baudrate
  pinMode(LED_BUILTIN, OUTPUT); //make the LED pin (13) as output
  digitalWrite (LED_BUILTIN, LOW);
  
  Serial.println("Hi!, I am Arduino");
}
 
void loop() {
while (Serial.available()){
  data = Serial.read();
}

if (data == '1')
digitalWrite (LED_BUILTIN, HIGH);

else if (data == '0')
digitalWrite (LED_BUILTIN, LOW);

}


           

Testing video:




Files:

Python code.py
Arduino code


Done

  1. Downloading and exploring datasheet
  2. Program the board.

New Learned

  1. How to read a datasheet and get any information out of it.
  2. How to program a microcontroller.
  3. Prepare a board for programming.

Enjoyed with

  1. Understanding the datasheet.
  2. Testing the board.