Embedded Programming | Week 09

Week Content

Learning after reading data-sheet
Any start with electronics can only done after reading datasheet. Each point is verly well explained. Its helps in understanding process and working of micro controller .

In Final project going to use in Satshakit in which its pin-out and design play very important role.
I can make small wearable sensor base toy which can be made through attiny controller.
I started with https://www.farnell.com/datasheets/1682209.pdf as this belong to Arduino. It was easy for me to understand.
Then after I understand it pins in details and how it can be used.







After understanding that you need to understand its uploading.
Check Tutorial for more in details



As Satsha kit is same as Arduino so below image was important to understand.
center
You can find many sub type in IC so its best to check datasheet and then design.
Rembering pins with connection to Arduino creates problem and mistake.
Avishek and Gautam Guided me and helped to find image explaining connection.


Basic Connection for uploading program by using Arduino as ISP
Attiny 44--Arduino UNO
VCC-- 5V
GND--GND
MISO--Pin12
MOSI--Pin11
SCK--Pin13
RST--Pin10


I have used the my LED board which I made in my week 7. In this board I have used 6 led's and two buttons. I have progrmmed in such a way that when we press one button, led's start glowing one after another and vice versa when we press other button. Basically I have made a counter of led's using two buttons.

I have used FAB ISP to Upload codes to my boards.
I have used my Design week Board and Uploaded Multiple LED Blink code into it.
Process of Uploading Code.
Do it Once to upload Bootloader.
You need to burn Bootloader once when you need to upload the code first time.
After that you just need to upload code with proper connection.
You need to select FAB ISP Atty tiny44
then connect MISO MOSI SLK and pins to to your board
You need to Upload program as Programmer. ( Sometimes only Upload don't Work


My CIrcuit Board.




Code for this Week Assignment


                   
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(10, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(0, HIGH);  
  delay(100);                     
  digitalWrite(0, LOW);   
  delay(100);     
  digitalWrite(1, HIGH);  
  delay(100);                     
  digitalWrite(1, LOW);   
  delay(100);  
  digitalWrite(2, HIGH);  
  delay(100);                     
  digitalWrite(2, LOW);   
  delay(100);  
  digitalWrite(3, HIGH);  
  delay(100);                     
  digitalWrite(3, LOW);   
  delay(100);  
  digitalWrite(7, HIGH);  
  delay(100);                     
  digitalWrite(7, LOW);   
  delay(100);   
  digitalWrite(10, HIGH);  
  delay(100);                     
  digitalWrite(10, LOW);   
  delay(100);                   
}
                 

Below are codes in Embedded Programing utilized for my Final Project


#include 
int newd = 0, oldd = 1;
Servo m1,m2;

void setup()
{
m1.attach(6);
m2.attach(5);
    Serial.begin(9600);
}

void loop()
{
  Serial.println(Serial.available());
   if(Serial.available() > 0  )
   {
      newd = Serial.read();
      Serial.println((char) newd);
      if( newd != oldd ){
        Serial.println("both are not same");
        if( newd == 'f' ){    
            m1.write( 180 );
            m2.write( 0 );
            Serial.println("moving..");
        }
        else if( newd == 'l' ){
                  m1.write( 0 );
                  m2.write( 0 );
                          Serial.println("Right");
        }      
        else if( newd == 'r' ){
                  m1.write( 180 );
                  m2.write( 180 );
                  Serial.println("Left");
        }
        else if( newd == 'd' ){    
            m1.write( 0 );
            m2.write( 180 );
            Serial.println("moving..");
        }
        oldd = newd;
      }
      //delay(10);         
   }
 }




	#include 
#include 
#include 
const int trigPin = 7;
const int echoPin = 8;

LiquidCrystal_PCF8574 lcd(0x3F);

int duration, distance, dirRotate =1,i;
  Servo m1,m2;
void setup()
{

  m1.attach( 9 );
  m2.attach( 10 );
 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT); 
  
  Serial.begin(115200);
  while (! Serial);
  Wire.begin();
  Wire.beginTransmission(0x3F);

  lcd.begin(16, 2);
}
int getDist(){
     
     digitalWrite(trigPin, LOW); 
     delayMicroseconds(2); 
    
     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10); 
     
     digitalWrite(trigPin, LOW);
     return (pulseIn(echoPin, HIGH) / 58.2);
     
  }
void loop()
{
    lcd.setBacklight(255);
    lcd.home(); 
          lcd.print( "Oh crap! i need" );
    distance = getDist();
    if(distance < 20 )
    {
      lcd.print( "Oh crap! i need" );
      lcd.setCursor(0,1);
      lcd.print( "to change my way" );
     
        if( dirRotate == 1 ){
              m1.writeMicroseconds(1000);
              m1.write(180);
             dirRotate = 0;
        }else{
          m2.writeMicroseconds(1000);
             m2.write(180);
             dirRotate = 1;
        }
       
        
    }else{
      lcd.clear();
      lcd.print("Moving fine :D");
      m1.write(0);
      m2.write(180);
    }
    
    delay(300);
}





	
	#include 
#include 

LiquidCrystal_PCF8574 lcd(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const int trigPin = 7;
const int echoPin = 8;

void setup()
{

  Serial.begin(115200);
   while (! Serial);
  Wire.begin();
  Wire.beginTransmission(0x27);

  lcd.begin(16, 2);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT); 
 
  Serial.println("LCD...");
}
int getDist(){
     
     digitalWrite(trigPin, LOW); 
     delayMicroseconds(2); 
    
     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10); 
     
     digitalWrite(trigPin, LOW);
     return (pulseIn(echoPin, HIGH) / 58.2);
     
  }
void loop()
{
   lcd.setBacklight(255);
    lcd.home(); lcd.clear();
    lcd.print( getDist() );
    lcd.print( " cm distance" );
    delay(300);
}


LED Circuit Files


^ Top