Skip to content

Commit

Permalink
Merge pull request #538 from mthoren-adi/adxl345_ip_cl_args_update
Browse files Browse the repository at this point in the history
lm75, adxl345, adxl355: Clean up and enhancements
  • Loading branch information
tfcollins authored Mar 9, 2024
2 parents f5deb5e + 4a47fe3 commit cf8af3f
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 187 deletions.
50 changes: 34 additions & 16 deletions examples/adxl345_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,55 @@
#
# SPDX short identifier: ADIBSD

import argparse
import time

import adi

# Optionally pass URI as command line argument with -u option,
# else use default to "ip:analog.local"
parser = argparse.ArgumentParser(description="ADXL345 Example Script")
parser.add_argument(
"-u",
default=["ip:analog.local"],
help="-u (arg) URI of target device's context, eg: 'ip:analog.local',\
'ip:192.168.2.1',\
'serial:COM4,115200,8n1n'",
action="store",
nargs="*",
)
args = parser.parse_args()
my_uri = args.u[0]

print("uri: " + str(my_uri))

# Set up ADXL345
myacc = adi.adxl345(uri="ip:192.168.1.232")
myacc.rx_output_type = "SI"
myacc.rx_buffer_size = 4
myacc.rx_enabled_channels = [0, 1, 2]
my_acc = adi.adxl345(uri=my_uri)
my_acc.rx_output_type = "SI"
my_acc.rx_buffer_size = 4
my_acc.rx_enabled_channels = [0, 1, 2]

sfa = myacc.sampling_frequency_available
sfa = my_acc.sampling_frequency_available
print("Sampling frequencies available:")
print(sfa)

print("\nX acceleration: " + str(myacc.accel_x.raw))
print("Y acceleration: " + str(myacc.accel_y.raw))
print("Z acceleration: " + str(myacc.accel_z.raw))
print("\nX acceleration: " + str(my_acc.accel_x.raw))
print("Y acceleration: " + str(my_acc.accel_y.raw))
print("Z acceleration: " + str(my_acc.accel_z.raw))

print("\nSample rate: " + str(myacc.sampling_frequency))
print("\nSample rate: " + str(my_acc.sampling_frequency))

print("Setting sample rate to 12.5 sps...")
myacc.sampling_frequency = 12.5
my_acc.sampling_frequency = 12.5
time.sleep(0.25)

print("new sample rate: " + str(myacc.sampling_frequency))
myacc.sampling_frequency = 100.0 # Set back to default
print("new sample rate: " + str(my_acc.sampling_frequency))
my_acc.sampling_frequency = 100.0 # Set back to default
print("\nData using unbuffered rx(), SI (m/s^2):")
print(myacc.rx())
print(my_acc.rx())

myacc.rx_output_type = "raw"
my_acc.rx_output_type = "raw"
print("\nData using unbuffered rx(), raw:")
print(myacc.rx())
print(my_acc.rx())

del myacc
del my_acc
148 changes: 97 additions & 51 deletions examples/adxl355_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,141 @@
#
# SPDX short identifier: ADIBSD

import sys
import argparse
import time

import adi

# Optionally pass URI as command line argument,
# else use default context manager search
my_uri = sys.argv[1] if len(sys.argv) >= 2 else None
# Optionally pass URI as command line argument with -u option,
# else use default to "ip:analog.local"
parser = argparse.ArgumentParser(description="ADXL355 Example Script")
parser.add_argument(
"-u",
default=["ip:analog.local"],
help="-u (arg) URI of target device's context, eg: 'ip:analog.local',\
'ip:192.168.2.1',\
'serial:COM4,115200,8n1n'",
action="store",
nargs="*",
)
args = parser.parse_args()
my_uri = args.u[0]

print("uri: " + str(my_uri))

# Set up ADXL355
myacc = adi.adxl355(uri=my_uri)
myacc.rx_buffer_size = 32
myacc.rx_enabled_channels = [0, 1, 2]
my_acc = adi.adxl355(uri=my_uri)
my_acc.rx_buffer_size = 32
my_acc.rx_enabled_channels = [0, 1, 2]

print("\nChecking temperature channel...")
print("Temperature raw: " + str(myacc.temp.raw))
print("Calculated Temperature: " + str(myacc.to_degrees(myacc.temp.raw)))
print("Temperature raw: " + str(my_acc.temp.raw))
print("Calculated Temperature: " + str(my_acc.to_degrees(my_acc.temp.raw)))

print("\nCurrent Timestamp: " + str(myacc.current_timestamp_clock))
# print("\nCurrent Timestamp: " + str(my_acc.current_timestamp_clock))
# Not enabled as of Kuiper 2022_r2, and not implemented in no-OS

sfa = myacc.accel_x.sampling_frequency_available
sfa = my_acc.accel_x.sampling_frequency_available
print("\nSampling frequencies available:")
print(sfa)

print("\nInitial sample frequency:")
print("X Sample frequency: " + str(myacc.accel_x.sampling_frequency))
print("Y Sample frequency: " + str(myacc.accel_y.sampling_frequency))
print("Z Sample frequency: " + str(myacc.accel_z.sampling_frequency))
print("X Sample frequency: " + str(my_acc.accel_x.sampling_frequency))
print("Y Sample frequency: " + str(my_acc.accel_y.sampling_frequency))
print("Z Sample frequency: " + str(my_acc.accel_z.sampling_frequency))

print("Single raw acceleration values:")
print("\nX acceleration: " + str(myacc.accel_x.raw * myacc.accel_x.scale) + " m/s^2")
print("Y acceleration: " + str(myacc.accel_y.raw * myacc.accel_y.scale) + " m/s^2")
print("Z acceleration: " + str(myacc.accel_z.raw * myacc.accel_z.scale) + " m/s^2")
print("Single calculated acceleration values:")
print("\nX acceleration: " + str(my_acc.accel_x.raw * my_acc.accel_x.scale) + " m/s^2")
print("Y acceleration: " + str(my_acc.accel_y.raw * my_acc.accel_y.scale) + " m/s^2")
print("Z acceleration: " + str(my_acc.accel_z.raw * my_acc.accel_z.scale) + " m/s^2")

print("\nSetting sample frequencies to 1000 sps...")
myacc.accel_x.sampling_frequency = sfa[2]
myacc.accel_y.sampling_frequency = sfa[2]
myacc.accel_z.sampling_frequency = sfa[2]
my_acc.accel_x.sampling_frequency = "{:.6f}".format(sfa[2])
my_acc.accel_y.sampling_frequency = "{:.6f}".format(sfa[2])
my_acc.accel_z.sampling_frequency = "{:.6f}".format(sfa[2])
time.sleep(0.25)

print("Verifying new sample rate: " + str(myacc.accel_x.sampling_frequency))
print("Verifying new sample rate: " + str(my_acc.accel_x.sampling_frequency))
print("Setting back to 4000 sps...")
myacc.accel_x.sampling_frequency = 4000.0
myacc.accel_y.sampling_frequency = 4000.0
myacc.accel_z.sampling_frequency = 4000.0 # Set back to default
my_acc.accel_x.sampling_frequency = "{:.6f}".format(4000.0)
my_acc.accel_y.sampling_frequency = "{:.6f}".format(4000.0)
my_acc.accel_z.sampling_frequency = "{:.6f}".format(4000.0)
time.sleep(0.25)

print("\nData using buffered rx(), SI (m/s^2):")
myacc.rx_output_type = "SI"
print(myacc.rx())
my_acc.rx_output_type = "SI"
print(my_acc.rx())

myacc.rx_output_type = "raw"
my_acc.rx_output_type = "raw"
print("\nData using buffered rx(), raw:")
print(myacc.rx())
print(my_acc.rx())

cutoffs = myacc.accel_x.filter_high_pass_3db_frequency_available
print("\nX available highpass cutoff frequencies: " + str(cutoffs))
cutoffs = my_acc.accel_x.filter_high_pass_3db_frequency_available
print("\nAvailable highpass cutoff frequencies: " + str(cutoffs))

print(
"Setting highpass cutoff frequency to "
"\nSetting highpass cutoff frequency to "
+ str(cutoffs[1])
+ " then taking a nap to settle..."
+ " then taking a 2 second nap to settle..."
)
myacc.accel_x.filter_high_pass_3db_frequency = cutoffs[1]
myacc.accel_y.filter_high_pass_3db_frequency = cutoffs[1]
myacc.accel_z.filter_high_pass_3db_frequency = cutoffs[1]
my_acc.accel_x.filter_high_pass_3db_frequency = "{:.6f}".format(cutoffs[1])
my_acc.accel_y.filter_high_pass_3db_frequency = "{:.6f}".format(cutoffs[1])
my_acc.accel_z.filter_high_pass_3db_frequency = "{:.6f}".format(cutoffs[1])

print(
"\nX highpass cutoff frequency: "
+ str(myacc.accel_x.filter_high_pass_3db_frequency)
+ str(my_acc.accel_x.filter_high_pass_3db_frequency)
)
print(
"Y highpass cutoff frequency: " + str(myacc.accel_y.filter_high_pass_3db_frequency)
"Y highpass cutoff frequency: " + str(my_acc.accel_y.filter_high_pass_3db_frequency)
)
print(
"Z highpass cutoff frequency: " + str(myacc.accel_z.filter_high_pass_3db_frequency)
"Z highpass cutoff frequency: " + str(my_acc.accel_z.filter_high_pass_3db_frequency)
)

time.sleep(2.0)
print("\nAccelerations after highpass, should be close to zero if the")
print("ADXL355 is sitting still...")
print("X acceleration: " + str(myacc.accel_x.raw))
print("Y acceleration: " + str(myacc.accel_y.raw))
print("Z acceleration: " + str(myacc.accel_z.raw))

print("\nSetting highpass cutoff frequency back to zero...")
myacc.accel_x.filter_high_pass_3db_frequency = 0.0000
myacc.accel_y.filter_high_pass_3db_frequency = 0.0000
myacc.accel_z.filter_high_pass_3db_frequency = 0.0000

del myacc

print(
"\nAccelerations after highpass, should be close to zero if the ADXL355 is sitting still...\n"
)
print("X acceleration: " + str(my_acc.accel_x.raw * my_acc.accel_x.scale) + " m/s^2")
print("Y acceleration: " + str(my_acc.accel_y.raw * my_acc.accel_y.scale) + " m/s^2")
print("Z acceleration: " + str(my_acc.accel_z.raw * my_acc.accel_z.scale) + " m/s^2")

print(
"\nSetting highpass cutoff frequency back to zero, then taking a 4 second nap to settle..."
)
my_acc.accel_x.filter_high_pass_3db_frequency = "{:.6f}".format(0.0)
my_acc.accel_y.filter_high_pass_3db_frequency = "{:.6f}".format(0.0)
my_acc.accel_z.filter_high_pass_3db_frequency = "{:.6f}".format(0.0)

time.sleep(4.0)

print("\nAccelerations after highpass settling...")

print("X acceleration: " + str(my_acc.accel_x.raw * my_acc.accel_x.scale) + " m/s^2")
print("Y acceleration: " + str(my_acc.accel_y.raw * my_acc.accel_y.scale) + " m/s^2")
print("Z acceleration: " + str(my_acc.accel_z.raw * my_acc.accel_z.scale) + " m/s^2")

print("\nSetting offset for each axis...\n")
print("X offset set to: " + str(my_acc.accel_x.raw >> 4))
print("Y offset set to: " + str(my_acc.accel_y.raw >> 4))
print("Z offset set to: " + str(my_acc.accel_z.raw >> 4))

my_acc.accel_x.calibbias = "{:.6f}".format(my_acc.accel_x.raw >> 4)
my_acc.accel_y.calibbias = "{:.6f}".format(my_acc.accel_y.raw >> 4)
my_acc.accel_z.calibbias = "{:.6f}".format(my_acc.accel_z.raw >> 4)

print(
"\nAccelerations after setting offset, should be close to zero if the ADXL355 is sitting still...\n"
)
print("X acceleration: " + str(my_acc.accel_x.raw * my_acc.accel_x.scale) + " m/s^2")
print("Y acceleration: " + str(my_acc.accel_y.raw * my_acc.accel_y.scale) + " m/s^2")
print("Z acceleration: " + str(my_acc.accel_z.raw * my_acc.accel_z.scale) + " m/s^2")

print("\nSetting offset for each axis back to 0...")
my_acc.accel_x.calibbias = "{:.6f}".format(0.0)
my_acc.accel_y.calibbias = "{:.6f}".format(0.0)
my_acc.accel_z.calibbias = "{:.6f}".format(0.0)

del my_acc
114 changes: 0 additions & 114 deletions examples/adxl355_no_os_example.py

This file was deleted.

Loading

0 comments on commit cf8af3f

Please sign in to comment.