Multiple ROIs_Bonsai &Arduino

554 views
Skip to first unread message

Hazim Dirdiri

unread,
Apr 9, 2021, 8:14:15 AM4/9/21
to Bonsai Users
Hi bonsai users,

I'm using arduino to stimulate LED light into specific ROIs in bonsai, using (EPM, OFT, and real time place preference). 
My issue is that in this protocol i want to stimulate multiple ROIs (Borders of Open field), yet bonsai only detects one ROI at time, which worked in the previous experiments stimulating only one ROI [First attached bonsai file]

- When trying to draw more than one ROI within the same node, it doesn't work, i think because it has to be 1 roi in the node.

- When i try to make more ROI activity nodes and link them to python transform so that if the mouse is within the ROIs, then it makes the digital output to be 1, but the problem is that now no light is coming from arduino. [second attached bonsai file]

i also attached the arudino files (firmata, and the stimulation parameters).

I thought of logic of making the program not stimulate if it's in the ROI, but that didn't work.

I think maybe my question is not clearly stated, but i tried a lot of things, and would love if someone helps, as i am not very good in the technical side

Best,

--

Hazim Eldirdiri

Beyeler Lab, Neurocentre Magendie,

INSERM (French NIH), University of Bordeaux

146 Rue Léo Saignat, 33000 Bordeaux, France



multiple_ROIs.zip

Hazim Dirdiri

unread,
Apr 9, 2021, 8:17:39 AM4/9/21
to Bonsai Users
I've gone through these threads as well

bruno...@neuro.fchampalimaud.org

unread,
Apr 9, 2021, 10:04:49 AM4/9/21
to Bonsai Users
"- When trying to draw more than one ROI within the same node, it doesn't work, i think because it has to be 1 roi in the node."
While bonsai is running, you can draw more ROIs. You can index them using the "index" node or, inside the python transform, "Item[index]" if i am not mistaken.

RE: LED not turning on. I am not sure I fully understand what you are trying to do. However, you should probably use a digitalOutput (1/0 -> 0-5V). By using a analogOuput you are sending a 5V signal but with a super small duty cycle (if i am not mistaken, the analogWrite goes 0-255 so: 1/255 ~ 0.3%) which, even if the led turns on, you would probably not be able to tell.  

I hope it helps!
Bruno

Hazim Dirdiri

unread,
Apr 9, 2021, 10:43:41 AM4/9/21
to Bonsai Users
Thanks for your quick reply! Basically, what i did now is that i made the code make an output of 1, if its outside the ROI (which i need), but now i am trying to figure out how to make arduino translate the analog output of 1 into LED light, maybe in firmata file or so.
The problem with the digital output is when i use it, with this method, it says no enough arguemnts (As the python transform file i coded it to switch to 0 or 1, based on the ROI)
i hope this made sense.

roi.PNG

bruno...@neuro.fchampalimaud.org

unread,
Apr 9, 2021, 11:12:07 AM4/9/21
to Bonsai Users
DigitalOutput expects a boolean (1/0 -> High/Low) whereas analog expects an int. Your python transform is returning an int (@returns(int)). Try to convert this int to a boolean before using digitalOutput (e.g. use a greaterThan(0) node after the python transform).

Hazim Dirdiri

unread,
Apr 9, 2021, 11:24:20 AM4/9/21
to Bonsai Users
Yes, i'm aware of that. It works in case i want the stimulation to be inside the ROIs, but the issue is i want it (Outside the ROI >> Hence using the analog int. functions) or (Multiple ROIs,), which both didn't work. 
adding greater than generated build error {The Binary Operator GreaterThan is not defined for the types System.Boolean' and 'System.boolean'

bruno...@neuro.fchampalimaud.org

unread,
Apr 9, 2021, 12:36:33 PM4/9/21
to Bonsai Users
Sorry I tried to help you with the arduino issue but I think it might be easier if i understand your experiment.

From the script you sent: you have a series of ROIs. For each frame, you check if the animal is inside these areas (python transform) and output a 1(int), or a 0 if it is not. You then want to turn a arduino pin to 5V if he is, and to 0 if he is not. If you want to stimulate outside the ROI, cant you just invert the logic inside the pythonTransform? I am not sure why do you need a "int" to be the output. 
Cheers,
Bruno

Hazim Dirdiri

unread,
Apr 13, 2021, 6:44:26 AM4/13/21
to Bonsai Users
Hi Bruno,
I finally got hold to solve the issue. My experiment is multiple behavioral assays for optogenetics, the one i wanted to do in this one is Open Field test, with optogenetic light stimulation in the borders of the field. I managed to solve the issue, by passing the boolean function to the digital ouptut, to (return not) the mice in the ROI. As previously done multiple ROIs with analog output didn't work well. 
I thought about complicated solutions, while it was an easy inversion of the logic as you said. It was because when i did it the first time i had error from bonsai of (Input arguments are not correct), 

Regards and thanks a lot for your help,
Hazim

Reply all
Reply to author
Forward
0 new messages