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_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
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
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.
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
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.