Welcome on PLAY Embedded

On PLAY Embedded you can find useful resources to getting started with embedded systems: media, examples and accurate descriptions are also provided. Come on, learn by doing!

Testing a WeSU in everyday life

1 Introduction

In this article, we will use a WeSU in some daily common scenarios. In this way, we will propose some case of use of wearable device, testing also its mechanical robustness and its sensitivity.

For our tests we will use the remote data capture feature provided by the smartphone app: this is very useful because it allows to save data and send them to an email address allowing offline post processing. Before starting each test, we need to pair WeSU and our smartphone using bluetooth: launch the application (ST WeSU) then click on START SCANNING (see Fig. 1).

If the procedure will be successful the WeSU will appears in the list of detected Bluetooth nodes near a black double check mark. To start recording data, we have to click on START LOGGING.

WESU bluetooth coupling
Fig.1 – The Correct bluetooth coupling between the WeSU and the smartphone.

The application creates a separate log file for each of the measured data: Pressure, Temperature, Gyroscope, Accelerometer, Pedometer, Battery Level, Magnetometer, MEMS sensor fusion data.

The various measurements allow us to perform tests in several real life applications. Following the descriptions of the tests listed below you can replicate them or just take inspiration to make your own application.

2 Managing gathered data

In our experiments we will gather a lot of data which must be interpreted and thus commented. To do this, it is a good idea to use a spreadsheet program like Excel or Libre Office Calc. In this paragraph, we will see how to import data and how the spreedsheet provided by our WeSU is organised.  Starting from them we will also create some charts. If you are already familiar with that just jump to the chapter three.

2.1 Importing from spreedsheet

2.1.1 Importing data in Excel

It is possible to import data in an Excel using the following procedure:

  1. Click File->Open in the menu, choosing All file types and select the csv file;
  2. Select the first column, click the tab named Data and select the option Text to Columns;
  3. In the window named Convert Text to Columns Wizard, choose Bordered data and click Next;
  4. In the next window choose the comma as data delimiter and and click Next;
  5. Finally choose the general data format and proceed.
2.1.2 Importing data in Libre Office Calc

It is possible to import data in an LibreOffice Calc using the following import procedure:

  1. Open the csv with LibreOffice Calc;
  2. In the newly opened windows choose comma as separator and click ok.

2.2 Spreadsheet explained

WESU data in spreadsheet
Fig.2 – The temperature values recorded by the WESU and imported in the spreadsheet.

Once you have imported data into the spreadsheet you will see table having at least 5 columns. The columns are organised in this way:

  1. HostTimestamp, which is the time counted since the beginning of log expressed in ms;
  2. NodeName, which is the name of the WeSU connected to the App through Bluetooth (in our case is 3CB08C);
  3. NodeTimestamp, which is the systick of WeSU;
  4. RawData, which is the raw data read from MEMS;
  5. Temp (°C), which is the temperature values expressed in Celsius degrees.

Note that if we are going to measure more data we would see some additional columns.

2.3 Plotting data

To quickly analyse the data acquired we are going to create a graph, plotting HostTimestamp on the x-axis and Temp (°C) on the y-axis. To make the graph we have to:

  1. move one of the column in order to have the two interested column in a columns side by side;
  2. replace the decimal point with a comma just using the “Search and replace” function (note that this step depends on your international setting in the control panel).
  3. Select both columns and choose the line XY graph, the first column will be used for the values of the x-axis and the second one for the values of the y-axis.

If you have done everything right, you will get a graph like the one shown in the figure 3.

3 Heat under control

3.1 The experiment

In our first test we will control the temperature, simulating how to control the cold chain for food preservation. As said, we will get data through the control Application on the smartphone. So, we will simulate an unwanted thermal shock raising the temperature of the environment. To do this we will:

  • use a normal household freezer to take WeSU at a temperature below 0° C;
  • use an hair dryer to raise up the WeSU measured temp in a short range time: this will simulate the thermal shock;
  • re-use the freezer to simulate the reverse to the normal situation.

This measurement could be used to detect a failure and consequently an irreparable alteration of the food. Another scenario could be the monitoring of kids or pets: with some changes in the code of the microcontroller, this feature could also be used to automatically trigger an alarm when the temperature exceeds a preset threshold.

3.2 Preliminary notes

WeSU has several chip which can operate in different condition. Before to start we should take a look to their reference manual to figure out the effective temperature operating range of the WeSU. Reading, we can figure out that:

  • The magnetic sensor (LIS3MDL) and the inertial module (LSM6DS3) can operate over a temperature range from -40° to +85° C.
  • The pressure sensor (LPS25HB) can operate in a range from -30° to +105° C.
  • The gas gauge (STC3115) has an internal temperature sensor which works in range from -40° C to +125° C  having a resolution of 1°C.

Crossing these notes, it should be clear we can operate in a range from -30° C to + 85° C. We should notice that a normal household freezer usually reaches an average temperature of -18° C. Before to start the measurement, we will wait that WeSU measurement is stable to the environment temperature (in our case -8° C).

During measurement, remember to keep open the door of the freezer: freezers often have a metal surface which act as a Faraday cage. This can jam the Bluetooth signal.

Remember that the application ST WeSU will sent us a file cvs (comma-separated values spreadsheet) when stop the data logi (for more info take a look to Review of WeSU: a development board for wearable applications).

3.3 Test results

Starting from data gathered we have created a chart using the previous explained method: we can clearly notice a temperature peak. This peak could be revealed through software and consequently software can implement countermeasures.

Fig.3 – Remote temperature acquired by the WeSU.

Note that, we can use the data and post process it to achieve more information:as example we can calculate additional parameters like the slope, the mean or the minimum and maximum.

4 A bike ride to collect  pressure data

4.1 The experiment

In the second test, we will evaluate the accuracy of the barometer of WeSU collecting the environment pressure during a bike ride and compare the result with altitude retrieved on the internet. There are several websites to calculates the map total ascension, starting from a selected route, as example Sport Route Planner. It also allow to create a graph of this parameter along an estimated travel time.

4.2 Preliminary notes

The barometer sensor (LPS25HB) has a range of 260 hPa up to 1260 hPa, with a sensitivity in high resolution of 0.01 hPa. To properly stimulate it, before start the test we suggest to plan a route with a series of climbs and descents.

Remember to save the altitude graph generated for our planned route. We need it for the following steps of the test.

In our case the altitude graph associated to our planned route is shown in the following image:

Altitude differences of the path chosen
Fig.4 – Altitude profile of the path chosen.

Before to start the ride we have placed the WeSU in a small bag attached to the bike handlebar.

4.3 Test results

Back home from our test ride, we have import the barometric data to the spreadsheet and plotted the collected data on a graph obtaining the Fig.5.

Pressure graph WESU
Fig.5 – The pressure graph from WeSU Data

To obtain the altitude values we use the formula to find the atmospheric pressure at a given altitude calculating it’s inverse:

Altitude =\frac{ (1 - (\frac{Pressure}{101325})^{(\frac{1}{5,25588})})}{0,0000225577}

4.3.1 Note to calculate the altitude with the spreadsheet

To calculate the altitude values we have to apply the previous inverse formula to the our pressure data. Doing that, we should pay attention to some details.

  • The collected pressure data are expressed in millibars instead the pressure in the formula is expressed in Pascal. Since 1 mbar = 1hPa = 100 Pa, we need to multiply each pressure value for the factor 100.
  • The air pressure at altitude of 10 km is 26436 Pa, so to verify the correction of the inverse formula we can insert this value in our spreadsheet to perform a check. If there aren’t syntax errors, the output must be 10000 meters.
  • In case of syntax error pay attention to parenthesis.
Altitude graph WESU
Fig.6 – The altitude graph from WeSU Data.





5 Using WeSU as a personal trainer

5.1 The experiment

Another nice test consist to insert the WeSU into a punching bag to monitor the frequency and intensity of hits during a training session. We have record some different sequences of hits and tried to determine each sequence, analyzing the graph of the collected accelerations .

5.2 Preliminary notes

The inertial module (LSM6DS3) is able to sense a range of accelerations from ± 2g to ± 16 g. It has 3 degrees of freedom, to detect the acceleration along x, y and z axes, but we only use the accelerations along x. We have record 3 different sequences of hits during a 2-minute workout:

  • The first sequence is made by low intensity hits;
  • The second one is made by hits at higher intensity. The third sequence is made by hits at the maximum intensity;
  • The final sequence is made by random hits.

If we have no way to open the punching bag we can attach the WeSU on the bottom with a fabric tape. We can also use a large sofa pillow.

5.3 Test results

From the graph of the collected data we clearly see the acceleration peaks: this correspond to the intensity of the hits on the punching bag. Instead the time distance between the peaks corresponds to training frequency. In the last part of the graph we easily distinguish the hits of the three previous sequences, as we can see in the next figure.

Sequences of hits acquired by the WeSU
Fig.7 – Sequences of hits acquired by the WeSU

So the WeSU can be used to monitor the improvements of  the training in any combat sport that requires kicks or punches.

6 No fear of water: another test to try

For the last test we suggest to use the WeSU to monitor of data during a swimming session, inspiring to XMetrics, a monitor for the activities of the swimmers. This device has the same sensors of the WeSU and report the collected data in a dedicated application.

To make this test we need a waterproof case for the WeSU. We could use some freezer bags, and use more than one like a matriosca dolls. After the sealing we can it inside the swimming cap and start a training session. The collected data can then be elaborate with a dedicated software and be used to evaluate the executed performance.

If you try this test, you have to avoid interrupting the bluetooth connection between WeSU and your smartphone. So we suggest to swim near the edge of the pool with someone on ground holding the phone and follows our movements.

7 Our conclusions

The WeSU platform, in his evaluation form is already suitable for very useful and practical applications, that have nothing to envy with that devices specifically designed for these purposes. The chance to edit code and act on it can completely change our perspectives opening an entire world of possible applications. Indeed, you could create the specific firmware for the wearable application and WeSU is a cheap way to test it before to create a dedicated hardware. Now is your turn: unleash your imagination.

Detecting obstacles using an ultrasonic sensor HC-SR04

Detecting obstacles using an ultrasonic sensor HC-SR04

1 HC-SR04: a cheap ultrasonic sensor

1.1 Description

HC-SR04 front view
Fig.1 – An HC-SR04 seen from front side.

HC-SR04 is a commonly used ultrasonic sensor which is capable to detect obstacles in a range of 2-300cm. The sensor looks like a small PCB having two metal cylinders on the front-side and a small circuit on the back-side (see Fig.1).

1.2 Documentation

In this article we will provide a simple demo to use HC-SR04. This requires a preliminary read of the sensor user manual:
HC-SR04 User Manual

1.3 Pinmap description

The sensor has 4 PIN:

  1. VCC, which must be connected to 5V;
  2. Trig, which is an input PIN to trigger the measurement;
  3. Echo, which is an output PIN which sent out a square wave;
  4. GND, which must be connected to ground.

Note that user manual specifies which GND must be connected first since a floating 5V could permanently damage the sensor.

2 How it works

The two cylinders are actually an ultrasonic receiver (R) and an ultrasonic transmitter (T) which are driven by the circuitry. The working principle is quite simple: when triggered the transmitter shoots some pulses. When sound encounters an obstacle it is echoed back and detected by the receiver. continue reading…

How to drive a HD44780 with I2C backpack with a STM32

How to drive a HD44780 with I2C backpack with a STM32

1 I2C backpack advantages

The HD44780 is a de-facto standard controller for display. We have already use it providing a source code to use a 16×2 LCD with a STM32. In this article we will step over introducing an I2C backpack for that display. Of course we will explain how to edit old code in order to get it work with this new hardware configuration.

Even if it is still popular, this controller was made commercially available in the late eighties. At that time serial communications were not so widespread because their were costly and involved constraint about clock speed. Because of that, the HD44780 comes with a parallel bus and requires up to 16 lines to work (8 for data, 3 for handshake, 2 for supply, 1 for contrast and 2 for backlight). With fastest MCU it is possible to use the 4-bit mode and with a couple of welds and a potentiometer we can reduce to 9 the required lines.

Nowadays, serial communication are largely used and SIPO (Serial-in Parallel-Out) converters are very cheap. Using a SIPO, it is possible to drive a HD44780 with less wires accepting a small extra charge due to additional hardware. Today it is possible to buy our display with the SIPO already mounted with a small extra amount (about 3.90 USD instead of 2.80 USD considering a 16×2 LCD).

The most used solution is based on PCF8574A, an I2C I/O expander from NXP. This solution is available as a backpack ready to be  soldered on our display. The backpack reduce the number of wires to 4: 2 for supply and 2 for the I2C communication. continue reading…