DesignSpark Electrical Logolinkedin
Menu Search
Ask a Question

20 May 2020, 9:48

Use Digital Discovery and Python to test MEMS Accelerometer

A microelectromechanical system (MEMS) accelerometer is a device that can measure acceleration on one or more axes. It can also be used to detect the orientation of your device relative to the earth’s gravity. MEMS accelerometers can be found in industrial and mobile applications, aeronautical instruments and tactical guidance systems. You can test MEMS accelerometer with Digilent Digital Discovery (136-8070) when you prototype your systems.

Digilent Digital Discovery is a combined logic analyzer and pattern generator instrument that was created to be the ultimate embedded development companion. The digital inputs and outputs can be connected to a circuit using simple wire probes or breadboard wires. The Digital Discovery high-speed adapter and impedance-matched probes can also be used to connect and utilize the inputs and outputs for more advanced projects.

WaveForms is our powerful multi-instrument software application for Digital Discovery. It is compatible with Windows, Mac, Linux and Raspberry Pi 4. Users can use Javascript in WaveForms Script Editor to control the Digital Discovery. The WaveForms Software Development Kit (SDK) provides access to a public application programming interface (API) that gives users the ability to create custom PC applications.

What you'll need for the test

  • Digilent Digital Discovery
  • WaveForms Software
  • A computer with a USB port to run the software
  • Python Software with Python 2.7 interpreter and matplotlib
  • An accelerometer with an I2C interface (In this example we use the LIS35DE mounted on a KAmodMEMS2 module)

Set Up the Test

1. Connect GND and Vdd of the sensor to the Digital Discovery's GND and VIO pins, respectively and make the following connections from the KAmodMEMS2 I2C interface to Digital Discovery

  1. CS pin to Vdd
  2. SDO pin to GND
  3. SDA and SCL lines to DIO33 and DIO32 respectively

2. Load WaveForms SDK 

3. Use Python script to enable the 3.3V power supply from Digital Discovery to the KAmodMEMS2 module and configure the I2C interface. To configure the demo, the user needs to set the operating frequency of the bus and select which pins of the Digital Discovery should be used.

# set I2C frequency and pins
dwf.FDwfDigitalI2cRateSet(hdwf, c_double(1e5)) # 100kHz
dwf.FDwfDigitalI2cSclSet(hdwf, c_int(32-24)) # SCL = DIO-32
dwf.FDwfDigitalI2cSdaSet(hdwf, c_int(33-24)) # SDA = DIO-33
 

4. Use the Python script to read the data and update graphs as long as the plot window is open. Each read operation from the KAmodMEMS2 module is a write-read operation on the I2C bus. A device address is set for complete operation and WaveForms SDK automatically maintains the R/W bit. Two arrays are used to write and read data, and the user specifies how many bytes should be written, and, after repeated start, read. In this test, only one byte is written. The register address is combined with a bitmask indicating that the sensor should increment the register address after each byte is read from the bus. Then, 5 bytes are read from the subsequent registers beginning at the OUTX register. The read data contains 3 bytes with X, Y and Z acceleration data represented in two’s complement and two dummy bytes.

dwf.FDwfDigitalI2cWriteRead(hdwf, c_int(address << 1), (c_ubyte*1)(LIS35DEreg.REG_OUTX | LIS35DEreg.READ_INC), c_int(1), rgRX, c_int(5), byref(iNak))

 

5. Run the script and test the KAmodMEMS2 module. The upper part of the window presents live XYZ acceleration from the sensor as a function of time, while the lower part presents the actual X and Y acceleration as a blue asterisk (*)

Learn the test step by step and download the source code in Digilent Wiki Page.

Love learn engineering in hands-on approach. Interested in new technology. Work in Digilent as International Sales and Distribution Manager.

20 May 2020, 9:48