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:  */ 
   7:  
   8: #define F_CPU 1000000UL
   9: #define FOSC 1000000 
  10: #define BAUD 4800
  11: #define MYUBRR FOSC/16/BAUD-1
  12:  
  13: #include <avr/io.h>
  14: #include <util/delay.h>
  15:  
  16: void USART_Init( unsigned int ubrr);
  17: void USART_Transmit( unsigned char data );
  18:  
  19: int main(void)
  20: {
  21:     USART_Init(MYUBRR);                                               //Initializing USART
  22:  
  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: }
  34:  
  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: }
  45:  
  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: }
  53:  

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.


CropperCapture[1]

Comments

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. ( https://github.com/krishnan793/PlymouthTheme-Cat )  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. :))

Product Design of a 4 wheel differential drive robot

I have been thinking of creating a small mobile robot from scratch. From scratch means, go through all the steps of a product development. Design the overall architecture, design the circuits, make 3D model of the parts, 3D print the parts and finally integrate with ROS. The methods I followed may not be the best practice. The only aim is to reach from idea to actual product (prototype). Features: 4 Wheel Differential Drive Camera WiFi IMU GPS(optional) Overview A 4 wheeled differential mobile robot with wheel encoders, camera, WiFi, IMU and GPS(optional). The first thing I did was to come up with an overall architecture. Raspberry pi 3 will be the heart of the robot. Pi Zero was considered in the beginning, but eventually had to  change because of the lack of support for ROS. Even though able to compile ROS from scratch, it became so hard to compile other packages needed for the project. Since I do not want to use pi to directly control motors, I had to design a

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@192.168.7.2 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  vinagre 192.168.7.2::5900 A remote desktop will be shown if all goes well. Try exploring other options in x11vnc using (in BBB) man x11vnc The se