Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Programming the BeagleBone

You're reading from  Programming the BeagleBone

Product type Book
Published in Jan 2016
Publisher
ISBN-13 9781784390013
Pages 180 pages
Edition 1st Edition
Languages

Table of Contents (21) Chapters

Programming the BeagleBone
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Cloud9 IDE Blinking Onboard LEDs Blinking External LEDs Controlling LED Using a Push Button Reading from Analog Sensors PWM – Writing Analog Information Internet of Things with BeagleBone Physical Computing in Python UART, I2C, and SPI Programming Internet of Things using Python GPIO Control in Bash BeagleBone Capes
Pinmux and the Device Tree Index

Program to read/write on UART


UART implementation inside the Adafruit Python library has methods to set up and start UART channels, load an appropriate device tree and to clean up. It does not provide actual UART read/write methods as they are already part of the Python module "pyserial." There is a need for a "pyserial" Python module installation to read/write on the UART channel. Run the following command:

sudo pip install pyserial

Connect pin "P9_24" (TX pin of UART1) to "P9_11" (RX pin of UART4) using a jumper wire. Type the following two programs in Cloud9, save them as UART1.py and UART4.py. Run UART4.py first. Then run UART1.py. You should see Hello World printed on the output window of program UART4.py.

This the code for UART1.py:

#!/usr/bin/python

import Adafruit_BBIO.UART as UART
import serial
import time

port = "/dev/ttyO1"
baudrate = 9600
write_str = "Hello World\n"

UART.setup("UART1")
ser1 = serial.Serial(port, baudrate)
ser1.close()
ser1.open()
if ser1.isOpen():
    print(...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}