Example Code for Raspberry Pi-Wakeup Function

Last revision 2026/01/19

Use wake-up function (Only available for Breakout Version).

Hardware Preparation

  • Raspberry Pi 4B(or similar) x 1
  • LIS331HH Triple Axis Accelerometer (Breakout Version) x1
  • Jumper wires x1

Software Preparation

Wiring Diagram

  • Connect the module to the Raspberry Pi according to the connection diagram. The default I2C address is 0x19. Connect the int1/int2 pin of the module to the interrupt pin of the Raspberry Pi.

Other Preparation Work

  1. Enable the I2C interface of the Raspberry Pi. If it is already enabled, you can skip this step. Open Terminal, type the following command, and press Enter:

    sudo raspi-config
    

    Then use the up and down keys to select "5 Interfacing Options", press Enter, select "P5 I2C", and press Enter to confirm "YES". Restart the Raspberry Pi main control board.

  2. To install Python dependent libraries and git, the Raspberry Pi needs to be connected to the Internet. If it is already installed, you can skip this step. In the terminal, type the following commands in sequence, and press Enter:

    sudo apt-get update
    
    sudo apt-get install build-essential python-dev python-smbus git
    
  3. Download the LIS series driver library. In the terminal, type the following commands in sequence and press Enter:

    git clone https://github.com/DFRobot/DFRobot_LIS
    

Sample Code

  • Run the sample code by typing the following commands in the terminal:
    cd DFRobot_LIS/tree/master/python/raspberrypi/examples/LIS331HH
    
    cd wake_up
    
    python wake_up.py
    

Result

  • When the interrupt event occurs, the terminal will print the acceleration data and the mode change (from sleep mode to normal mode).

Was this article helpful?

TOP