Read Accelerometer Data in Python

Read Accelerometer Data in Python

View the app user interface

Running tests with an accelerometer? Dash DAQ gives you the components you need to write rich, flexible GUIs for interfacing with your instruments in Python.

Here at Plotly, we wrote an app to facilitate the control of a Phidgets 1041_0B accelerometer. Try out our demo app online, and check out the video demo below ūüĎÄ

 

To write the app, first we import the general dash, Phidgets22, and dash_daq Python libraries:

Our app layout represents an accelerometer control panel, with the device information displayed at the top. In the simulation app, a Dash DAQ ToggleSwitch component turns on the simulation.

We create the toggle switch:

By default, calculations for motion along the x, y, and z axes are generated every 1,000 milliseconds. This time interval is defined in the Interval component in the dash_core_components module.

In the mock app, a Dash callback is formed using this connection¬†element, changing the interval to run every one hour, simulating a disconnection with a device. The callback retrieves the value from the toggle switch (“Connected” or “Disconnected”), directly affecting the Interval¬†element, labeled stream.

The live hardware app, by contrast, features a Dash DAQ Indicator component that will light up when Dash DAQ is connected to the device.

The app can also directly modify hardware settings on the device. Using Dash DAQ Slider components, we can easily and intuitively adjust the change interval and data interval parameters, using API calls within Dash callback.

With a corresponding Dash DAQ LEDDisplay component, users can keep track of these adjustments easily.

Using the setAccelerationChangeTrigger method in the following callback, we are able to select the device’s change interval with the Phidgets22 API. The slider component’s value is then returned to the LED display component.

The data retrieved by the accelerometer is displayed by Dash DAQ Gauge components. The gauges are defined as the following:

The gauges’ values are updated using an Interval¬†component:

Upon every 1,000 millisecond interval, the getAcceleration method is called, and its first index is returned to the gauge. Similar processes apply to all the gauges.

You can try out the demo app for yourself.

Purchase a Dash DAQ license to access the full source code for this app, and others, and turn your Python skills into powerful, flexible GUIs for your testing and measurement devices.