Mobile Phone Sensor Data Collection with MATLAB – Update

This week, the practical on data acquisition with LEGO Mindstorms, spectral and 3D cameras and smartphone sensors is running again. A lot has changed in the use of smartphone sensors in recent years, both on smartphones with MATLAB Mobile and on MATLAB Desktop – here is the update!

The goal of the data acquisition lab is to show students how hardware and software can be connected to work together. The software controls the hardware, which sends data back to the software. Decisions are made there, which in turn control the hardware. We used LEGO Mindstorms for this, where there are motors and sensors that can communicate with MATLAB. Not everyone has LEGO Mindstorms available, but most people have a smartphone full of sensors.

Thanks to MATLAB Mobile, these sensors can be read and the data shared via MATLAB Drive. In the MRDAES, there were several examples where the sensors of smartphones were read and the data streamed to MATLAB Desktop. Examples were the MATLAB Mobile GPS Paperchase, a magnetic survey with LEGO Mindstorms (Tronicke and Trauth, 2018), and dip and dip direction with a smartphone (Trauth, 2021). A particularly attractive and popular experiment was the paperchase, where one group of students solved tasks on the university campus while their route and speed was streamed live to the laptop of the second group in the seminar room.

At the time the MRDAES book (Trauth, 2021 was written, smartphones and desktops were connected using the MATLAB Connector, which was discontinued overnight for security reasons. After that, the recommendation was to save the data from the smartphone in the MATLAB Drive and load it from there into MATLAB Desktop. Unfortunately, this did not allow for a live stream; saving and loading only worked with the usual time delay. An alternative was offered by ThingSpeak, as the example of a weather station with MATLAB showed.

The new version of MATLAB Mobile, the MATLAB Support Package for Apple iOS Sensors and the MATLAB Support Package for Android Sensors brings back the popular live stream feature. After installing MATLAB Mobile and setting the necessary permission on the smartphone, navigate to Sensors in the menu of the app. There, change the streaming from local storage to MATLAB. Then click on More and enable sensor access. Further down, the directory on MATLAB Drive is displayed and automatic uploading via Wifi and mobile network is activated.

On MATLAB Desktop, the connection is established using the command

 m = mobiledev

This …

After we have started logging the magnetometer data of the phone on the smartphone, for example, the data is recorded and streamed to MATLAB. We can then access this data using the command

[log, timestamp] = magfieldlog(m)

It is really a live stream of the data, you can access and display the sensor data while you are still measuring for instance within a for loop. Accordingly, the above examples can easily be rewritten to work with the new version of MATLAB Mobile and Desktop.

Examples Mentioned in the Text

MATLAB Mobile GPS Paperchase (11 Nov 2017)

Apple iPhone/MATLAB Mobile/LEGO Mindstorms Scanner (15 Mar 2017)

Smartphone Seismometer using MATLAB (16 Feb 2020)

Dip and Dip Direction using Smartphones (3 Dec 2019)

ThingSpeak IoT Weather Station (11 Mar 2024)

References

Trauth, M.H. (2021) Signal and Noise in Geosciences, MATLAB Recipes for Data Acquisition in Earth Sciences. Springer International Publishing, 544 p., https://doi.org/10.1007/978-3-030-74913-2 (MRDAES).

Tronicke, J., Trauth, M.H. (2018) Classroom-sized geophysical experiments: magnetic surveying using modern smartphone devices. European Journal of Physics, 39, 035806, http://doi.org/10.1088/1361-6404/aaad5b.