FreeFeed, pellet remove = short pulse, wait 'x' seconds, pellet

75 views
Skip to first unread message

Miguel Duran

unread,
Oct 25, 2021, 7:50:14 PM10/25/21
to FEDforum
Good evening Lex,

Love tinkering with this device and I really want to take it up a notch for our lab. I was playing with the code in Free Feeding v1.8.5, but seemed to be stumped. I'm pairing the FED3 with an external hardware that will be connected via BNC. I want the hardware to receive input from FED3 when a mouse removes a pellet by sending a pulse. A step further would be to have FED3 not dispense another pellet for a set amount of time because we are using fiber photometry to record the before, during, and after of each epoch of pellet retrieval. How might one code for this? I tried the timeout function and thought it would solve it but I end up telling it to timeout before it sends a pulse. 

Thank you Dr. Kravitz for your help and support and letting me join the group!

Fond regards,

Miguel D.  

Lex Kravitz

unread,
Oct 25, 2021, 11:34:18 PM10/25/21
to FEDforum
Hi Miguel!
You want the FED3 to send a pulse immediately after the pellet is removed, and then also do a Timeout?  There are three functions we need to juggle into the right order.  (BTW you can see all the functions for the FED3 library here). The three relevant functions are:
1) Feed, which runs the feeding routine to drop a pellet.
2) BNC, which controls pulses from the BNC output.  For instance, you can call the BNC function as:
fed3.BNC(200,1) to deliver a single 200ms pulse or fed3.BNC(100,10) to deliver ten 100ms pulses
3) Timeout runs a timeout routine, basically pausing the FED3 for a specified time.

The complication you're experiencing is because the Feed routine automatically calls Timeout.  But you want Feed, then BNC, and then Timeout.  Long-term I should probably make it so Feed doesn't automatically call Timeout but for now that's how it works. I did it that way because it makes the high level code clean.  I made the following edits to the Free-feeding script to do what you want (noted in yellow arrows below):
1) I turned off the Timeout call in the Feed function, by setting fed3.timeout = 0.  Now when Feed calls TImeout the timeout duration will be 0s, or essentially off.
2) I added fed3.BNC(200,1) to the void loop() after the Feed function, which will deliver a single 200ms pulse immediately after the pellet is removed.  You can edit this pulse call how you want.
3) I added delay (115000) to the code to replace the timeout function we removed - delay is a built in Arduino function that pauses the microprocessor.  So this will pause the FED3 for 115 seconds here, after which it will resume at the top of the void loop().

image(1).png
This should creates the task logic you want. I'm also attaching the Arduino script.  Have fun!  -Lex
FreeFeeding_with_BNCout_and_2minTimeout.ino
Reply all
Reply to author
Forward
0 new messages