Skip to content

Peripherals

The BrioSens allows access to its different peripherals.

  • USB

  • FTDI

  • Serial RS232

  • GPIO

  • ADC

  • Wi-Fi

  • Bluetooth

  • Wireless connectivity through the BitPipe

USB

The BrioSens Gateway is equipped with a USB port which acts as a USB host.

Serial Console

A serial console is accessible via an onboard header. With the provided FTDI serial cable connected to the board, a serial terminal such as Putty can be used with the following configurations:

  • Baud rate: 115200
  • Flow control: none
  • Data bits: 8
  • Stop bits: 1
  • Parity bits: 0

Serial RS-232

An additional serial RS-232 interface is available on the BrioSens. The serial interface is accessible as a regular TTY device and is shown in the device list as:

/dev/ttyAPP0

GPIO Inputs (DIN)

The GPIOs can be used to read digital signals or the state of dry contacts (e.g. switch or relay). The GPIOs are accessible through the sysfs GPIO interface.

Warning

The digital inputs have internal pull-ups and so, when used to read the state of a dry contact, one side must be connected to the digital input; the other side of the contact must be tied to ground.

To use a GPIO, it must first be exported in sysfs. The GPIOs export is available in the following directory:

/sys/class/gpio

When used as input interrupts, the gpios must be exported, configured as input and then the edge must be configured as "rising" or "falling". The interrupt count can then be obtained by reading the /proc/interrupts file

The following table indicates the GPIO numbers to use:

DIN # IO pin Interrupt pin
1 GPIO56 GPIO 85
2 GPIO57 GPIO 86
3 GPIO38 GPIO 67
4 GPIO39 GPIO 68

GPIO Inputs Example

The following script will configure DIN1 and then read the number of interrupts that have been detected:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/sh

# set variables
DIN1_GPIO=56
DIN1_INTERRUPT=85

# export the GPIO
echo "$DIN1_GPIO" > /sys/class/gpio/export

# set the GPIO to input
echo in > "/sys/class/gpio/gpio${DIN1_GPIO}/direction

# set the interrupt edge to falling
echo falling > "/sys/class/gpio/gpio${GIO1_GPIO}/edge

# read the interrupts file and extract the interrupt count
cat /proc/interrupts | grep gpio-mxs | grep ${DIN1_INTERRUPT} | sec 's/\s\s*/ /g' | cut -d' ' -f3

GPIO Outputs (DOUT)

The GPIOs can be configured as outputs. The GPIOs are accessible through the sysfs GPIO interface.

Info

The GPIOs output logic is reversed, meaning that a value of 1 is written, the logical output value will be 0.

Warning

The GPIOs are labeled DIO on the board; however, the GPIOs can only be used as inputs on hardware revisions prior to Rev130. The hardware version can be obtained using the get_hw_version command.

To use a GPIO, it must first be exported in sysfs. The GPIOs export is available in the following directory:

/sys/class/gpio

The following table indicates the GPIO numbers to use:

DOUT # IO pin
1 GPIO131
2 GPIO132
3 GPIO83
4 GPIO84

GPIO Outputs Example

The following script will configure DOUT1 and then read the number of interrupts that have been detected:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/sh

# set variables
DOUT1_GPIO=131

# export the GPIO
echo "$DOUT1_GPIO" > /sys/class/gpio/export

# set the GPIO to output
echo out > "/sys/class/gpio/gpio${DOUT1_GPIO}/direction

# change the value of the GPIO
echo 1 > "/sys/class/gpio/gpio${DOUT1_GPIO}/value

ADC

The ADC pins on the microcontroller can measure voltages up to 1.85V (Refer to the ADC electrical specifications). In order to measure voltages above that limit, various gains can be configured for each ADC channel. The voltage applied to the ADC inputs (AIO1-AIO4) can go up to 24.46V.

The gain for each analog input can be individually controlled by setting and resetting various GPIO variables. Each ADC input has corresponding GPIOs for the gain. The following table presents the GPIOs corresponding to each ADC channel.

Input DIV GAIN1 GAIN2 GAIN3
AIO1 GPIO51 GPIO 50 GPIO 53 GPIO 54
AIO2 GPIO 59 GPIO 52 GPIO 48 GPIO 47
AIO3 GPIO 44 GPIO 49 GPIO 45 GPIO 46
AIO4 GPIO 43 GPIO 42 GPIO 40 GPIO 41

Gain configuration

The gains that can be achieved through the GPIO configurations are shown in the table below:

DIV GAIN1 GAIN2 GAIN3 Total gain Max voltage
1 0 0 0 0.075853342 24.000
1 1 0 0 0.090525168 19.291
1 0 1 0 0.11416311 15.173
1 1 1 0 0.128834937 13.404
1 0 0 1 0.222571605 7.668
1 1 0 1 0.237243431 7.182
1 0 1 1 0.260881373 6.528
1 1 1 1 0.275553199 6.174
0 0 0 0 0.458273599 3.820
0 1 0 0 0.546914527 3.175
0 0 1 0 0.689724912 2.497
0 1 1 0 0.77836584 2.207
0 0 0 1 1.344682881 1.262
0 1 0 1 1.43332381 1.182
0 0 1 1 1.576134194 1.074
0 1 1 1 1.664775122 1.016

For maximum precision in a given application, choose the gain configuration closest to the application's maximum voltage while ensuring that the highest expected voltage at the pin is equal or greater than the application's maximum voltage. If the voltage at the ADC pin exceeds the maximum voltage, saturation will occur and the ADC will output the maximum value.

ADC readings

The ADC values can be obtained by reading the corresponding files as shown below:

/sys/bus/iio/devices/iio:device0/<AIO file>

The following table shows the file to read the corresponding ADC input:

Input AIO file
AIO1 in_voltage3_raw
AIO2 in_voltage2_raw
AIO3 in_voltage1_raw
AIO4 in_voltage0_raw

The actual voltage on the ADC pin is computed using the following equation:

\text{Vin} = \frac{\frac{\left( \text{adc}_{\text{reading}}*1.85 \right)}{4096}}{\text{total}_{\text{gain}}}

Where:

Vin: Voltage at the ADC microcontroller pin
adc_reading: value read form AIO the file
total_gain: configured gain of the ADC channel

ADC as a current loop (4-20mA) sensor input

All analog inputs can be used as a current loop (4-20mA) sensor input. The input can be used with either an external or internal input resistor. The internal resistor has a value of 100Ω.

The internal resistor can be activated with GPIOs. The GPIO should be set as output and the output set as a logical “1”. The GPIO pins corresponding to the internal resistor of each ADC input is shown below:

Analog Input GPIO pin
AIO1_4-20MA GPIO68
AIO2_4-20MA GPIO69
AIO3_4-20MA GPIO70
AIO4_4-20MA GPIO71

By default, these GPIOs have already been exported, configured as output and their value set to logical “0” (disabled).

With the internal 100Ω resistor activated, the expected voltage range is

Vmax= 20mA*100 \Omega

The closest gain that will maximize the resolution a current loop sensor is 0.78005. The GPIO configuration required to obtain the desired gain is illustrated in the table below.

Pin Value
AIOx_4-20MA 1
DIV 0
GAIN1 1
GAIN2 1
GAIN3 0

ADC Example

The following script configures AIO2 input for a gain 0.78005 and then reads its value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh

# set variables
AIO2_FILE="/sys/bus/iio/devices/iio:device0/in_voltage2_raw"
DIV_GPIO="59"
GAIN1_GPIO="52"
GAIN2_GPIO="48"
GAIN3_GPIO="47"

# export the GPIOs
echo ${DIV_GPIO} > /sys/class/gpio/export
echo ${GAIN1_GPIO} > /sys/class/gpio/export
echo ${GAIN2_GPIO} > /sys/class/gpio/export
echo ${GAIN3_GPIO} > /sys/class/gpio/export

# set the GPIOs to output
echo out > /sys/class/gpio/gpio${DIV_GPIO}/direction
echo out > /sys/class/gpio/gpio${GAIN1_GPIO}/direction
echo out > /sys/class/gpio/gpio${GAIN2_GPIO}/direction
echo out > /sys/class/gpio/gpio${GAIN3_GPIO}/direction

# set the GPIOs values
echo 0 > /sys/class/gpio/gpio${DIV_GPIO}/value
echo 1 > /sys/class/gpio/gpio${GAIN1_GPIO}/value
echo 1 > /sys/class/gpio/gpio${GAIN2_GPIO}/value
echo 0 > /sys/class/gpio/gpio${GAIN3_GPIO}/value

# read the value of AIO2
cat ${AIO2_FILE}

LEDs

LEDs on the BrioSens Gateway are controlled via the standard sysfs GPIO interface or via the BLink RestAPI.

LED GPIO #
User Green 124
User Red 125

LEDs Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Export the GPIO and configure it (this only need to be done once per boot-up)
echo 125 > /sys/class/gpio/export

echo out > /sys/class/gpio/gpio125/direction

# Turn on the LED
echo 1 > /sys/class/gpio/gpio125/value

# Turn off the LED
echo 0 > /sys/class/gpio/gpio125/value

Wi-Fi

The BrioSens Gateway offers Wi-Fi support through the Linux WPA supplicant. wpa_supplicant is a cross-platform supplicant with support for WEP, WPA and WPA2.

Warning

WEP is supported but it’s not safe since the encryption key is static. WEP is considered deprecated for that reason.

Discovering the networks

To enable the WiFi, use the following command:
ifconfig wlan0 up

To disable the WiFi, use the following command:
ifconfig wlan0 down

To scan for any wireless access points, use the following command:
iwlist wlan0 scan

The output will contain a list of all the discovered networks. Each line will correspond to a network as shown below: ESSID: “NETWORK_NAME” Where NETWORK_NAME corresponds to the name of the discovered wireless networks.

Configuring the wpa-supplicant

The ssid and password fields must be modified in the wpa_supplicant.conf file located in /mnt/storage/.

If the SSID is hidden, an additional option (scan_ssid) may help with the connection.

Once configured, disable and re-enable the Wi-Fi interface using the commands in the previous section. Alternatively, the BrioSens Gateway can be rebooted to connect automatically.

Once connected, the IP address can be retrieved using the ifconfig command.

Bluetooth

The Bluetooth module on the BrioSens Gateway offers Bluetooth 4.1 Compliance and Bluetooth LE support.

On the BrioSens Gateway, the Bluetooth module is controlled as two services:

  • bluetooth-enable.service: manages power and activation of the Bluetooth module.

  • bluetooth.service: running Bluetooth service (device driver)

By default, the services controlling the Bluetooth module are enabled and started. To reduce energy consumption, the Bluetooth module can be powered down by stopping the bluetooth-enable.service.

To develop applications using the Bluetooth module, refer to the qt bluetooth examples section.

Cellular connectivity

The BrioSens Gateway uses the BitPipe™ USB interface to create a standard Network adapter. Depending on the onboard BitPipe™ model, different protocols can be used: PPP, ECM and NCM. For each protocol, a Linux script is available to easily establish a cellular connection. Refer to the Application Note AN0031 (Using USB Interface on BitPipe™) to obtain the list of supported protcols and scripts for each BitPipe™ model. The Application Note also contains instructions to explain how to use the scripts.

Note that the Application Note uses “BPxx” to refer to the different BitPipe™ models. BPxx refers to the specific BitPipe™ radio in the BrioSens Gateway and can be found in the BrioSens reference number. For example, BrioSens BSNS-43G1-US-BUWX uses BitPipe™ BP43G1.

By default the BrioSens Gateway has a systemd service called bitpipe.service that will handle the cellular connection according to the configured APN. This APN can be set through the Wi-Fi dashboard or via the file /mnt/storage/apn.config.

Humidity and Temperature Sensor

The BrioSens has an integrated high accuracy humidity and temperature sensor. The SI7006-A20 sensor is connected to the processor through the I2C-0 bus.

Below are the sources of si7006-a20-tool.c which opens the I2C bus and then performs humidity and temperature readings.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*

si7006-a20-tool
RH:23.80
TC:29.17
RH Stands for: Relative Humidity
TC Stands for: Temperature in Celcius
*/

#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>

#define I2C_BUS "/dev/i2c-0"
#define SI7006_A20_ADDR 0x40
#define SI7006_A20_REL_HUMIDITY_CMD 0xF5
#define SI7006_A20_REL_HUMIDITY_RATIO 125.0
#define SI7006_A20_REL_HUMIDITY_OFFSET 6.0
#define SI7006_A20_TEMPERATURE_CMD 0xF3
#define SI7006_A20_TEMPERATURE_RATIO 175.72
#define SI7006_A20_TEMPERATURE_OFFSET 46.85
#define MAX_16BIT_WORD_VALUE 65536

void main()
{
    // Create I2C bus
    int file;
    char *bus = I2C_BUS;

    if((file = open(bus, O_RDWR)) < 0) {
        printf("Failed to open the bus. \n");
        exit(1);
    }

    // Get I2C device
    ioctl(file, I2C_SLAVE, SI7006_A20_ADDR);

    // Send humidity measurement command
    char config[1] = {SI7006_A20_REL_HUMIDITY_CMD};
    write(file, config, 1);

    sleep(1);

    // Read 2 bytes of humidity data
    char data[2] = {0};
    if(read(file, data, 2) != 2) {
        printf("Error : Input/Output error \n");
    }
    else
    {
        // Convert the data
        float humidity = ((((data[0] << 8) + data[1]) * SI7006_A20_REL_HUMIDITY_RATIO) / (float)MAX_16BIT_WORD_VALUE) - SI7006_A20_REL_HUMIDITY_OFFSET;

        printf("RH:%.2f\n", humidity);
    }

    // Send temperature measurement command
    config[0] = SI7006_A20_TEMPERATURE_CMD;
    write(file, config, 1);

    sleep(1);

    // Read 2 bytes of temperature data
    if(read(file, data, 2) != 2)
    {
        printf("Error : Input/Output error \n");
    }
    else
    {
        // Convert the data
        float cTemp = ((((data[0] << 8) + data[1]) * SI7006_A20_TEMPERATURE_RATIO) / (float)MAX_16BIT_WORD_VALUE) - SI7006_A20_TEMPERATURE_OFFSET;
        printf("TC:%.2f\n", cTemp);
    }
}