ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW Code Questions

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with 3 accelerometer using python


  • I have struggle with 3 accelerometer(Model 352c33) using with DAQ(NI-9230BNC + cDAQ-917) with this code:
  • import nidaqmx
    import csv
    import time
    import numpy as np

    # Define your accelerometer channel names here
    accelerometer_channels = ["cDAQ1Mod1/ai0", "cDAQ1Mod1/ai1", "cDAQ1Mod1/ai2"]

    # Create a task for analog input for each accelerometer channel
    tasks = []
    for channel in accelerometer_channels:
    task = nidaqmx.Task()
    task.ai_channels.add_ai_voltage_chan(channel)

    # Set the voltage range for each channel (adjust as needed)
    task.ai_channels[-1].ai_max = 5.0 # Set the maximum voltage to +5V
    task.ai_channels[-1].ai_min = -5.0 # Set the minimum voltage to -5V

    tasks.append(task)

    for i in range(30):
    # Start all tasks
    for task in tasks:
    task.start()

    # Read data from all channels
    data = [task.read(number_of_samples_per_channel=10000) for task in tasks]

    # Stop all tasks
    for task in tasks:
    task.stop()

    # Create a time axis
    time_axis = np.arange(len(data[0])) / 10000 # Assuming the same sampling rate for all channels

    # Save data to a CSV file
    csv_file = f"vibration_data{i}.csv"
    with open(csv_file, "w", newline="") as file:
    writer = csv.writer(file)
    writer.writerow(["Time (s)", "Channel 0", "Channel 1", "Channel 2"]) # Write header row
    for t, ch0, ch1, ch2 in zip(time_axis, *data):
    writer.writerow([t, ch0, ch1, ch2])

    # Sleep to wait for the next trial (optional)
    time.sleep(10.0) # Sleep for 10 seconds between trials

    # Close all tasks
    for task in tasks:
    task.close()


  • Before this code i can use 1 accelerometer to detect vibration signal, but when i adjust the code to use 3. It only detect 1, i can’t use 3 together
0 Kudos
Message 1 of 1
(1,390 Views)