electronics- serial communication-uart

76
Serial Communication -UART UART or Serial Console Raspberry Pi Python Serial Library Electronics Serial Communication-UART Terry Sturtevant Wilfrid Laurier University November 7, 2018 Terry Sturtevant Electronics Serial Communication-UART

Upload: others

Post on 20-Apr-2022

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

ElectronicsSerial Communication-UART

Terry Sturtevant

Wilfrid Laurier University

November 7, 2018

Terry Sturtevant Electronics Serial Communication-UART

Page 2: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver TransmitterSimplest form of serial communicationBetween 2 devicesUses 2 signals (and Ground), Rx and TxAsynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 3: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver Transmitter

Simplest form of serial communicationBetween 2 devicesUses 2 signals (and Ground), Rx and TxAsynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 4: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver TransmitterSimplest form of serial communication

Between 2 devicesUses 2 signals (and Ground), Rx and TxAsynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 5: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver TransmitterSimplest form of serial communicationBetween 2 devices

Uses 2 signals (and Ground), Rx and TxAsynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 6: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver TransmitterSimplest form of serial communicationBetween 2 devicesUses 2 signals (and Ground), Rx and Tx

Asynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 7: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Serial Communication -UART

Universal Asynchronous Receiver TransmitterSimplest form of serial communicationBetween 2 devicesUses 2 signals (and Ground), Rx and TxAsynchronous, so both must agree on baud rate

Terry Sturtevant Electronics Serial Communication-UART

Page 8: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” levelLSB transmitted firstCan have odd, even, or no parity bit1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 9: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” level

LSB transmitted firstCan have odd, even, or no parity bit1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 10: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” levelLSB transmitted first

Can have odd, even, or no parity bit1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 11: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” levelLSB transmitted firstCan have odd, even, or no parity bit

1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 12: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” levelLSB transmitted firstCan have odd, even, or no parity bit1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 13: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Communication parameters

1 Start bit at “0” levelLSB transmitted firstCan have odd, even, or no parity bit1 or 2 Stop bits at “1” level

Since start and stop bits are opposite, new characters can alwaysbe detected.

Terry Sturtevant Electronics Serial Communication-UART

Page 14: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Terry Sturtevant Electronics Serial Communication-UART

Page 15: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

Terry Sturtevant Electronics Serial Communication-UART

Page 16: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1

Terry Sturtevant Electronics Serial Communication-UART

Page 17: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1

1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 18: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2

1 1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 19: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2 3

1 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 20: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2 3 4

1 1 1 0 0

Terry Sturtevant Electronics Serial Communication-UART

Page 21: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2 3 4 5

1 1 1 0 0 1

Terry Sturtevant Electronics Serial Communication-UART

Page 22: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2 3 4 5 6

1 1 1 0 0 1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 23: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

LSB

1 2 3 4 5 6 7

MSB

1 1 1 0 0 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 24: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

0

LSB

1 2 3 4 5 6 7

MSB

1 1 1 0 0 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 25: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

0

LSB

1 2 3 4 5 6 7

MSB

1 1 1 0 0 1 1 0

UART no parity - 01100111

Terry Sturtevant Electronics Serial Communication-UART

Page 26: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

Parity0 1 2 3 4 5 6 7

UART even parity

Terry Sturtevant Electronics Serial Communication-UART

Page 27: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

Parity0 1 2 3 4 5 6 7

UART even parity

Terry Sturtevant Electronics Serial Communication-UART

Page 28: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

Parity0 1 2 3 4 5 6 7

UART odd parity

Terry Sturtevant Electronics Serial Communication-UART

Page 29: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Baud rate calculation

Baud rate is the number of bits possible in a seconde.g. 9600 baud → 1 bit takes 1

9600 secondAfter start bit is detected, wait time for 11

2 bit to testfor first data bit and then after every 1 bit intervalResetting at the start bit allows some clock variation

Terry Sturtevant Electronics Serial Communication-UART

Page 30: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Baud rate calculation

Baud rate is the number of bits possible in a second

e.g. 9600 baud → 1 bit takes 19600 second

After start bit is detected, wait time for 112 bit to test

for first data bit and then after every 1 bit intervalResetting at the start bit allows some clock variation

Terry Sturtevant Electronics Serial Communication-UART

Page 31: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Baud rate calculation

Baud rate is the number of bits possible in a seconde.g. 9600 baud → 1 bit takes 1

9600 second

After start bit is detected, wait time for 112 bit to test

for first data bit and then after every 1 bit intervalResetting at the start bit allows some clock variation

Terry Sturtevant Electronics Serial Communication-UART

Page 32: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Baud rate calculation

Baud rate is the number of bits possible in a seconde.g. 9600 baud → 1 bit takes 1

9600 secondAfter start bit is detected, wait time for 11

2 bit to testfor first data bit and then after every 1 bit interval

Resetting at the start bit allows some clock variation

Terry Sturtevant Electronics Serial Communication-UART

Page 33: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Baud rate calculation

Baud rate is the number of bits possible in a seconde.g. 9600 baud → 1 bit takes 1

9600 secondAfter start bit is detected, wait time for 11

2 bit to testfor first data bit and then after every 1 bit intervalResetting at the start bit allows some clock variation

Terry Sturtevant Electronics Serial Communication-UART

Page 34: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Terry Sturtevant Electronics Serial Communication-UART

Page 35: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

Terry Sturtevant Electronics Serial Communication-UART

Page 36: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0

1

Terry Sturtevant Electronics Serial Communication-UART

Page 37: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1

1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 38: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2

1 1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 39: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2 3

1 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 40: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2 3 4

1 1 1 0 0

Terry Sturtevant Electronics Serial Communication-UART

Page 41: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2 3 4 5

1 1 1 0 0 1

Terry Sturtevant Electronics Serial Communication-UART

Page 42: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2 3 4 5 6

1 1 1 0 0 1 1

Terry Sturtevant Electronics Serial Communication-UART

Page 43: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

0 1 2 3 4 5 6 7

1 1 1 0 0 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 44: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

0 1 2 3 4 5 6 7

1 1 1 0 0 1 1 0

Terry Sturtevant Electronics Serial Communication-UART

Page 45: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

0 1 2 3 4 5 6 7

1 1 1 0 0 1 1 0

Bit timing

Terry Sturtevant Electronics Serial Communication-UART

Page 46: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted±3→ ±12Zero is not a valid voltageMark level (inactive/1) is a negative voltageSpace level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 47: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted

±3→ ±12Zero is not a valid voltageMark level (inactive/1) is a negative voltageSpace level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 48: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted±3→ ±12

Zero is not a valid voltageMark level (inactive/1) is a negative voltageSpace level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 49: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted±3→ ±12Zero is not a valid voltage

Mark level (inactive/1) is a negative voltageSpace level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 50: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted±3→ ±12Zero is not a valid voltageMark level (inactive/1) is a negative voltage

Space level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 51: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

RS232 communication

Voltages are inverted±3→ ±12Zero is not a valid voltageMark level (inactive/1) is a negative voltageSpace level (active/0) is a positive voltage

Terry Sturtevant Electronics Serial Communication-UART

Page 52: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

ParityMark 0 1 2 3 4 5 6 7

Terry Sturtevant Electronics Serial Communication-UART

Page 53: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start

ParityMark

Space

0 1 2 3 4 5 6 7

Terry Sturtevant Electronics Serial Communication-UART

Page 54: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

ParityMark

Space

0 1 2 3 4 5 6 7

Terry Sturtevant Electronics Serial Communication-UART

Page 55: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial LibraryBaud rate calculationRS232 communication

Start Stop

ParityMark

Space

0 1 2 3 4 5 6 7

RS232 levels

Terry Sturtevant Electronics Serial Communication-UART

Page 56: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

UART or Serial Console

On the Raspberry Pi, the serial console uses the UART→ the UART isn’t available for other devicesThe serial console can be disabledThis means you need to connect to monitor, keyboard, etc.

Terry Sturtevant Electronics Serial Communication-UART

Page 57: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

UART or Serial Console

On the Raspberry Pi, the serial console uses the UART

→ the UART isn’t available for other devicesThe serial console can be disabledThis means you need to connect to monitor, keyboard, etc.

Terry Sturtevant Electronics Serial Communication-UART

Page 58: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

UART or Serial Console

On the Raspberry Pi, the serial console uses the UART→ the UART isn’t available for other devices

The serial console can be disabledThis means you need to connect to monitor, keyboard, etc.

Terry Sturtevant Electronics Serial Communication-UART

Page 59: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

UART or Serial Console

On the Raspberry Pi, the serial console uses the UART→ the UART isn’t available for other devicesThe serial console can be disabled

This means you need to connect to monitor, keyboard, etc.

Terry Sturtevant Electronics Serial Communication-UART

Page 60: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

UART or Serial Console

On the Raspberry Pi, the serial console uses the UART→ the UART isn’t available for other devicesThe serial console can be disabledThis means you need to connect to monitor, keyboard, etc.

Terry Sturtevant Electronics Serial Communication-UART

Page 61: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

There is a script to enable and disable the serial console

sudo rpi-serial-console disablewill disable the consolesudo rpi-serial-console enablewill enable the console

Remember you probably don’t want to be using thiscommand from within the serial console.

Terry Sturtevant Electronics Serial Communication-UART

Page 62: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

There is a script to enable and disable the serial consolesudo rpi-serial-console disablewill disable the console

sudo rpi-serial-console enablewill enable the console

Remember you probably don’t want to be using thiscommand from within the serial console.

Terry Sturtevant Electronics Serial Communication-UART

Page 63: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

There is a script to enable and disable the serial consolesudo rpi-serial-console disablewill disable the consolesudo rpi-serial-console enablewill enable the console

Remember you probably don’t want to be using thiscommand from within the serial console.

Terry Sturtevant Electronics Serial Communication-UART

Page 64: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

There is a script to enable and disable the serial consolesudo rpi-serial-console disablewill disable the consolesudo rpi-serial-console enablewill enable the console

Remember you probably don’t want to be using thiscommand from within the serial console.

Terry Sturtevant Electronics Serial Communication-UART

Page 65: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial

ser = serial.Serial()open portser.baudrate = 19200set baudrateser.port =’//dev//ttyAMA0’set portser.is openreturns True if open, False if not

Terry Sturtevant Electronics Serial Communication-UART

Page 66: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial

ser = serial.Serial()open port

ser.baudrate = 19200set baudrateser.port =’//dev//ttyAMA0’set portser.is openreturns True if open, False if not

Terry Sturtevant Electronics Serial Communication-UART

Page 67: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial

ser = serial.Serial()open portser.baudrate = 19200set baudrate

ser.port =’//dev//ttyAMA0’set portser.is openreturns True if open, False if not

Terry Sturtevant Electronics Serial Communication-UART

Page 68: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial

ser = serial.Serial()open portser.baudrate = 19200set baudrateser.port =’//dev//ttyAMA0’set port

ser.is openreturns True if open, False if not

Terry Sturtevant Electronics Serial Communication-UART

Page 69: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial

ser = serial.Serial()open portser.baudrate = 19200set baudrateser.port =’//dev//ttyAMA0’set portser.is openreturns True if open, False if not

Terry Sturtevant Electronics Serial Communication-UART

Page 70: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial (continued)

ser.write(b’string’)write stringser.read(10)read 10 bytes (or until timeout)ser.readline()read until ’\n’ receivedser.close()close port

Terry Sturtevant Electronics Serial Communication-UART

Page 71: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial (continued)

ser.write(b’string’)write string

ser.read(10)read 10 bytes (or until timeout)ser.readline()read until ’\n’ receivedser.close()close port

Terry Sturtevant Electronics Serial Communication-UART

Page 72: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial (continued)

ser.write(b’string’)write stringser.read(10)read 10 bytes (or until timeout)

ser.readline()read until ’\n’ receivedser.close()close port

Terry Sturtevant Electronics Serial Communication-UART

Page 73: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial (continued)

ser.write(b’string’)write stringser.read(10)read 10 bytes (or until timeout)ser.readline()read until ’\n’ received

ser.close()close port

Terry Sturtevant Electronics Serial Communication-UART

Page 74: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial (continued)

ser.write(b’string’)write stringser.read(10)read 10 bytes (or until timeout)ser.readline()read until ’\n’ receivedser.close()close port

Terry Sturtevant Electronics Serial Communication-UART

Page 75: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial sample code

i m p o r t s e r i a ls e r = s e r i a l . S e r i a l (”/ dev /ttyAMA0 ”)s e r . b a u d r a t e = 9600data = s e r . r e a d ( 1 0 )#data = s e r . r e a d l i n e ( )s e r . w r i t e ( data )s e r . c l o s e ( )

Terry Sturtevant Electronics Serial Communication-UART

Page 76: Electronics- Serial Communication-UART

Serial Communication -UARTUART or Serial Console

Raspberry Pi Python Serial Library

PySerial sample code

i m p o r t s e r i a ls e r = s e r i a l . S e r i a l (”/ dev /ttyAMA0 ”)s e r . b a u d r a t e = 9600data = s e r . r e a d ( 1 0 )#data = s e r . r e a d l i n e ( )s e r . w r i t e ( data )s e r . c l o s e ( )

Terry Sturtevant Electronics Serial Communication-UART