Introduction: Serial Communication and Firebase Data Sending With DragonBoard 410c

Picture of Serial Communication and Firebase Data Sending With DragonBoard 410c

Using Python serial library, we read the sensor values and send to Firebase using Pyrebase third party library.

Step 1: Setting Serial Parameters

Picture of Setting Serial Parameters

To read the sensors values with serial communication we need to import a Python library called "serial":

import serial

ser = serial.Serial('/dev/ttyUSB') is the port that serial is connected;

ser.baudrate = 115200 is the serial baudrate of serial;

Step 2: Setting Firebase Database Parameters

Picture of Setting Firebase Database Parameters

To make communication with Firebase we need to install a third party library called "Pyrebase".

To do this we will execute the follow terminal command:

pip install pyrebase (before this, you need to install the pip "python get-pip.py").

After this import the library (import Pyrebase).

Now the parameters will be set:

config = {

"apiKey": "AIzaSyBlHBEbRzYL5IOHc9Yqkn-2XlxHe1R947Q",

"authDomain": "imaca2-36859.firebaseapp.com",

"databaseURL": "https://imaca2-36859.firebaseio.com",

"storageBucket": "imaca2-36859.appspot.com"

}

These parameters you will obtain in your Firebase database.

Next you create firebase variables:

firebase = pyrebase.initialize_app(config)

db = firebase.database()

Step 3: Reading Values From Serial and Sending to Firebase

Picture of Reading Values From Serial and Sending to Firebase

The following code reads a serial line:

var = serial.readline()

To format and convert to float the next two lines are executed:

var = var.replace('\0', '')

var = float(var)

Now we send the value to our database:

db.update({"key": var})

After all we will finish the serial communication:

ser.close()

Comments

DIY Hacks and How Tos (author)2017-01-22

Welcome to Instructables. Thanks for sharing with the community.