visualisierung
Deutsch   English   

13. VISUALIZING SENSOR DATA

The examples in this chapter can currently only be run using https://temp.webtigerpython.ethz.ch/.

 

YOU WILL LEARN...

 

how to use the additional module mbsensor to display measurement data from the micro:bit sensors graphically and export the data as a CSV file for further processing on your computer.

 

 

VISUALIZING ACCELEROMETER DATA

 

As you learned in Chapter 3, the built-in accelerometer measures the x, y, and z components of acceleration. The x component indicates the sideways tilt, the y component the forward tilt, and the z component the gravitational acceleration of the micro:bit.

After importing the mbsensor module, you can use the command logged_accelerometer.get_x()to display the x values graphically in a coordinate system.

 
 

Program:

from microbit import *
from mbsensor import *

repeat:
    logged_accelerometer.get_x()
    sleep(200)
► Copy to clipboard

If your micro:bit is connected to your computer via a USB cable while the program is running, the x values are continuously displayed in the WebTigerPython graphics window, both as a graph in a coordinate system and in a table.

You can stop the measurement by clicking the Disconnect device icon .

With the command logged_accelerometer.get_values(), you can visualize all three measured values simultaneously.

Program:

from microbit import *
from mbsensor import *

repeat:
    logged_accelerometer.get_values()
    sleep(200)
► Copy to clipboard

 

 

EXPORTING MEASUREMENT DATA AS A CSV FILE

 

Run the previous program again. By default, the MONITOR view is selected, where the data is displayed graphically. Click OVERVIEW to access additional functions. By clicking CSV, you can save the measurement data in CSV format to a directory of your choice on your computer. The data can then be processed further, for example using Excel.

Click PREVIEWto inspect the data before exporting it. You can delete data series that you no longer need by clicking DELETE.


 

 

REMEMBER...

 

The mbsensor module provides an easy way to visualize sensor data from the micro:bit. With the command logged_accelerometer.get_values(), you can display the measured values of the accelerometer graphically. Commands for supporting additional micro:bit and mbRobot sensors can be found in the documentation.

The sensor data can be saved on your computer in CSV format and processed further, for example using Excel.

 

 

ZUM SELBST LÖSEN

 

 

1.

The mbsensor module provides the following commands for visualizing data from the magnetic field sensor (compass):

logged_magnetic_field.get_x() x-component of the magnetic field in microtesla
logged_magnetic_field.get_y() y-component of the magnetic field in microtesla
logged_magnetic_field.get_z() z-component of the magnetic field in microtesla
logged_magnetic_field.get_values() x, y, and z-components in microtesla
logged_magnetic_field.get_strenght() magnetic field strength in microtesla

Create several graphs and save the data in CSV format.

   

2.



3.