ΣSigmaStudio Ask AI Русский Log in

Communication between ADAU1701 and Python scripts

SigmaDSP & SigmaStudio ECHO9 May 21, 2025 00:00 1 replies Original on forum ↗
Subscribe
ECHO9 Question
May 21, 2025 00:00

I have a design to trigger 40 Hz light and sound using Python codes (example attached later)

Each signal generators have its own design:

1. Signal generator

2. light generation

3. sound generation

4. signal generator 2

Audio Visual Stim.dspproj

Currently, a common tool defines different functions to activate stimulation sessions:

import serial

from time import sleep

import sys

sys.path.insert(1, '/home/stim/Linux_Drivers/USB/python')

from usb_1208FS import *

CORRECTION_FACTOR = 1.01725

class ExperimentBoardController():

def __init__(self, com_port_stim):

self.port = serial.Serial(com_port_stim)

self.port_trig = usb_1208FS()

self.port_trig.DConfig(self.port_trig.DIO_PORTA, 0x0)

self.configure_stim('light', mode='active')

self.configure_stim('sound', mode='active')

def play_chime(self, chime_number):

self.port.write(f"play_chime({chime_number})\r".encode('ascii'))

def set_frequency(self, freq_hz):

freq_hz /= CORRECTION_FACTOR

self.port.write(f"set_freq({freq_hz})\r".encode('ascii'))

def configure_stim(self, target, **kwargs):

args = []

for k, v in kwargs.items():

if isinstance(v, str):

v = f"'{v}'"

args.append(f'{k}={v}')

args = ', '.join(args)

command = f"configure_stim('{target}', {args})\r"

self.port.write(command.encode('ascii'))

def trigger(self, trigger_id):

self.port_trig.DOut(self.port_trig.DIO_PORTA, trigger_id)

sleep(0.005)

self.port_trig.DOut(self.port_trig.DIO_PORTA, 0)

def new_phase(self, message, trigger_id, time_s, chime_num=0):

trigger_id = trigger_id + 1

self.trigger(trigger_id)

time_s = time_s

print(f'[{trigger_id}] - {time_s}sec - {message} ')

if chime_num >= 0:

self.play_chime(chime_num)

sleep(time_s)

def end(self):

self.new_phase("End", 254, 1)

This is an example of an active condition:

from time import sleep

from common_tools import ExperimentBoardController

SOUND_INTENSITY = 0.70

LIGHT_INTENSITY = 5/8

board = ExperimentBoardController('COM4', 'COM3')

board.set_frequency(40)

board.configure_stim('light', intensity=0)

board.configure_stim('sound', intensity=0)

#board.new_phase("Eyes open, no stim", 0, 30)

#board.new_phase("Eyes closed, no stim", 1, 60)

board.play_chime(0)

board.configure_stim('light', intensity=LIGHT_INTENSITY, duty_percent=50, phase_deg=0)

board.configure_stim('sound', intensity=0)

board.new_phase("40Hz Light alone", 2, 60, chime_num=-1)

board.configure_stim('light', intensity=0)

board.configure_stim('sound', intensity=0)

board.new_phase("Eyes open, no stim", 0, 30, chime_num=-1)

board.configure_stim('light', intensity=0, duty_percent=50, phase_deg=0)

board.configure_stim('sound', intensity=SOUND_INTENSITY, duty_percent=4, phase_deg=0)

board.new_phase("40Hz sound alone", 3, 60, chime_num=-1)

board.configure_stim('light', intensity=0)

board.configure_stim('sound', intensity=0)

board.new_phase("Eyes open, no stim", 0, 30, chime_num=-1)

board.configure_stim('light', intensity=LIGHT_INTENSITY, duty_percent=50, phase_deg=0)

board.configure_stim('sound', intensity=SOUND_INTENSITY, duty_percent=4, phase_deg=0)

board.new_phase("40Hz light and sound", 4, 120, chime_num=-1)

board.configure_stim('light', intensity=0)

board.configure_stim('sound', intensity=0)

board.new_phase("Eyes open, no stim", 0, 30, chime_num=0)

board.end()

I am going to design a new design paced 40 Hz light and sound with 5 Hz, like this:

My questions are:

How can I integrate the new design with the existing one? Does the chip support both designs simultaneously, or do we need to manually combine them?

If only one design can be stored in RAM at a time, how can I link the two designs and switch between them using Python?

Where can I find the correct address or commands to trigger:

only 40 Hz light or sound, and

40 Hz light/sound synchronized with 5 Hz pacing?

I’d greatly appreciate any insights!

Audio Signal Processors

hardware

SigmaDSP Audio Processors

python

light and sound

adau1701

Show More

pastedimage1747836847166v1.png
pastedimage1747836847166v1.png
pastedimage1747836890487v2.png
pastedimage1747836890487v2.png
pastedimage1747836902872v3.png
pastedimage1747836902872v3.png
pastedimage1747836913250v4.png
pastedimage1747836913250v4.png
pastedimage1747836932340v5.png
pastedimage1747836932340v5.png
pastedimage1747837497288v6.png
pastedimage1747837497288v6.png
DaveThib Reply
Aug 18, 2025 00:00

Hello ECHO9,

I was just doing some cleanup on posts and ran into your old post with no answers!! I apologize for this happening and apparently nobody else in the community chimed in either. I was out of town (out of the country actually) right about when you posted this. Then the other detail is that it is really hard to follow everything you are doing with this project.

It seems like you are really going about this in a very complicated way. It would be good to know what your end goals are for the light and sound?

Then you asked about if the two programs could be stored at the same time. Well, you did not supply the details of how many instructions your current program is using? No, you cannot have two programs loaded in at the same time. What you would have to do is either load in a new program or if you have enough instructions, just have the differences combined into one program and then either switch a MUX switch to a different signal or change the parameters to produce the different signal. Something along that line.

Finding the correct addresses for the objects in your program would require you to export the System Files. In those files are all the addresses of the controls of the blocks in your program. You could derive them from the Capture window and the Params window but the System Files is helpful.

I understand if you do not want to divulge more information on the open forum. Just send me a friend request and then send the program to me in PM.

At this point you are probably way past these issues. Again, I am sorry about that.

By the way, based on what you have detailed and what I know about the brain, I think I would really love to help you with this project.

Dave T