From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple way to control speakers via analog output

Solved!
Go to solution

Hello to all,

My institution has several NI tools for my thesis.

 

We have a chassit 1033 and two NI 44-98 cards allowing the recording of vibration in a sample via accelerometers.

 

We have recently acquired a NI 6323 card and two SCB 68A.

 

The AO ports of the two SCB68A are connected to amplifiers connected to speakers.

 

I would like to find a simple way via python to emit the desired signals, to transmit them to the amplifier which itself will transmit them to the speakers. This allows me to have a total control of my source.

 

For the moment, I can't find any example in python similar to what I would like to do.

I started to code a piece of code, but it doesn't work.


import nidaqmx
rate = 40000 # Sample rate in Hz
duration = 10 # Duration in seconds

samples = int(rate * duration)
list = []
for x in range(samples):
list.append(x % 2)
with nidaqmx.Task() as task:
task.ao_channels.add_ao_voltage_chan("Dev1/ao1")
task.timing.cfg_samp_clk_timing(rate)
task.write(list, auto_start=False)
task.start()

 


Do you have any examples that I could use as inspiration, or any ideas?

Sincerely,

 

Thomas

0 Kudos
Message 1 of 2
(794 Views)
Solution
Accepted by topic author KramGeo

Hi,

 

Problems solved :

 

import nidaqmx
import numpy as np
from nidaqmx import *

test_Task = nidaqmx.Task()
test_Task.ao_channels.add_ao_voltage_chan('Dev1/ao2')
test_Task.timing.cfg_samp_clk_timing(rate= 10, sample_mode= nidaqmx.constants.AcquisitionType.CONTINUOUS, samps_per_chan= 5)
test_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(test_Task.out_stream, auto_start=True)
samples = np.append(5*np.ones(10), np.zeros(10))
test_Writer.write_many_sample(samples)
test_Task.wait_until_done(timeout=5)

Message 2 of 2
(777 Views)