Twitter icon
Facebook icon
LinkedIn icon
Google icon
Reddit icon
StumbleUpon icon
Del.icio.us icon

Smart Sensor IoT Bring Up on Two Continents

Added to IoTplaybook or last updated on: 10/27/2021
Smart Sensor IoT Bring Up on Two Continents

Story

Introduction

The Smart Sensor IoT board is a custom board developed for training engineers on the design and development of embedded system based around an IoT solution.

This board is intended to support IoT developments, Sensor Processing and Machine Learning for predictive maintenance.

At the heart of the SensorsThink Smart IoT board is a Zynq 7020 SoC, which has 1 GB of DDR3 and 128 Mb of QSPI for primary boot, SD Card for secondary boot.

Sensors wise the board provides

  • Onboard three axis accelerometer - with temperature
  • Onboard FLIR Lepton 3 thermal sensor
  • Onboard vibration sensor
  • Onboard eCompass for magnetic field detection
  • On board temperature and humidity
  • Remote temperature sensing
  • Remote humidity sensor

As the application is intended for connected applications it also provides the following interfaces.

  • 1G Ethernet
  • WiFi
  • Bluetooth
  • USB host
  • USB UART for debugging

Currently we have boards in the USA and the UK, I thought it would be good as part of the test program to develop a test application which could show the benefits of this board and use its IoT Connectivity to communicate temperature data from both boards to a central cloud hub. This neatly demonstrates the capabilities of the Smart Sensor IoT Board.

Things used in this project

Hardware components

 
Smart Sensor IoT Board
 
× 1

Adiuvo

Software apps and online services

Vivado Design Suite
Xilinx Vivado Design Suite
 
  Xilinx
PetaLinux
Xilinx PetaLinux
 
  PetaLinux

Vivado Design

As this board is a custom board there is no board definition which can be pulled into Vivado to help us get started creating the design. The first thing we need to do is create a project targeting the Zynq 7020 in the CLG400 package

With the project created the next step is to configure the processing system with the correct MIO, Clocking and DDR.

The clock is 50 MHz, with expected CPU clock frequency of 666Mhz and 525 MHz for the DDR

The final step is to configure the DDR3 interface where our applications will run from.

You may need information from the board design for to complete this.

With the Zynq PS configured the next step is to create the block diagram which will be able to support the sensors. located on the board.

The board has the following sensors

These sensors are predominantly connected to the PL pins as such a

With this created, we can build the application export the XSA to create a PetaLinux Solution.

Petalinux Design

To be able to effectively drive the sensors and network connections the Zynq PS will be running a Embedded Linux Solution created by PetaLinux.

The first thing to do is create the project - This targets a generic Zynq implementation.

The next step is to then configure the design to use the XSA just exported.

To be able to use the USB and the I2C sensors we need to make a few modifications to the device trees under the project/meta-user layer

The first is to add in the USB and configure it as the host

The second is to add in the I2C

We also need to make some modification to the Kernel to enable the I2C drivers and to use a SD Card for the ROOTFS.

petalinux-config -c kernel

petalinux-config -c kernel

In the kernel enable the Xilinx I2C Controller

We also need to disable the RAM Root FS in the Kernel

Within the Root FS we need to enable several packages including I2Ctools and Python.

petalinux-config -c rootfs

petalinux-config -c rootfs

Enable the I2C tools in the RootFS

Enable Python3

Enable the Python Package

In the overall project configuration, select the rootfs as being located externally on a SD card

petalinux-config

fff

With the configuration complete we are able to build the petalinux project

petalinux-build

Once the build is complete we need to create a SD Card which is correctly partitioned. A guide to doing this can be found here.

Once the card has two partitions copy the boot.bin boot.scr and image.ub to the boot partition.

On the root partition, extract rootfs.tar.gz then run the sync command.

Once this is complete we are able to write the boot.bin to the QSPI and insert the SD Card.

Power on the system, and connect the wired Ethernet port.

IoT configuration

To get started using the Smart IoT board we need to install several Python packages using PIP3.

The first of these is to install the Adafruit IO package which will allow data to be posted to the cloud.

Once this is installed, the next step is to install the smbus protocol to enable us to communicate with the I2C devices on the board.

The final step is to develop the application and upload it to the smart sensor IoT Board.

import smbus2
from smbus2 import SMBus, i2c_msg
import Adafruit_IO
from Adafruit_IO import Client
import time

aio = Client('SensorsThink', 'aio_BMiV46Ym7u45hhNOcr34pvniPZsv')

MAXINT = 255  # Must be a power-of-two minus one
NUM_BITS = MAXINT.bit_length()

def merge(a, b):
    c = (a << NUM_BITS) | b
    return c


#aio = Client('NAME', 'USER')

i2c_bus = smbus2.SMBus(3)
Sensor_addr = 0x6a

msg = i2c_msg.write(Sensor_addr, [0x0f])
i2c_bus.i2c_rdwr(msg)

msg = i2c_msg.read(Sensor_addr, 0x1)
i2c_bus.i2c_rdwr(msg)

data = list(msg)
print("device ID =", data)

msg = i2c_msg.write(Sensor_addr, [0x10, 0x40])
i2c_bus.i2c_rdwr(msg)
feeds = aio.feeds()
print(feeds)
while True:
    #if (data[2] == 0x00):
    #    ppm_result = (data[0]*256) + data[1]
    #    tvoc_result = (data[7]*256) + data[8]
    #    aio.send('co2-internal', ppm_result)
    #    aio.send('tvoc', tvoc_result)
        msg = i2c_msg.write(Sensor_addr, [0x20])
        i2c_bus.i2c_rdwr(msg)

        msg = i2c_msg.read(Sensor_addr, 0x2)
        i2c_bus.i2c_rdwr(msg)

        data = list(msg)
        
        upper = (data[1])
        lower = (data[0])
        temp = merge(upper, lower)
   
        
        if (temp & 0x8000 == 0):
            temp_c = (temp / 256.0) + 25.0
        else:
            temp_c = temp * 0.0625
        
        #print (temp)
        print (temp_c)
        aio.send('temperature', temp_c)
        time.sleep(5)

When all this was completed we can see the temperature from the board being output on the Ada Fruit cloud the dashboards associated with this are public so can be see at https://io.adafruit.com/SensorsThink/dashboards/sensorsthink-temperature

Of course this is showing data from both boards, one located in MA, USA and the other just outside London in the UK

Wrap Up

This project was very interesting to complete, it is the first time the SensorThink Smart Sensors IoT board has been brought up to run a full Linux OS and communicate with sensors and the cloud as it is expected to do in applications.

Over the next few months as the Book and Board are released you will be hearing more about both of these!

Credits

Adam Taylor

Adam Taylor

Adam Taylor is an expert in design and development of embedded systems and FPGA’s for several end applications (Space, Defense, Automotive)

 

Hackster.io

This content is provided by our content partner Hackster.io, an Avnet developer community for learning, programming, and building hardware. Visit them online for more great content like this.

This article was originally published at Hackster.io. It was added to IoTplaybook or last modified on 10/27/2021.