Bonsai + Arduino for Controlling Fear Conditioning Shock Grid

434 views
Skip to first unread message

Chris Gabriel

unread,
Sep 30, 2019, 4:29:42 PM9/30/19
to Bonsai Users
Hello,

My lab has recently adopted Bonsai for implementation of our behavior experiments. We are interested in running fear conditioning with Bonsai, using it to coordinate a web camera, a simple speaker, and signals to a box generating shocks.

We have been impressed with the ease and flexibility of Bonsai thus far but have gotten stuck when trying to use an Arduino Uno in our workflow. I followed the instructions to install Firmata onto the Arduino and confirmed that it was capable of communicating with it via my PC. I then attempted to use the installed Arduino functions (e.g. DigitalOutput) to attempt to do the following:

-Start a camera (beginning of trial)
-After 3 minutes has elapsed (since camera on or trial start), turn Arduino pin 13 to HIGH for 1 second (initiate shock)
-Turn the pin off (end the shock)
-Wait 3 more minutes
-Repeat above shock procedure

I have been unable to figure out how to tell the Arduino to turn the pins ON and OFF from Bonsai--do you have any guidance or suggestions regarding how to implement this workflow with Bonsai?

Thanks,
Chris

LJ

unread,
Oct 8, 2019, 2:01:31 PM10/8/19
to Bonsai Users
Hi Chris,

You can use a Timer before a Boolean to send a timed TRUE after 3 min (using the Due Time parameter) and then wait another 3 min until the next TRUE (using the Period parameter). If you connect this Boolean to the Digital Output the ouptup will only be "actived" when it receives the TRUE value.

But you also need to turn the shocker off, so you need another timer controling another Boolean, this time sending a FALSE statement to the Digital Output. If you want the shocker to be on for 1 seconds, you need to set the Due Time parameter to 3min and 1sec. (and the Period parameter to be the same as in the other Timer).

Here is an image showing want you want to do:

stim_ON_OFF.png



You can see what is inside the StimON workflow. The StimOFF workflow is exactly the same, except the output of the Boolean must be a FALSE. And the Due Time parameter in the timer must be 1sec ahed of the StimON timer.

Hope it solves your problem.

Luis

Sigma

unread,
Nov 25, 2022, 3:33:03 AM11/25/22
to Bonsai Users
Hello, i met the same problem. Could you please show more detailed workflow to me? Thank you so much!
Reply all
Reply to author
Forward
0 new messages