I’m trying to read accelerometric data from the evaluation board EVAL-ADXL355-PMDZ. The board is connected to a raspberry pi 4 that runs on raspbian
.
The circuit is cabled into the standard SPI pins (4-wires) in the raspberry pi but the chip selection (CS
) is connected into one of the free pins (12).
To test the board I wrote the following code that uses spidev to make the comunication with the chip and RPi.GPIO to make the chip selection:
#!/usr/bin/env python3.7
import time
import spidev
import RPi.GPIO as gpio
pin = 12
gpio.setwarnings(False) # stop warnings when the script runs multiple times
gpio.setmode(gpio.BCM)
gpio.setup(pin, gpio.OUT)
spi = spidev.SpiDev()
spi.open(0,0)
spi.mode = 3
spi.max_speed_hz = 5000000
READBIT = 0x01
WRITEBIT = 0x00
def check_adxl355(pin):
'''gets true if DEVID_MST is 0x1D'''
address = 0x01 << 1 | READBIT
gpio.output(pin, gpio.LOW)
id_ = spi.xfer2([address ,0])
gpio.output(pin, gpio.HIGH)
return id_[1] == 0x1D
def configure_adxl355(pin):
'''configure the accelerometer '''
RANGE = 0x2C << 1 | WRITEBIT
gpio.output(pin, gpio.LOW)
o_ = spi.xfer2([RANGE, 0x01]) # RANGE_2G
gpio.output(pin, gpio.HIGH)
POWER_CTL = 0x2D << 1 | WRITEBIT
gpio.output(pin, gpio.LOW)
o_ = spi.xfer2([POWER_CTL, 0x06])
gpio.output(pin, gpio.HIGH)
print("ADXL355 : {}".format(check_adxl355(pin)))
configure_adxl355(pin)
# read data from the ADXL355
AXIS_START = 0x08 << 1 | READBIT
while 1:
gpio.output(pin, gpio.LOW)
axisBytes = spi.xfer2([AXIS_START, 0, 0, 0, 0, 0, 0, 0, 0, 0])[1:] # read 9 bytes
gpio.output(pin, gpio.HIGH)
X = (axisBytes[0] << 16 | axisBytes[1] << 8 | axisBytes[2]) >> 4
Y = (axisBytes[3] << 16 | axisBytes[4] << 8 | axisBytes[5]) >> 4
Z = (axisBytes[6] << 16 | axisBytes[7] << 8 | axisBytes[8]) >> 4
print(">> {} {} {}".format(X, Y, Z))
time.sleep(1)
In general what it does is to configure the communication between the accelerometer and the raspberry pi, check if the ADXL355 is connected to the pin 12 by locking at the the mems id register (check_adxl355
), configure the range of the accelerometer (configure_adxl355
) and reading samples from the FIFO register. When running the previous code I have as the results:
pi@raspberrypi:~/adxl355spi $ ./adxl355.py
ADXL355 : True
>> 0 0 0
>> 0 0 0
...
the first block looks ok as it reports that the accelerometer was found, after that the configuration of the accelerometer is not checked, and finaly the the block that read the accelerometric data (X, Y, Z
) returns only 0
even though the accelerometer is moving.
Can anyone spot a problem when reading the accelerometric data?
-
Did you try out the example code from github.com/nuclearfutureslab/adxl355-pi? The author mentioned that his solution should work, so I’m guessing it might work for you too. Maybe you can spot your mistakes more easily when comparing it to a running solution. Or at least you might be able to exclude the possibility of a broken sensor. – raphael_mav 10 hours ago
-
and maybe this simple example github.com/gpvidal/adxl355-python/blob/master/examples/… – user3732793 10 hours ago
ADXL355 Accelerometer PMOD Demo
https://wiki.analog.com/resources/eval/user-guides/eval-adicup360/reference_designs/demo_adxl355
The ADuCM360_demo_adxl355_pmdz is an accelerometer demo project for the EVAL-ADICUP360 base board with the EVAL-ADXL355-PMDZ board, using the GNU ARM Eclipse Plug-ins in Eclipse environment.
General description
This project is an example for how to use EVAL-ADICUP360 board in combination with the EVAL-ADXL355-PMDZ accelerometer PMOD board.
The ADuCM360_demo_adxl355_pmdz project uses the EVAL-ADXL355-PMDZ which has the ADXL355 3-axis MEMS accelerometer on board.
The application reads the X , Y , and Z acceleration registers.
The acceleration in the 3 axis is displayed in [G].
There is an internal temperature sensor in the ADXL355, which is converted by the on chip 12-bit ADC.
The acceleration range can also be selected by setting the ADXL355_RANGE variable with the ADXL355.h file. (Values of [2, 4, and 8 are acceptable] )
All the outputs are printed from the UART to the USER USB port and can be read on the PC using a serial terminal program, such as Putty or Tera Term.
For precision applications, each ADXL355 chip requires individual calibration which can be done by measuring and setting the definitions
ACC_TEMP_BIAS and ACC_TEMP_SENSITIVITY parameters in the ADXL362.h file.
The temperature in degrees celsius, can be derived from the ADC readings Tadc using the predefined formula:
Temp = (Tadc - ADXL355_TEMP_BIAS)/ ADXL355_TEMP_SLOPE) + 25;
Demo Requirements
The following is a list of items needed in order to replicate this demo.
-
Hardware EVAL-ADICUP360
-
EVAL-ADXL355-PMDZ
-
-
Mirco USB to USB cable
-
PC or Laptop with a USB port
-
-
Software
-
-
ADuCM360_demo_adxl355_pmdz software
-
CrossCore Embedded Studio (2.7.0 or higher)
-
ADuCM36x DFP (1.0.2 or higher)
-
CMSIS ARM Pack (4.3.0 or higher)
-
Serial Terminal Program
-
Such as Putty or Tera Term
-
-
Setting up the hardware
-
Plug the EVAL-ADXL355-PMDZ board in the EVAL-ADICUP360 base board, via the PMOD_SPI port (P4).
-
Plug in the USB cable from the PC to the EVAL-ADICUP360 base board via the User USB.(P13)
Obtaining the source code
We recommend not opening the project directly, but rather import it into CCES and make a local copy in your workspace.
The source code and include files of the ADuCM360_demo_adxl355_pmdz can be found on Github:
CrossCore Embedded Studio Application Source Code:
For more information on importing, debugging, or other tools related questions, please see the tools user guide.
Configuring the Software Parameters
-
Temperature sensor calibration
-
values– ADXL355_TEMP_BIAS and ADXL355_TEMP_SLOPE paramaters – find your values based on the calculation formula (ADXL355.h ):
#define ADXL355_TEMP_BIAS (float)1852.0 #define ADXL355_TEMP_SLOPE (float)-9.05
-
Accelerometer range setting – ADXL_RANGE parameter – 2, 4, or 8 are acceptable values to set the [g] range for the ADXL355 (ADXL355.h).
#define ADXL_SENSE 2
-
Sensor activity and inactivity thresholds – ACT_VALUE and INACT_VALUE paramaters used to determine at which acceleration values the sensor can react at sleep/wake-up commands (ADXL355.h):
#define ACT_VALUE 50 #define INACT_VALUE 50
-
Sensor activity and inactivity time – ACT_TIMER and INACT_TIMER paramaters used to determine sleep/wake-up intervals(ADXL355.h):
#define ACT_TIMER 50 #define INACT_TIMER 50
Outputting Data
Serial Terminal Output
-
In order to view the data, you must flash the program to the EVAL-ADICUP360.
-
Once complete you will need to switch the USB cable from the DEBUG USB (P14) to the USER USB (P13).
-
Then follow the UART settings below with the serial terminal program.
Following is the UART configuration.
Select COM Port Baud rate: 9600 Data: 8 bit Parity: none Stop: 1 bit Flow Control: none
The user must press the <ENTER> key each time they want to display the results.
How to use the Tools
The official tool we promote for use with the EVAL-ADICUP360 is CrossCore Embedded Studio. For more information on downloading the tools and a quick start guide on how to use the tool basics, please check out the Tools Overview page.
Importing
For more detailed instructions on importing this application/demo example into the CrossCore Embedded Studios tools, please view our How to import existing projects into your workspace section.
Debugging
For more detailed instructions on importing this application/demo example into the CrossCore Embedded Studios tools, please view our How to configure the debug session section.
Project structure
This project contains: system initialization part – disabling watchdog, setting system clock, enabling clock for peripheral; port configuration for SPI0, accelerometer sensor use; SPI read/write functions; sensor monitoring.
In the src and include folders you will find the source and header files related to ADXL355 application.
You can modify as you wanted those files. The Communication.c/h files contain SPI and UART specific data, meanwhile the ADXL355.c/h files contain the accelerometer data. Here are parameters you can configure:
The RTE folder contains device and system related files:
-
Device Folder – contains low levels drivers for ADuCM360 microcontroller.(try not to edit these files)
-
system.rteconfig – Allows the user to select the peripherial components they need, along with the startup and ARM cmsis files needed for the project.
End of Document
resources/eval/user-guides/eval-adicup360/reference_designs/demo_adxl355.txt · Last modified: 21 Mar 2018 16:48 by Brandon
Categories: Uncategorized