Monday, November 23, 2015

Serial Communication Test on Raspberry-pi


Serial Communication Test on Raspberry-pi

  1. First we have to disable OS from using serial port

1.png

2.png

3.png

4.png

  1. Just for the testing; Connect TxRx pin 8 and 10 on pin header with a jumper(cable).

8-10.png

  1. Then write to Serial port with following python code.

#!/usr/bin/env python

import time

import serial

ser = serial.Serial(

            port='/dev/ttyAMA0',

            baudrate = 9600,

            parity=serial.PARITY_NONE,

            stopbits=serial.STOPBITS_ONE,

            bytesize=serial.EIGHTBITS,

            timeout=1

)

counter=0

while 1:

            print counter

            ser.write('Write counter: %d \n'%(counter))

            time.sleep(1)

            counter += 1

write.png

  1. Use following code to read it

#!/usr/bin/env python

import time

import serial

ser = serial.Serial(

                   port='/dev/ttyAMA0',

                   baudrate = 9600,

                   parity=serial.PARITY_NONE,

                   stopbits=serial.STOPBITS_ONE,

                   bytesize=serial.EIGHTBITS,

                   timeout=1

               )

counter=0

while 1:

  x=ser.readline()

  print x

read.png

Srinath Gamage has attached the following document:
Serial Communication Test on Raspberry-pi
Google Docs: Create and edit documents online.Logo for Google Docs

Share Article : Serial Communication Test on Raspberry-pi
Share/Save/Bookmark

0 comments:

Post a Comment