Skip to main content

Featured Post

Product Design of a 4 wheel differential drive robot

Serial port communication using AVR


Serial port communication is pretty much useful and also simple to carry out. There are certain thing you need to get first.

1. A microcontroller (Here Atmega328p).

2. A USB2serial converter.

3. A terminal software.

Modern computers won’t have this rs232 serial ports. So there is no use to go for an rs232 module and get started. Only option left is to communicate through USB ports. Many microcontrollers lack USB support. So there is an easy way. Buy a USB2serial converter or use an old Nokia 1200 or 1680 USB data cable. It has a serial to USB converter. It costs only around 60Rs(India). These are old handsets.

131011-145739If you ain’t find this one, go to eBay and buy this USB To RS232 TTL Converter Adapter Module PL2303HX( Link here). You have to pay around 200 RS for this one.

Let’s get started.

Find the TX pin from datasheet. For Atmega328 it’s pin no: 3. Connect it to RX pin of the USB2serial converter. Then use the given code for sending the word “HELLO” to PC.

Use a terminal to view the output. You can use putty (link here) or HyperTerminal. Putty is free and open source. It’s available for Linux and Windows. HyperTerminal is preinstalled with windows. You can download it for WIN7 or WIN8.

   1: /*
   2:  * Serial_port.c
   3:  *
   4:  * Created: 06-10-2013 11:51:41
   5:  *  Author: ANANTHAKRISHNAN
   6:  */ 
   8: #define F_CPU 1000000UL
   9: #define FOSC 1000000 
  10: #define BAUD 4800
  11: #define MYUBRR FOSC/16/BAUD-1
  13: #include <avr/io.h>
  14: #include <util/delay.h>
  16: void USART_Init( unsigned int ubrr);
  17: void USART_Transmit( unsigned char data );
  19: int main(void)
  20: {
  21:     USART_Init(MYUBRR);                                               //Initializing USART
  23:     while(1)
  24:     {
  25:         USART_Transmit('H');
  26:         USART_Transmit('E');
  27:         USART_Transmit('L');
  28:         USART_Transmit('L');
  29:         USART_Transmit('O');
  30:         USART_Transmit('\n');
  31:         USART_Transmit('\r');
  32:     }
  33: }
  35: void USART_Init( unsigned int ubrr)
  36: {
  37:     /*Set baud rate */
  38:     UBRR0H = (unsigned char)(ubrr>>8);
  39:     UBRR0L = (unsigned char)ubrr;
  40:     //Enable receiver and transmitter */
  41:     UCSR0B = (1<<TXEN0) | (1<<RXEN0);
  42:     /* Set frame format: 8data, 2stop bit */
  43:     UCSR0C = (1<<USBS0)|(3<<UCSZ00)|(1<<UPM01);//Asynchronous 8bit data Even parity 1 stop bit
  44: }
  46: void USART_Transmit( unsigned char data ) 
  47: {
  48:    // Wait for empty transmit buffer */
  49:    while ((UCSR0A & (1 << UDRE0)) == 0) {};
  50:    // Put data into buffer, sends the data */
  51:    UDR0 = data;
  52: }

The code is self explanatory. If you have any doubts do comment. Don’t forget to add same boad rate and parity in the terminal.

Here is a snapshot of putty displaying the output.



Popular posts from this blog

Plymouth theme for Ubuntu

Bored of having the same boot animation screen again and again? There are plenty of Plymouth themes available out there. This is a theme I created by slicing some cool gif files I found online. You can download the theme and find the installation steps on my github account. (

 The theme is created for Ubuntu 16.04. But this can be installed on previous versions with slight modification. If you have a slow computer then you can watch the whole animation loops. (The VM I used to record the screen was fast though. :))

Raspberry pi based Car Infotainment system

Out in the market, there are a handful of car infotainment systems that you can buy for 10 to 30k INR. But nothing beats the thrill of making one from scratch and put it on your own car. So this is my effort to make one from the scratch.

At heart, it is a raspberry pi 3 Model B single board computer. For those who don't know about raspberry pi, it is a single board compute with a Quad Core 1.2GHz Broadcom BCM2837 64bit CPU with on board WiFi and Bluetooth. See this for a complete spec. It is connected with a 7 inch multi touch display running Ubuntu Mate (a Linux variant). Os is modified so that it is only running the bare minimum services to run the system. It will save the boot up time and improve performance a little bit. It is connected to a GPS module via UART to get current location. It is used in the navigation section. It is also used to get time, when the device is not connected to internet. It uses google map API for navigation.

The complete infotainment system is buil…

Remote access your BeagleBone Black using vnc

Before going into how to share desktop with your BBB I assume you have a proper ssh access to your BBB. (through USB) (if not read this) Also this tutorial is for BBB with Debian installed (type cat /etc/*-release to know which distro you are currently using. Or refer here)
First install the vnc server in BBB.(After logging into BBB)
ssh root@ apt-get install x11vnc
Then go to your local computer and open a terminal window. Install a vnc viewer like vinagre.
sudo apt-get install vinagre
Now its time to start vnc server in BBB.
x11vnc -auth /var/run/lightdm/root/:0 -forever
This will start a vnc server at port 5900. Note this server setup is temporary. If you want to remotely connect to your BBB after a reboot type the above command again.
Go to your local computer and type 

A remote desktop will be shown if all goes well. Try exploring other options in x11vnc using (in BBB)
man x11vnc
The server that's currently running will not have any password s…