Showing posts sorted by relevance for query arduino-interrupt. Sort by date Show all posts
Showing posts sorted by relevance for query arduino-interrupt. Sort by date Show all posts

Sunday 1 December 2013

MENERIMA DATA DARI UART DENGAN SISTEM INTERUPSI

SEMANGAT PAGI sobat Blogger, pada kesempatan ini saya akan berbagi lagi nih, cara MENERIMA DATA DARI UART DENGAN SISTEM INTERUPSI. Cara kerja nya sama seperti SISTEM POOLING yaitu menerima data yang di berikan Arduino IDE kepada LCD penerima, TETAPI pada percobaan ini kita akan menggunakan SISTEM INTERUPSI bukan POOLING. Penerima data akan menggunakan BAUDRATE 9600. AYO SIMAK langkah-langkah di bawah ini :
  1. Seperti biasa, sebelum melakukan percobaannya kita harus membuat rangkaiannya. Rangkaian yang harus di buat seperti di bawah ini.
  2. Mari lakukan coding program dengan menggunakan sintaks program di bawah ini.


  3. Setelah selesai, Ayo buka Serial Monitor pada IDE dengan cara Ctrl + M. Pastikan konfigurasi Serial Monitornya Seperti tampilan di bawah ini.
  4. Contoh data yang dikirim IDE dan yang di terima di LCD penerima
  • Teks Yang DikirimkanArduino
    Teks Yang Di TerimaLCD
    Halo
    Halo
    SayaMakanNasi
    SayaMakanNasi
    Hasmar
    Hasmar

    Husein
    Husein
    Harahap
    Harahap
Adapun penjelasan sintaks pemograman di atas adalah sebagai berikut :
  • #include <LiquidCrystal.h>    //memanggil library untuklcd
    #define FOSC 16000000         //menetapkannilai FOSC bernilai 16000000
    LiquidCrystallcd(2, 3, 4, 5, 6, 7); // inisialisasi pin lcd
    String dataSerial;                    //mendekelarasikandataSerialsebagai string
    voidinitSerial(intbaudrate)
    {
    intubrr = FOSC/16/baudrate-1;
    // Mengisi register UBRR0H dan UBRR0L untukmenentukanbaudrate
    UBRR0H |= ubrr>>8;
    UBRR0L |= ubrr;
    // Mengaktifkansaluran transmitter dan receiver
    UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
    // Menggunakan format data 8 bit
    UCSR0C |= (0<<UCSZ02)|(1<<UCSZ01)|(1<<UCSZ00);
    // Menggunakan 1 stop bit
    UCSR0C |= (0<<USBS0);
    // No Parity
    UCSR0C |= (0<<UPM01)|(0<<UPM00);
    // Mengaktifkan RX interrupt
    UCSR0B |= (1<<RXCIE0);
    }
    // Rutin yang akandijalankanjikaterjadiinterupsi
    ISR(USART_RX_vect){
    char data = UDR0;
    if(data=='\n')
    {
    lcd.clear();                   // tampilanlcd di hapus
    lcd.setCursor(0,0);      //Menampilkan text padabarispertama LCD
    lcd.print("Incoming Data"); //Menampilkan text “Incoming Data” padabarispertama di LCD
    lcd.setCursor(0,1);      //Menampilkan text padabariskedua LCD
    lcd.print(dataSerial);   //Menampilkan data ygdikirimmelalui serial
    dataSerial = "";
    }
    Else
    {         
    if(data!='\r')                 //jika data tidakada
    {
    dataSerial += data;      //Jikatidakada data makatampilkan text “data”
    }
    }
    }
    void setup()                 //settinganawal program
    {
    initSerial(9600);
    lcd.begin(16,2);           // tampilanlcd (kolom , baris)
    lcd.clear();                   // tampilanlcd di hapus
    sei();
    }
    void loop()                  //program looping
    {
    }

    • Perbedaan antara INTERUPSI dengan POOLING adalah Suatu kondisi yang memicu atau memaksa sitem mikrokontroler untuk menghentikan program utama dan memaksa menjalankan interupsi, SEDANGKAN sitem POOLING adalah kondisi arduino menunggu pengiriman data dari komunikasi serial.


Wednesday 21 October 2015

PROPELLER :: PROPELLER(ROTATING) LED DISPLAY





People often use ARDUINO platforms and other microcontrollers (pic, avr ) for making a propeller led display. If you are from a rural area like me it will be a little difficult to have such good hardware.I am trying to make one using AT89S52 microcontroller (which is very cheep).

i'm using a 11.0592MHz crystal and a 7805 for power supply leds are connected to the PORT0 of the MCU. 8 LED's are used for displaying letters. I used 7 red and 1 blue led to make it look good. you can connect LEDs to the microcontroller in two ways
  1. ACTIVE HIGH (logic '1' on MCU pin will make the LED glow)
  2. ACTIVE LOW (logic '0' on MCU pin will make the LED glow)

It is better to connect the leds in active low configuration(cathode to MCU pin and anode to Vcc through 220ohm resister for current limiting.

The whole arrangement is placed in a wheel using foam plaster so the it sticks on both sides
the wheel is attached to 6mm shaft and 1000RPM metal gare motor.




Keep the arrangement as strong as possible. So that it won't fall out of the high speed rotating platform.Try to make it stable to suppress the vibrations at high speed. I attached the 9V battery using a tape to the circuit board of MCU .It means  I am using "ON BOARD" power supply.

I arranged the LEDs on a separate PCB and connected them to the pinheads and an eight pin female connector is used to connect the 8 LEDs to connect to PORT0 of AT89S52.

I used the KIEL software to program the microcontroller. i prefer to work with C rather than assembly. I am using a USB based programmer to burn the AT89S52 MCU.

 try to make your code flexible so that you can easily modify to display any word
at first every thing was a bit messy
watch the video


   
        looks nice is isn't it.
I'm trying to make a single stand still display. calculation of proper delay is very important in making this project.because speed of  any two motors is not equal.calculate delay as per your motor.motor speed should not be less than 1000.

 for displaying each letter make a standard notation.I'm following 5*7 notation



if your motor is rotating in clock wise direction then the corresponding code will be as follows.
 leds are connected to PORT0 of AT89S52 so the logic will be
                P0=0x81; delay( );//define this function as per your motor
P0=0x6f;  delay( ); 
 P0=0x6f;  delay( );
 P0=0x6f;  delay( );
   P0=0x81;  delay( ); 
                              P0=0xff;  delay( );// to make one column gap between letters 
if it is anti clock wise then
same code in the reverse order
in this example im using the letter "A" which is symetrical
for other letters you need to follow from down to top of the code algorithm discussed above
                                                               P0=0xff;    delay( );// to make one column gap between letters
P0=0x81;  delay( ); 
P0=0x6f;  delay( );  
P0=0x6f;  delay( ); 
P0=0x6f;  delay( ); 
P0=0x81;  delay( );
similarly for active high the following notation must be followed
  so the code will be:

led=0x7e;delay();
led=0x90;delay();
led=0x90;delay();
led=0x90;delay();
led=0x7e;delay();
                                            led=0x00;delay();column gap betwwn 2 letters
so that you can display any word on your moving display

but the question is how much delay we need to use after each and every colum
follow theses calculations..
DELAY CALCULATIONS 
motor speed===1000 RPM
time for one rotation===60 milli seconds
radious =30cm
peremeter=2*3.414*30=204.84~205
width of led column=0.5cm ( this indicated the duration of led glow in terms of length of display)
total num of columns(leds)=205/0.5=410
410 leds=60 milli seconds
one led(column)time=146 micro seconds// 
columns for each letter=6
time for a letter=6*146=876 micro seconds
length for letter=6*0.5=3
total leters=205/3=68
THE CALCULATIONS VARIES ACCORDING  TO THE GLOW TIME OF LED AND RADIUS OF THE ROTATING ARM 
motor speed===1000 RPM
time for one rotation===60 milli seconds
radius =30cm
peremeter=2*3.414*30=204.84~205
width of led column=1cm( this indicated the duration of led glow in terms of length of display)
total num of columns(leds)=205
205 leds=60 milli seconds
one led(column)time=292 micro seconds
columns for each letter=6
time for a letter=6*292=1752 micro seconds
length for letter=6
total leters=205/6=34
THESE ARE ROUGH CALCULATIONS BECAUSE THE MOTOR SPEED IS NOT ALWAYS CONSTANT 
BUT THEY HELP IN APROXIMATING THE DELAY



 if you are a bit good at it
TRY WITH  "RGB" LEDS
ALL THE BEST   
EXAMPLE PROGRAM     
circuit diagram using 8051 
//THIS PROGRAM IS FOR 8051
// in this code i did not used lookup tables for reducing the complexity                                                      
// i just gave code logic for one letter'A' and space ' '                                                                               

#include<reg51.h> 

                                                                                                                            
#define led P0 //port0 will be connected to leds 
                                 
unsigned int del=50//variable to control delay
                                                                                           
void delay(void)
{
 unsigned int i,j;
for(i=0;i<del;i++)
for(j=0;j<1275;j++);

}
void display(unsigned char car); // declaration of a function 

void main()
{
 while(1)
{
  display('A'); // this displays a continious rotating"A  A  A  A"
  display(' '); 
//try to change the del value as per your motor until you get a perfect
//display once you got it then write your code for remaining letters 
//once you did this it will be very easy you can do your own fonts
//like "smily" ,"heart" etc 
//but the main logic is to achieve perfect "delay".once if you refer to the
 //delay calculations you will get it
//direction of rotation is also one important thing(clock wise or anti clock) 
// this "A" is simetrical so works on both directions.
}

}

void display(car)
{
  
  switch(car)

  case 'A' : // letter A
   
   {
    led=0x81;  delay( ); 

    led=0x6f;  delay( );  

    led=0x6f;  delay( ); 

    led=0x6f;  delay( ); 

    led=0x81;  delay( ); 

    led=0xff;  delay( );// to make one column gap between letters  
   } 
    break;
  
   case ' '  : // space
   
   {
    led=0xff;  delay( );

    led=0xff;  delay( ); 

    led=0xff;  delay( );  

    led=0xff;  delay( ); 

    led=0xff;  delay( ); 

    led=0xff;  delay( ); 
    
    led=0xff;  delay( );// to make one column gap between letters 
  
   } break;
  default:
   led=0xfe;
}
// END of program

=======================================================================================



                                             //THIS PROGRAM IS FOR AVR

// in this code i did not used lookup tables for reducing the complexity                                                      
// i just gave code logic for one letter'A' and sapace ' '                                                                              

#include<avr/io.h> 
#define F_CPU 8000000 // crystal frequency used in the circuit this helps in calibration of delay as per your frequency 
#include<util/delay.h> header file for generating delay for
                                                                                                                            
 DDRD=0xff;     //declaring portD as out put  
 #define led PORTD   // the word "led" will be replaced by PORTD at compile time                                                                       
unsigned int del=50 //variable to control delay
                                                                                          

//the delay function is ther as default in util package of winavr so use:  _delay_us( );
void delay(void)
{
 _delay_us(del);
 _delay_us(del);
 _delay_us(del);
 _delay_us(del);
}
 //remaining logic will be same for all microcontroller units

void display(unsigned char car);

void main()
{
 while(1)
{
  display('A'); // this displays a continious rotating"A  A  A  A"
  display(' ');
//try to change the del value as per your motor until you get a perfect
//display once you got it then write your code for remaining letters
//once you did this it will be very easy you can do your own fonts
//like "smily" ,"heart" etc
//but the main logic is to achieve perfect "delay".once if you refer to the
 //delay calculations you will get it
//direction of rotation is also one important thing(clock wise or anti clock)
// this "A" is simetrical so works on both directions.
}

}

void display(car)
{

  switch(car)

  case 'A' : // letter A
  
   {
    led=0x81;  delay( );

    led=0x6f;  delay( ); 

    led=0x6f;  delay( );

    led=0x6f;  delay( );

    led=0x81;  delay( );

    led=0xff;  delay( );// to make one column gap between letters 
   }
    break;

   case ' '  : // space
  
   {
    led=0xff;  delay( );

    led=0xff;  delay( );

    led=0xff;  delay( ); 

    led=0xff;  delay( );

    led=0xff;  delay( );

    led=0xff;  delay( );
   
    led=0xff;  delay( );// to make one column gap between letters

   } break;

 default:
   led=0xfe;
 // gives an underline when no letter to display blue line in the code
}
// END of program

=======================================================================================
i m giving  the example for understanding the logic of this project.you can extend the code by adding number of "switch cases" i made it for active low logic means logic zero indicates led glowing and one indicates off.
with this technique you can make your own custom designs like "heart " "smile"
by changing the "del" variable value you can change the width of a letter.because no two motors are alike.
i prefer you to go for 1000 RPMmotor from vegarobokits. Which will be around 145 Rs


This propeller LED display can be made stable using an interrupt source. An IR sensor can be used to make it stable. Better to use a IR slot sensor as shown in the picture it will be a faster compared to an LM358 based sensor. if your motor is faster than 1500 rpm then this sensor is the best.





observe this video carefully.... you will find a small yellow paper on the base ground which comes in between the slot sensor pins and triggers the display. So your display always starts from a particular point

propeller LED display on sealing fan

in the above pic the fan is shaking due to weight imbalance.

this is due to improper delay between the letters.



the video:





Bluetooth controlled rotating POV LED display 



                                  ALL THE BEST

          +++++++++++++++++++++++++++++++++++++++++++++

=============================================

NOTE: 


  DON'T JUST ASK FOR THE ENTIRE CODE.  


TRY TO


 DEVELOP IT FOR YOUR SELF 


     GO THROUGH THE ARTICLE ONCE AGAIN


 YOU 


WILL FIND EVERY THING  

+++++++++++++++++++++++++++++++++++++++++++++

=============================================

                                                                                                                                 

=========================================================================
=========================================================================  


FOR THOSE WHO WANT TO BUY THE KIT:

FREE SHIPPING ALL OVER INDIA


MAIL US AT
vaabrobotics@gmail.com