Introduction: DragonBoard and OBD2

Picture of DragonBoard and OBD2

Reading the data that comes out of the OBD2 port in your car, it is possible to collect amazing information from it. Using the DragonBoard 410c, we worked on this project and detailed it here so you can do it yourself.

This project was only possible due to the partnership with #Qualcomm #Embarcados #Linaro #Arrow #BaitaAceleradora that allowed us to have access to the best hardware on the market, as well as the contact to the best professionals to support the development.

The team was composed by these guys:

  • Marcel Ogando - Hacker - marcelogando@gmail.com
  • Leandro Alvernaz - Hacker - leandrofga@gmail.com
  • Thiago Paulino Rodrigues - Marketing - thiago.prodrigues@gmail.com

We are very keen to help you achieve your goal, and make sure you complete your project, so let us know if you need any help further than the instructions below.


Para seguir este projeto em Português, clique aqui:

https://www.instructables.com/id/DragonBoard-Com-OBD


For this project we used the following items:

  • Qualcomm DragonBoard 410c
  • ELM327 Bluetooth OBD2 Interface
  • Dongle USB 3G/4G
  • Tension Inverter Car Charger (110v)

Step 1: Performing the DragonBoard 410c Initial Setup**

Picture of Performing the DragonBoard 410c Initial Setup**

Using Qualcomm DragonBoard 410c, we started the project by installing Linux's distribution called Linaro, allowing us to setup all devices needed.

To create an image of Linaro for the DragonBoard, use Ubunto on VirtualBox, so you can use FastBoot (that is a Linux based app). So basically what you have to do is to open up the Terminal at the VM Ubuntu and enter:

sudo apt-get android-tools-fastboot

To install Linaro, we have to go through 2 important steps:

1) Installing the BOOTLOADER

File name: dragonboard410c_bootloader_emmc_linux-79.zip

http://builds.96boards.org/releases/dragonboard410c/linaro/rescue/latest/

Unzip the files and select the folder:

cd /FolderName (path to the unzipped folder)

Enter the following code:

sudo fastboot devices

Expected return:

(hexadecimal) fastboot

Then type in:

sudo ./flashall

Expected return:

finished. total time 1.000s (without errors)

Installing the OPERATIONAL SYSTEM

http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/

Download these 2 files:

boot-linaro-stretch-qcom-snapdragon-arm64-20170607-246.img.gz

This is the latest version available to date (June/17) so the name might change in the future. The pattern you would be looking for is "boot-linaro-VersionName". This one is called "Stretch" and the previous was "Jessie".

linaro-stretch-alip-qcom-snapdragon-arm64-20170607-246.img.gz

This is the latest version to date (June/17) and the name might change in the future. Look for the pattern "linaro-VersionName-alip".

Unzip the files from the .GZ

Access the "root" folder, in relation to the unzipped files

example: "/Downloads" which is the place downloaded files are stored.

Now start with the following commands:

sudo fastboot devices

sudo fastboot flash boot boot-linaro-NomeDaVersão-qcom-snapdragon-arm64-DATA.img

Expected return (remembering the time may vary):

finished. total time: 100.00s

Connect a Mouse, Keyboard and a monitor/TV using the HDMI port

Have this at hand:

user: linaro

password: linaro

Open the app Lxterminal and proceed with the download of the available updates list, regarding the installed packages:

sudo apt-get update

Make sure to install the available packages from the list:

sudo apt-get upgrade

Hint: Linaro was chosen due to an extremely fast boot, and a community very engaged and problem solving oriented, which saves a lot of time.

Step 2: Locating Your DragonBoard 410c Using Its GPS Antenna

Picture of Locating Your DragonBoard 410c Using Its GPS Antenna

Start by installing the necessary apps that will be the clients to the GPS module. The app names are: GNSS-GPSD, GPSD and GPSD-CLIENTS. To do it, follow the commands:

sudo apt-get install gnss-gpsd gpsd gpsd-clients

With these apps installed, you will need more commands to start it properly:

sudo systemctl start qdsp-start.service

sudo systemctl start gnss-gpsd.service

sudo systemctl start qmi-gps-proxy.service

Now take the DragonBoard 410c to a wide open area, with clear view of the sky, allowing it to receive the signal from the satellites. Now type into the terminal:

gpsmon –n

From our tests, data would start showing up on the screen after 10 minutes, on average. That changes a lot from place to place, besides the position of the DragonBoard on the window, or indoors, besides many other barriers that may interfere in the GPS signal reception.

Step 3: Installing the 3G/4G USB Dongle

Picture of Installing the 3G/4G USB Dongle

There are a few ways to connect the DragonBoard 410c to the 3G/4G/GSM Network:

  • Using a Shield / BreakoutBoard with a GSM modem that also has a SimCard slot;
  • Use a USB 3G/4G Dongle.

For this project we decided to use Huawei's E3272 USB Dongle, because it was easy and quick to buy one.

To configure the modem you can use the terminal (by using the WVDial app), but the easiest way to do it is by using Linaro's Graphic User Interface (GUI). To it as follows:

  • With the USB Dongle connected to the DragonBoard, right-click the "networks" icon on the bottom right corner of the screen;
  • “Edit Connections” > “Add”;
  • Pick “Mobile Broadband” from the dropdown menu;
  • Click "Create”.

Follow the instructions from the wizard, making sure to select the proper Carrier from the menu, allowing the device to connect accordingly.

Step 4: Transforming the DragonBoard 410c Into a Wifi Hotspot / Access Point

Picture of Transforming the DragonBoard 410c Into a Wifi Hotspot / Access Point

The easiest way to configure the DragonBoard 410c as a wifi router or a hotspot (now that you have configured internet connection) is to use the system’s GUI. To do that, follow the steps below:

  • Right click the network icon in the lower right hand corner
  • Choose “Edit Connections and then “Add”
  • Choose “WiFi”
  • Click create

Change the name of the network you want to create in the “SSID” field and the change the “Mode” field to “Hotspot”.

To make sure that it will work, verify the following:

  • Go to “IPv4 Settings” tab
  • Verify if the “Method”

Step 5: Accessing the DragonBoard 410c Wirelessly Using SSH, Via Hotspot Connectivity

Picture of Accessing the DragonBoard 410c Wirelessly Using SSH, Via Hotspot Connectivity

We managed to create a way to access the DragonBoard remotely, not mattering if you are near it or not. Usually you would need to connect to the board itself, using wifi or bluetooth. Another way, would be to access it by connecting to the same Wifi Network (eg: from a router). By performing the next steps, we are creating a self contained device, that generates its own network, and opens itself to the web, in order to be accessed.

You can start by installing the "Auto SSH", using the code below:

sudo apt-get install gcc make
wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz
tar -xf autossh-1.4e.tgz
cd autossh-1.4e
./configure
make
sudo make install


Now we are going to generate a cryptographic key, using RSA standard. This key is going to be used to access securely a Linux endpoint instance, through the Public IP of the 3G Modem. The main goal of this step. The following code will copy that key into Linux's Trusted Keys Repository, making sure there's even more security to the connection.

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub user@remote_server:.ssh/authorized_keys
autossh -M 0 -q -f -N -i /home/pi/.ssh/id_rsa -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2222:localhost:22 user@remote_server


By following these steps, you have just transformed the Qualcomm DragonBoard 410c into a Cloud Server! \o/

Step 6: Connecting the DragonBoard 410c to the Car's OBD Using Bluetooth - Part 1/2

Picture of Connecting the DragonBoard 410c to the Car's OBD Using Bluetooth - Part 1/2

Car's communication interface is done through an OBD2 port. The informations that is exchanged in this port needs to be translated, and for that we need an interpreter device. There are two hardware alternatives: ELM327 or STN1170.

For this project, we used a Bluetooth device with a chipset based on ELM327.

It is importante to note the availability of the ELM327 does not mean it is the ORIGINAL VERSION of ELM327. Most part of the available chipsets are based on version 1.5, that was when the chip's information was cloned and leaked into the market. The original ELM327 is now on version 2.2. The evolution of this chipset brings more data about newer cars. It's important to know that, because depending on tests, you may or may not be able to access data from newer vehicles.

With the OBD2 Bluetooth adapter, find your car's OBD2 port. It may be locate somewhere under the steering wheel. It may be easier to look for it using this tool: https://www.hum.com/port

Access the DragonBoard 410c using SSH, from your notebook (remember that now you are in the car, and do not have a TV/Monitor to plug the board in). As soon as the OBD2 Bluetooth device is inserted into the car port, follow the steps below to access the bluetooth connectivity.

sudo bluetoothctl
pairable on
agent on
default-agent
scan on
At this stage is important that you copy the MAC Address because you will need it for the next steps.

Type these commands:

trust MACADDRESS
pair MACADDRESS

You should be prompted with a request to type the PIN Code to Pair the Bluetooth OBD2 with the board.

Usually the PIN Code is whether 1234 or 0000 - depends on your hardware

Now you should see the "connection successful" screen. To quit the Bluetooth application, use the following command:

quit

Next step is to BIND the device with the Serial Port:

sudo rfcomm bind 0 MACADDRESS 1

To make sure the operation succeeded, type:

ls /dev

The port “Rfcomm0" should be listed.

Step 7: Connecting the DragonBoard 410c to the Car's OBD Using Bluetooth - Part 2/2

Picture of Connecting the DragonBoard 410c to the Car's OBD Using Bluetooth - Part 2/2

The main objective of this step is to guarantee that the communication between the 3 devices is working:

ELM327, DragonBoard 410c and the car

Download “Screen” app to send serial messages through the serial port

sudo apt-get install screen

The serial port will be used to send AT Commands and receive the responses between the DragonBoard 410c and the ELM327 device.

Access the following link for more information on AT Commands:
http://elmelectronics.com/ELM327/AT_Commands.pdf

Warning:

Be very careful with this step! All information you send to the device will be interpreted and sent to the car, if a the wrong message is sent, it can be misinterpreted by the car and cause issues. Pay attention to the commands and study them before you attempt your own code. We strongly recommend following the instructions bellow to the letter.

Follow the command sequence below to initiate the communication:

  • This function will start the serial communication using screen:
    screen /dev/rfcomm0

As soon as the terminal loads, type the following commands in this sequence:

ATZ

ATL1

ATH1

ATS1

ATSP0

Final communication test:

Type in the console:

ATI

It should return “ELM327 v1.5” or the ELM version of your device

This is proof that the communication of the ELM device and the DragonBoard 410c is working

Quick Tip

To quit “Screen” it is necessary to type Ctrl+A followed by Ctrl+D.

Step 8: Connecting the DragonBoard 410c to the Car's OBD Using PyOBD

Picture of Connecting the DragonBoard 410c to the Car's OBD Using PyOBD

PyOBD is a Python library to enable the communication with OBD2 devices that can be connected to cars. With that, we can extract several information including the vehicle’s speed and electrical erros.

In this step we need to ensure that the following python libraries are installed in Linaro of your DragonBoard 410c:

  • PIP - Python’s package manager
    sudo apt-get install python-pip
  • SetupTools - file installation manager
    sudo pip install -U pip setupstools
  • Wheel - install package formatter
    sudo apt-get install python-wheel
  • OBD - Python library to communicate with OBD device
    sudo apt-get install python-obd
  • GPS - Python library to get data from GPS
    sudo pip install gps
  • Requests - Python package for RESTful
    sudo pip install requests

To verify if OBD’s package is working correctly, follow these steps:

sudo python

Now the terminal’s cursor will be changed to “>>>” indicating that Python is running. You can now start typing the commands below:

  • Start by importing OBD library:
    import obd 
  • To connect to the Serial Port use the command:
    connection = old.OBD(“dev/rfcomm0”)
  • It is normal to show an error message, saying that communication failed, so if that happens, try one more time.
  • To find out if Python is getting information from the car passing through ELM327 over bluetooth, type the following:
    connection.protocol_name()

Step 9: Reading Data From the Car, by Using Python

Picture of Reading Data From the Car, by Using Python

We will create a file called: OBD.py, as instructions below, followed by the code.

Start by importing the OBD library into Python to start the connections.

For unknown reasons, using our hardware, the first connection attempt always fails. Second attempt, always works. That's why on the code, you will notice two lines of command trying to make the connection.

After the connection is successful, we started an infinite loop, that seeks for OBD data, formats it according to preset parameters. After that, it creates an URL, using Query String, allowing it to be sent to the server using the POST method.

On the example below, we managed to get the following information:

  • RPM
  • Speed

The functions to capture data use two parameters. For example, using [1][12] you are serching for [module] [PID]. The list of funcions can be found at: https://github.com/brendan-w/python-OBD/blob/master/obd/commands.py

At last, generate the URL with all information concatenated and added to the file, called "obd_data.dat".

Code for OBD.py is below.

After connecting and capturing the data, we will create a file called: envia_OBD.py

This part of the code gets simpler. Import the libraries related to the request/send data, using RESTFUL.

Create a WHILE to use POST and send the URL of the first line of the file, populated previously by OBD.py. After that, to avoid data to be sent again, it erases that line from the file.

Code for the file OBD.py is below.

Step 10: Recurring Scripts and Data Storage Procedure for the Data Captured

Picture of Recurring Scripts and Data Storage Procedure for the Data Captured

Everthing we have done so far was oriented to make sure the DragonBoard communicated properly with the components, like 3G, Wifi, Bluetooth, GPS data and more.

Use the code below to edit the file "rc.local", that already has some functions and predefined commands. It's located at '/etc'. To edit, use the command:

sudo nano /etc/rc.local

Now we need to configure all services and functions, creating routines that initialize automatically when the DragonBoard starts up. Let's use BASH to do this. BASH (Bourne-Again-SHell) is a Linux Command interpreter app.

The following code has BASH commands, and you will need to insert the Bluetooth/OBD MAC Address. Be extra careful to make sure to end the code with "exit 0" that is the system's response that the action was successful.

if [ ! -f /etc/ssh/ssh_host_rsa_key ]
then
    systemctl stop ssh.socket||true
    dpkg-reconfigure openssh-server
fi
sudo systemctl start qdsp-start.service
rfcomm bind 0 MACADDRESS 1
sudo python /home/linaro/Documents/FadaDoCarro/conectaGPS.py &
sudo python /home/linaro/Documents/FadaDoCarro/OBD.py &
sudo python /home/linaro/Documents/FadaDoCarro/envia_OBD.py &
exit 0

From now on, every time you turn the DragonBoard on, it will connect to 3G and send GPS and OBD data to the chosen server.

Step 11: Troubles Along the Way

Picture of Troubles Along the Way

We listed below some of the issues we found along the way before writing this Instructable, but we thought it could help you if it happens to you.

  • PyOBD
    • You need to be very cautious to send data while communicating with the car. In one of our first tries, when the communication wasn’t stable, we sent the wrong command which basically crashed the ECU. The gearshift was stuck in parking and some of the lights of the dashboard kept blinking randomly. The solution found was to disconnect one of the battery cables for about 15 minutes. This resets the ECU to its factory default state, therefore canceling any commands or changes we might’ve made.
  • Linaro
    • We had an issue with our DragonBoard, which kept on restarting sporadically. The issue was resolved by Linaro’s team which released a newer version of the OS. We wrote this tutorial with the updated version.
  • DragonBoard’s GPS

Step 12: References

Picture of References

Bootloader

http://builds.96boards.org/releases/dragonboard410c/linaro/rescue/latest/

Linaro

http://builds.96boards.org/releases/dragonboard410c/linaro/debian/latest/

Como instalar o Linaro na DragonBoard 410c

https://www.embarcados.com.br/linux-linaro-alip-na-qualcomm-dragonboard-410c/

Documentação de GPS para DragonBoard

https://discuss.96boards.org/t/gps-software/170/16

GPS Demo

https://gist.github.com/wolfg1969/4653340

Python OBD

https://github.com/brendan-w/python-OBD

Conectando RaspberryPi à um OBD Bluetooth

http://gersic.com/connecting-your-raspberry-pi-to-a-bluetooth-obd-ii-adapter/

Comments

About This Instructable

196views

2favorites

Bio: Fizemos este perfil para compartilhar o conhecimento de como conectar a Qualcomm DragonBoard 410c ao seu carro, usando o protocolo OBD2. Boa sorte.
More by fadadocarro:DragonBoard and OBD2DragonBoard Com OBD
Add instructable to: