This tutorial represents communication between Beaglebone black and Arduino through UART. You don’t need any another peripheral for this tutorial. UART stands for universal asynchronous receiver and transmitter. It transmits and receives data asynchronously with another device which also supports UART protocol.
Required Tools:
- Beaglebone Black
- Arduino
- Female to Female connectors
Setup of Software environment
Install the latest python version in BBB as explained in tutorial How to make first python program with Beaglebone Black. Install the adafruit python-GPIO library.
Working
Beaglebone transmits the message which is entered from command prompt and Arduino receives the data and displays it on Arduino serial terminal. Run the python script from SSH terminal and at the same time open Arduino serial in PC. Write some message from SSH terminal. BBB transfers the data through UART which is then received by Arduino and displayed on serial terminal.
Description
BBB has on chip five UART ports each containing two pins: RX pin and TX pin to receive and transmit respectively. In this tutorial, UART1 is used for communication with Arduino. Here, BBB acts as transmitter and Arduino as receiver. Connect the UART1 transmitting pin (24th pin of header P9) of BBB to receiving pin (pin number 10th) of Arduino. I have used software UART in Arduino that’s why I have connected it with pin number 10th (I declared 10th and 11th pin as RX and TX in program respectively). Make the common ground connection between Arduino and BBB which is necessary for communication.
Open the command terminal and access Beaglebone black through SSH as explained in getting started with Beaglebone black. Create a new file using touch command with .py extension (i.e. led.py). Open the file with any text editor (i.e. nano, vim etc.) and write a code in python language.
Connect Arduino with PC through USB cable. Open it and then write a code for receiving data in C language. For help, you may refer to the tutorial how to Install and run Arduino in Linux.
UART setup in BBB
You need to import UART in program to make use of I2C device. You can create your own library but that would consume more time. Hence Ad fruit library can be used that provides all kind of python library of BBB.
import Adafruit_BBIO.UART as UART
Also import the serial from python library. It encapsulates access to serial port.
import serial
Configure UART by following function:
UART.setup(“UART1”)
serial.Serial (port = “/dev/ttyO1”, baudrate=9600)
First function is setup and configuration of UART1. Second function accesses the serial device with defined baud rate. Find the device port attached with UART from the list below and access it.
Now, you can transmit and receive data through UART. You can close the port when you don’t want to use it.
Arduino Setup
Write a receiving source code in Arduino and load it onto Arduino Uno. After the data is received, it will be displayed on the serial terminal.
Run the script from terminal:
Enter the following command with file name from command prompt:
python filename.py
i.e. python uart.py
You may also like:
Project Source Code
Project Source Code
###
// UART.C
#include
SoftwareSerial uart(10,11);void setup(){Serial.begin(9600);uart.begin(9600);}void loop(){if(uart.available() > 0){Serial.write(uart.read());}}//import Adafruit_BBIO.UART as UARTimport serialUART.setup("UART1")disp = serial.Serial (port = "/dev/ttyO1", baudrate=9600)disp.close()disp.open()while True:if disp.isOpen():print "Serial is Openn"message = raw_input("Enter your message:n")disp.write(message)disp.write("n")exit = raw_input("You want to exit or not YN:")while ((exit != 'Y') and (exit != 'N') and (exit != 'y') and (exit != 'n')):print "Invalid Input!!!n"exit = raw_input("You want to exit or not YN:")if (exit == 'Y') or (exit == 'y'):breakelse:print "To be continue....n"print "Sorry!!! You not able to do communicate with device"disp.close()###
Circuit Diagrams
Project Video
Filed Under: BeagleBone, Electronic Projects
Filed Under: BeagleBone, Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.