Introduction: Interface ADXL335 Sensor on Raspberry Pi 4B in 4 Steps
In this Instructable we are going to interface an ADXL335 (accelerometer) sensor on Raspberry Pi 4 with Shunya O/S
Step 1: Install Shunya OS on Raspberry Pi 4
You will need a laptop or computer with a micro SD card reader/adapter to load the micro SD card with Shunya OS.
- Download Shunya OS from the official releas e site
- Shunya OS guys have a decent tutorial on Flashing Shunya OS on Raspberry Pi 4.
- Insert micro SD card into Raspberry Pi 4.
- Connect mouse & keyboard to Raspberry Pi 4.
- Connect Monitor to Raspberry Pi 4 via micro-HDMI
- Connect the power cable and Power ON the Raspberry Pi 4.
The Raspberry Pi 4 should boot up with Shunya OS.
Step 2: Install Shunya Interfaces
Shunya Interfaces is a GPIO library for all boards supported by Shunya OS.
To install Shunya Interfaces we need to connect it to the wifi with internet access.
1. Connect to the wifi using the command
2. Installing the Shunya Interfaces is easy, just run the command
$ sudo apt install shunya-interfaces
Step 3: Sensor Connections
ADXL335 is an analog sensor, but Raspberry Pi 4 is a digital device. Hence we need a converter PCF8591 (ADC) which converts all the analog values given by ADXL335 to digital values understandable by the Raspberry Pi 4.
The circuit diagram is given in the image above.
- Connect SDA & SCL pins on PCF8591 to pin 3 & pin 5 on the Raspberry Pi 4.
- Connect VCC & GND on PCF8591 to pin 4 (5V) & pin 6 (GND) on Raspberry Pi 4.
- Connect VCC & GND on ADXL335 to VCC & GND on PCF8591.
- Connect Ain1 on PCF8591 to X on ADXL335.
- Connect Ain2 on PCF8591 to Y on ADXL335.
- Connect Ain3 on PCF8591 to Z on ADXL335.
Step 4: Example Code
- Download the code given below.
- Compile it using the command
$ gcc -o adxl335 adxl335.c -lshunyaInterfaces
- Run it using the command
$ sudo ./adxl335