Interface ADXL335 Sensor on Raspberry Pi 4B in 4 Steps

by shunyaos4ai in Circuits > Raspberry Pi

4502 Views, 1 Favorites, 0 Comments

Interface ADXL335 Sensor on Raspberry Pi 4B in 4 Steps

IMG_20190718_130738.jpg
IMG_20190718_131446.jpg
IMG_20190718_131524.jpg
IMG_20190718_131458.jpg
IMG_20190718_130645.jpg
IMG_20190718_131516.jpg

In this Instructable we are going to interface an ADXL335 (accelerometer) sensor on Raspberry Pi 4 with Shunya O/S

Supplies

  1. Raspberry Pi 4B (any variant)
  2. Raspberry Pi 4B compliant power supply
  3. 8GB or bigger micro SD card
  4. Monitor
  5. micro-HDMI Cable
  6. Mouse
  7. Keyboard
  8. laptop or another computer to program the memory card
  9. ADXL3355 Accelerometer sensor - Buy
  10. PCF8591 ADC module - Buy
  11. Breadboard
  12. Connecting wires

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.

  1. Download Shunya OS from the official releas e site
  2. Shunya OS guys have a decent tutorial on Flashing Shunya OS on Raspberry Pi 4.
  3. Insert micro SD card into Raspberry Pi 4.
  4. Connect mouse & keyboard to Raspberry Pi 4.
  5. Connect Monitor to Raspberry Pi 4 via micro-HDMI
  6. Connect the power cable and Power ON the Raspberry Pi 4.

The Raspberry Pi 4 should boot up with Shunya OS.

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

$ nmtui

2. Installing the Shunya Interfaces is easy, just run the command

$ sudo apt install shunya-interfaces

Sensor Connections

sample1.png

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.

  1. Connect SDA & SCL pins on PCF8591 to pin 3 & pin 5 on the Raspberry Pi 4.
  2. Connect VCC & GND on PCF8591 to pin 4 (5V) & pin 6 (GND) on Raspberry Pi 4.
  3. Connect VCC & GND on ADXL335 to VCC & GND on PCF8591.
  4. Connect Ain1 on PCF8591 to X on ADXL335.
  5. Connect Ain2 on PCF8591 to Y on ADXL335.
  6. Connect Ain3 on PCF8591 to Z on ADXL335.

Example Code

Selection_038.png
  • Download the code given below.
  • Compile it using the command
$ gcc -o adxl335 adxl335.c -lshunyaInterfaces
  • Run it using the command
$ sudo ./adxl335

Downloads