<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem with 3 accelerometer using python in LabVIEW Code Questions</title>
    <link>https://forums.ni.com/t5/LabVIEW-Code-Questions/Problem-with-3-accelerometer-using-python/m-p/4332567#M69</link>
    <description>&lt;UL&gt;
&lt;LI&gt;&lt;HR /&gt;I have struggle with 3 accelerometer(Model 352c33) using with DAQ(NI-9230BNC + cDAQ-917) with this code:&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;import nidaqmx&lt;BR /&gt;import csv&lt;BR /&gt;import time&lt;BR /&gt;import numpy as np&lt;/P&gt;
&lt;P&gt;# Define your accelerometer channel names here&lt;BR /&gt;accelerometer_channels = ["cDAQ1Mod1/ai0", "cDAQ1Mod1/ai1", "cDAQ1Mod1/ai2"]&lt;/P&gt;
&lt;P&gt;# Create a task for analog input for each accelerometer channel&lt;BR /&gt;tasks = []&lt;BR /&gt;for channel in accelerometer_channels:&lt;BR /&gt;task = nidaqmx.Task()&lt;BR /&gt;task.ai_channels.add_ai_voltage_chan(channel)&lt;BR /&gt;&lt;BR /&gt;# Set the voltage range for each channel (adjust as needed)&lt;BR /&gt;task.ai_channels[-1].ai_max = 5.0 # Set the maximum voltage to +5V&lt;BR /&gt;task.ai_channels[-1].ai_min = -5.0 # Set the minimum voltage to -5V&lt;BR /&gt;&lt;BR /&gt;tasks.append(task)&lt;/P&gt;
&lt;P&gt;for i in range(30):&lt;BR /&gt;# Start all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.start()&lt;/P&gt;
&lt;P&gt;# Read data from all channels&lt;BR /&gt;data = [task.read(number_of_samples_per_channel=10000) for task in tasks]&lt;/P&gt;
&lt;P&gt;# Stop all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.stop()&lt;/P&gt;
&lt;P&gt;# Create a time axis&lt;BR /&gt;time_axis = np.arange(len(data[0])) / 10000 # Assuming the same sampling rate for all channels&lt;/P&gt;
&lt;P&gt;# Save data to a CSV file&lt;BR /&gt;csv_file = f"vibration_data{i}.csv"&lt;BR /&gt;with open(csv_file, "w", newline="") as file:&lt;BR /&gt;writer = csv.writer(file)&lt;BR /&gt;writer.writerow(["Time (s)", "Channel 0", "Channel 1", "Channel 2"]) # Write header row&lt;BR /&gt;for t, ch0, ch1, ch2 in zip(time_axis, *data):&lt;BR /&gt;writer.writerow([t, ch0, ch1, ch2])&lt;/P&gt;
&lt;P&gt;# Sleep to wait for the next trial (optional)&lt;BR /&gt;time.sleep(10.0) # Sleep for 10 seconds between trials&lt;/P&gt;
&lt;P&gt;# Close all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.close()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;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&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 04 Oct 2023 12:54:36 GMT</pubDate>
    <dc:creator>Sarun8755</dc:creator>
    <dc:date>2023-10-04T12:54:36Z</dc:date>
    <item>
      <title>Problem with 3 accelerometer using python</title>
      <link>https://forums.ni.com/t5/LabVIEW-Code-Questions/Problem-with-3-accelerometer-using-python/m-p/4332567#M69</link>
      <description>&lt;UL&gt;
&lt;LI&gt;&lt;HR /&gt;I have struggle with 3 accelerometer(Model 352c33) using with DAQ(NI-9230BNC + cDAQ-917) with this code:&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;import nidaqmx&lt;BR /&gt;import csv&lt;BR /&gt;import time&lt;BR /&gt;import numpy as np&lt;/P&gt;
&lt;P&gt;# Define your accelerometer channel names here&lt;BR /&gt;accelerometer_channels = ["cDAQ1Mod1/ai0", "cDAQ1Mod1/ai1", "cDAQ1Mod1/ai2"]&lt;/P&gt;
&lt;P&gt;# Create a task for analog input for each accelerometer channel&lt;BR /&gt;tasks = []&lt;BR /&gt;for channel in accelerometer_channels:&lt;BR /&gt;task = nidaqmx.Task()&lt;BR /&gt;task.ai_channels.add_ai_voltage_chan(channel)&lt;BR /&gt;&lt;BR /&gt;# Set the voltage range for each channel (adjust as needed)&lt;BR /&gt;task.ai_channels[-1].ai_max = 5.0 # Set the maximum voltage to +5V&lt;BR /&gt;task.ai_channels[-1].ai_min = -5.0 # Set the minimum voltage to -5V&lt;BR /&gt;&lt;BR /&gt;tasks.append(task)&lt;/P&gt;
&lt;P&gt;for i in range(30):&lt;BR /&gt;# Start all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.start()&lt;/P&gt;
&lt;P&gt;# Read data from all channels&lt;BR /&gt;data = [task.read(number_of_samples_per_channel=10000) for task in tasks]&lt;/P&gt;
&lt;P&gt;# Stop all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.stop()&lt;/P&gt;
&lt;P&gt;# Create a time axis&lt;BR /&gt;time_axis = np.arange(len(data[0])) / 10000 # Assuming the same sampling rate for all channels&lt;/P&gt;
&lt;P&gt;# Save data to a CSV file&lt;BR /&gt;csv_file = f"vibration_data{i}.csv"&lt;BR /&gt;with open(csv_file, "w", newline="") as file:&lt;BR /&gt;writer = csv.writer(file)&lt;BR /&gt;writer.writerow(["Time (s)", "Channel 0", "Channel 1", "Channel 2"]) # Write header row&lt;BR /&gt;for t, ch0, ch1, ch2 in zip(time_axis, *data):&lt;BR /&gt;writer.writerow([t, ch0, ch1, ch2])&lt;/P&gt;
&lt;P&gt;# Sleep to wait for the next trial (optional)&lt;BR /&gt;time.sleep(10.0) # Sleep for 10 seconds between trials&lt;/P&gt;
&lt;P&gt;# Close all tasks&lt;BR /&gt;for task in tasks:&lt;BR /&gt;task.close()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;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&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 04 Oct 2023 12:54:36 GMT</pubDate>
      <guid>https://forums.ni.com/t5/LabVIEW-Code-Questions/Problem-with-3-accelerometer-using-python/m-p/4332567#M69</guid>
      <dc:creator>Sarun8755</dc:creator>
      <dc:date>2023-10-04T12:54:36Z</dc:date>
    </item>
  </channel>
</rss>

