The INS! ASM330LHH IMU Interfacing With Raspberry Pi Zero
by Aniket_Kulkarni in Circuits > Raspberry Pi
1729 Views, 4 Favorites, 0 Comments
The INS! ASM330LHH IMU Interfacing With Raspberry Pi Zero
Hello Everyone!
About ASM330LHH - STEVAL MKI193V1:
It is the best IMU I have come across, read about it before you start working.
The ASM330LHH is a system-in-package featuring a high-performance 3-axis digital
accelerometer and 3-axis digital gyroscope. This device is suitable for telematics and dead-reckoning applications as well as a vehicle-to-vehicle (V2X) and impacts detection as a result of its high stability over temperature and time, combined with superior sensing precision. The event-detection interrupts enable efficient and reliable motion-activated functions, implementing hardware recognition of free-fall events, 6D orientation, activity or inactivity, and wake-up events. Up to 3 kbytes of FIFO allows overall power saving of the system. Like the entire portfolio of MEMS sensor modules, the ASM330LHH leverages the robust and mature in-house manufacturing processes already used for the production of micromachined accelerometers and gyroscopes. The various sensing elements are manufactured using specialized micromachining processes, while the IC interfaces are developed using CMOS technology that allows the design of a dedicated circuit which is trimmed to better match the characteristics of the sensing element
The ASM330LHH has a full-scale acceleration range of ±2/±4/±8/±16 g and a wide angular rate range of ±125/±250/±500/±1000/±2000/±4000 DPS that enables its usage in a broad range of automotive applications. All the design aspects of the ASM330LHH have been optimized to reach superior output stability, extremely low noise, and full data synchronization to the benefit of sensor-assisted applications like dead reckoning and sensor fusion.
This makes it truly an Industry Grade Sensor.
Downloads
Supplies
Make sure you have the following supplies before you begin with the project:
Tap on the supply to order one for yourself. I have made it easy for you!
- 1 pc x ASM330LHH IMU
- 1 pc x Raspberry Pi Zero
- 1 pc x Power Adapter or Power Bank (5v, 2A minimum)
- 1 pc x SD-card (Min 8GB)
- 1 pc x Breadboard
- 1 pc x 10uf Capacitor
- 1 pc x 0.01uf Capacitor
- 20 pcs x Jumper Cables
Setting Up Your Raspberry Pi Zero!
The Raspberry Pi Headless Setup:
A computer setup without a monitor is said to be running headless. You might want to do this if you're installing your Pi into some project, or want to keep power-usage and cost minimal. This kind of setup is what the Pi Zero W was built for. The idea is that you can still access your Pi's terminal interface over your network using a protocol called SSH. This is what made me to chose Raspberry Pi!
All we need to do is get our Pi set up with the right WiFi credentials and we'll be able to remotely access it through a terminal program as if we were using the terminal Pi's own desktop. What's more, we'll get our Pi connected to WiFi without ever having to plug in a monitor, keyboard, or mouse to configure it.
Downloading OS for our Raspberry Pi:
Access different Raspberry OS images and download from the official link: https://www.raspberrypi.org/software/operating-sys...
To burn an OS image into an SD card refer to the link:
https://www.raspberrypi.org/documentation/installa...
I would personally suggest you using Raspberry Pi Imager for this task.
Trust me, it made my work damn easy.
Accessing via SSH:
Now,
- Insert your SD card with Raspbian into it into your computer and open the SD card from your file explorer - the drive will be labeled boot.
- Within the boot directory, Right-Click > New > Text Document and rename the document to wpa_supplicant.conf - Make sure that you change the file extension from .txt to .conf - You will be prompted to confirm the extension change.
- With the empty file created, Right-Click on it and select open. You may be prompted to select a program you'd like to open the file with - just choose Notepad.
- This is where we enter our WiFi details. Enter the following text into the file, replacing the placeholder text with your own details, including country. I have attached a screenshot of the same. Refer same.
- By default, the current version of Raspbian has SSH disabled. We're going to enable it here.
- Create an empty file in the boot directory called ssh Make sure that the file has no file extension, i.e. remove the .txt if you created the file by selecting New > Text File.
- Your Pi is now ready for startup. Eject the SD card from your computer and insert it into your Pi. Power up your Pi (I recommend an official power supply) and wait a few moments for the initial boot to complete. On your computer, open up PuTTY.
- If you don't have PuTTY installed, sharing a link here:
- PuTTy - official website
- We know that the default hostname (the name of the machine) for a fresh Raspbian install is raspberrypi, so in the Host Name, (or IP address) field enter "raspberrypi".
- This searches for machines on that name on the local network. Once a connection is established, you'll be prompted by PuTTY to accept the connection to the new machine.
- You should see a black terminal prompting for a login. Enter the default username: "pi" and the default password: "raspberry"
You are now ready to use Terminal on RaspberryPi with a successful Headless Setup.
The WPA-Supplicant File -(For accessing the Network) Fill in your network deatils before saving the file into boot folder. # -------------------------------------------------------------- <pre>country=IN ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="MyWiFiNetwork" psk="aVeryStrongPassword" key_mgmt=WPA-PSK }<br># --------------------------------------------------------------- # EOF
Downloads
Interfacing IMU(ASM330LHH) With Raspberry Pi Zero!
Actual Interfacing:
For me, Interfacing IMU with Raspberry was the toughest part.
Literally, even today we have no information or blog regarding this on the internet today.
This made me write a blog and help you and make your task easy further.
- The IMU supports both I2C as well SPI protocol for communication. I made I2C my choice. It is basically a two-wire protocol that uses one line for synchronization and the other for bidirectional data. More information on I2C (click here).
- I went through the datasheet in detail before finding out the final connections, made some experiments, and then noted the final design.
- The Raspberry Pi has the inbuilt pull-up registers required for standard I2c bus speed. Adding some more would bring up errors.
- The MEMS on IMU is affected by static discharge. Take necessary precautions and avoid touching it with bare hands.
- I have set the LSB of the I2C address as "0", pull up the SDO pin to 3.3V to set it as "1"
- Get ready and bring your breadboard!
- Any faults in connection won't give you results on your terminal. Also giving reverse voltage supply kills the sensor in seconds. Don't forget that the maximum voltage at any pin on the sensor is 3.5V. Refer datasheet attached at the beginning of the instructable.
- Remember to check all the connections as mentioned below thrice before powering up the circuit.
The connections:
- 1. VDD – 3.3 V - (supply)
- 2. VDDIO – 3.3 V - (IO supply)
- 3. SDO – GND - (Set I2C address LSB to 0)
- 4. SDA – SDA1 (Pin 3 Raspberry) - (I2C Data Line)
- 5. SCL – SCL1 (Pin 5 Raspberry) - (I2C Clock Line)
- 6. CS – 3.3 V - (I2C Mode, SPI disabled)
- 7. INT2 -GND - (Disable INT)
- 8. GND -GND - (Common Ground)
- 9. 10uf cap between VDDIO and GND
Executing the Code!
Steps to execute the code:
1. Refer to the attached code (make changes if necessary). Save the code in the working directory.
2. Open terminal. Install packages or run the following commands. (Assuming Python3 is installed)
a. pip3 - sudo apt-get -y install python3-pip
b. smbus - pip3 install smbus
c. serial - pip3 install serial
3. Reboot. Then run the code from the terminal.
4. Voila! You should see the real-time data on the screen.
Refer the code or Download the attached one.# ------------------------------------------------------------------------------# IMU - This code is tested and verified - True# 1st Feb 2021 - Monday# Author - Aniket Kulkarni# ------------------------------------------------------------------------------# Importing Packages:import sysimport timefrom time import sleepimport smbus# ------------------------------------------------------------------------------# Initialising I2C Bus for Communication:print("Aniket Kulkarni")print("This code will give you real time data pulled from IMU Sensor")bus = smbus.SMBus(1)bus.write_byte_data(0x6a, 0x18, 0xe1)bus.write_byte_data(0x6a, 0x10, 0x40)bus.write_byte_data(0x6a, 0x11, 0x40)time.sleep(1)# ------------------------------------------------------------------------------# Function to Pull Data:def getData():bytes = bus.read_i2c_block_data(0x6a, 0x20, 14)# Temperature Data:Temp = bytes[0] | (bytes[1] << 8)# Gyroscope Data:Gx = bytes[2] | (bytes[3] << 8)if(Gx & (1 << 16 - 1)):Gx = Gx - (1 << 16)Gy = bytes[4] | (bytes[5] << 8)if(Gy & (1 << 16 - 1)):Gy = Gy - (1 << 16)Gz = bytes[6] | (bytes[7] << 8)if(Gz & (1 << 16 - 1)):Gz = Gz - (1 << 16)# Accelerometer Data:Ax = bytes[8] | (bytes[9] << 8)if(Ax & (1 << 16 - 1)):Ax = Ax - (1 << 16)Ay = bytes[10] | (bytes[11] << 8)if(Ay & (1 << 16 - 1)):Ay = Ay - (1 << 16)Az = bytes[12] | (bytes[13] << 8)if(Az & (1 << 16 - 1)):Az = Az - (1 << 16)# Get the data on Terminal:# print(" Temp = %.3f " % Temp)# print("\n")# print(" Gx = %.3f " % Gx)# print(" Gy = %.3f " % Gy)# print(" Gz = %.3f " % Gz)# print("\n")# print(" Ax = %.3f " % Ax)# print(" Ay = %.3f " % Ay)# print(" Az = %.3f " % Az)# print("\n")outdata = {"Temp": Temp, "Gx": Gx, "Gy": Gy, "Gz": Gz, "Ax": Ax, "Ay": Ay, "Az": Az}return outdata# ------------------------------------------------------------------------------# Main Block:if __name__ == '__main__':try:while True:print(getData())time.sleep(0.5)except KeyboardInterrupt:sys.exit()# ------------------------------------------------------------------------------# EOF
Downloads
Thank You!
I hope you found my instructable helpful.
Thank you for reading.
This is my first one.
Yes, since I’m a beginner at Raspberry Pi, there are probably loads of people, that can do it far better and quicker and in color, but humor me and let me know what I could have done better in the comments so that I can learn more. Kindly follow and share the instructable with as many as possible.
If possible please leave a comment.
Reach me out by mail for any kind of assistance if required.
And ALWAYS stay fascinated!