Skip to main content

Study and development of client-server application for accelerometer on IoT platform

Student: Stefano Breda

Supervisor: prof. Pier Luca Montessoro

Platform: Orange Pi PC 2

Overview

This Bachelor Thesis is about the development of a client-server application on IoT platform with Linux Embedded OS (Orange Pi PC 2) to interface with a sensor, in particular the accelerometer LIS3DH. The used communication protocols are I2C and SPI. The application is written in C language and the work is valid with appropriate changements also for other sensors like gyroscopes, temperature or pressure sensors... Client-server communication provides data usage outside the IoT paltform to avoid the installation of applications too heavy on the system. The software provides the data transfer and a basic visual representation of the data in real-time.

What you need

  • Orange Pi PC 2 (you can use also other model of Orange Pi or other boards)
  • accelerometer LIS3DH
  • an Ethernet cable
  • Wi-Fi connection
  • Stefano Breda's code (Github)

 

Setup

The first step is the connection of the accelerometer to Orange Pi board.

In particular, for use I2C protocol you have to follow theese indications:

  • pin 1: SDO
  • pin 2: VIN
  • pin 3: SDA
  • pin 5: SCK
  • pin 6: GND

For SPI protocol the pins are the following:

  • pin 2: VIN
  • pin 6: GND
  • pin 19: MISO
  •  pin 21: MOSI
  •  pin 23: SCK
  •  pin 24: CS

Then, the next step is connect Orange Pi PC 2 to your pc with an Ethernet cable and configure a network bridge between your Wi-Fi and Ethernet. If you use a pc with Microsoft Windows OS go to PC Settings => Network & Internet => Network connections, select Wi-Fi and Ethernet, right click and select Bridging connecions to obtain a Network bridge. Complete the network bridge configuration: right click on Network bridge, double click on Internet Protocol version 4 (TCP/IPv4) and edit the parameters. You have to put your pc IP address added by 1. Other parameters like netmask, default gateway, DNS servers can remain the same. Now you can connect to Orange Pi board with Remote Desktop Connection software at configured IP address.

In the following video you can see the accelerometer connection for use both I2C and SPI communication protocols.

Run the program

The first step is obtain root permits with Linux command sudo su. Then you can verify the accelorometer connection with the command:

# gpio i2cdetect

If all is good will appear a number 19 in the answer.

For the server it's enough go to the server folder and launch it with the commands:

# cd <path to server folder>

# ./tcpserver 127.0.0.1 5000

The next step is the building of the client software with the commands:

# cd <path to client folder> 

# gcc -o acc_lis3dh acc_lis3dh.c Lis3dh.c -lwiringPi -lpthread

Then you can launch the client program with the command:

# ./acc_lis3dh <protocol> <LIS3DH full scale> <server IP address> <port>

where protocol is I2C or SPI, full scale can be 2, 4, 8 or 16, server IP address is your pc IP address and for the port you can choose the number. Example:

# ./acc_lis3dh I2C 2 127.0.0.1 5000

At this point in the client you can digit the number of samples to send to the server and start to move the accelerometer. You can see the measured accelerations on the client and also on the server.

For SPI communication protocol the commands are the same. An example of SPI client command is the following:

# ./acc_lis3dh SPI 8 127.0.0.1 5000