Light ON when pellet in magazine

76 views
Skip to first unread message

Marie Le May

unread,
Aug 2, 2022, 10:36:08 AM8/2/22
to FEDforum
Hi Lex!

I am trying to modify the Free feeding code in order to have a light ON during the whole time when the Free feeding mode is active (12h per day). In other words, during the 12h when the Fed delivers food in Free feeding mode I would like a light to be constantly ON, and during the 12h when the Fed does not deliver food, the light should be OFF. In that way I want the mice to associate food access with light ON.

At the moment I have the problem that the light is only ON before the pellet is dispensed (i.e. during a few seconds) and then it is switched off when the pellet is in the magazine.
It feels like it would be a simple function to add but I do not know what. Do you have any idea?

Thanks a lot for your help, really appreciated!

Best,
Marie

Free feeding with light on.docx

Lex Kravitz

unread,
Aug 2, 2022, 3:59:19 PM8/2/22
to FEDforum
Hi Marie! 
The issue is that in the Feed() function (on line 150 of the FED3.cpp file) we call pixelsOff() when a pellet is detected in the well, which turns the pixels off.  This was done for the default behavior of FED3, where the pixels turn on in the ConditionedStimulus() function and turn off when the FED3 detects a pellet.  If you want to leave the pixels on even when a pellet is detected you will have to comment out line 150 of the FED3 library.

To do this, go to where your FED3 library is (probably C:\Users\<YOURUSERNAME>\Documents\Arduino\libraries\FED3\src\), and open FED3.cpp in a text editor.  Use two slashes "//" to comment out the call to pixelsOff() on line 150.  It will look like this:
//pixelsOff();

Then save the FED3.cpp file and reflash your FED3.  You will also want to disable sleep mode to leave the Neopixels on for long durations. 

Sorry this is such a hack, I'll think if I can come up with a simpler way to allow the pixels to stay on.  Anyway please post back if this works!
-Lex

Marie Le May

unread,
Aug 3, 2022, 9:25:45 AM8/3/22
to FEDforum
Hi Lex!
(I replied only to you so I am reposting so everyone can see and just to make sure you got it)

Thanks for your tips. I tried what you suggested but it did not help unfortunately... The light is still turned off when a pellet is dispensed.

I now attach the code of the whole menu program where Modes 2 and 3 and the Free feeding with light ON (for left and right active nose poke).
I have tried adding "fed3.disableSleep()" in addition to the " fed3.EnableSleep = false" that is in the code now, but it did not help.

Do you see anything else I could try?

Thanks a lot!

Best,
Marie
Menu code with FF with light on.docx

Marie Le May

unread,
Aug 4, 2022, 3:26:37 AM8/4/22
to FEDforum
Hi Lex,

Here is the ino file.
Thanks for your help!

Best,
Marie
AttentionFED3_LEFT_FF_12h.ino

Lex Kravitz

unread,
Aug 5, 2022, 10:51:15 AM8/5/22
to FEDforum
Hi Marie, and thanks for posting your code! 

The issue was deeper than I remembered but I have a solution for you. To give some background, the microprocessor, motor driver, and NeoPixels all burn power while idle and we wanted to reduce this to maximize battery life.  The sleep modes reduce the power draw from the microprocessor but do not stop the power draw from the motor driver and Neopixels.  To stop power draw from these components we included a transistor to cut their power.  In the code there are multiple calls to digitalWrite(MOTOR_ENABLE, HIGH) and digitalWrite(MOTOR_ENABLE, LOW), which toggle power to the motor driver and NeoPixels on and off respectively, only giving them power when they are being used.  So the reason you could not keep the NeoPixel lit was that the FED3 was still cutting power to the Neopixels independently of the sleep functions.

The solution I came up with was to link the motor/Neopixel power saving behavior to the microprocessor sleep modes.  So when sleep modes are enabled FED3 will cut power to the motor driver and Neopixels to save battery life.  But when sleep is disabled it will stop doing this.  This will now allow you to leave the NeoPixels on for as long as you want.  I think this is a good compromise that is not too hacky.

To test this out, update your FED3 library to v1.1.4.0 via the library manager:
1.jpg

This update should work seamlessly with your code, as long as sleep modes are disabled.  (Also you can just call fed3.disableSleep(); you don't need to also set enableSleep to false). Please also write back and let me know if this works for you. As you'll be the first tester besides me, please let me know if you discover any bugs!  

Best,
-Lex

Marie Le May

unread,
Aug 17, 2022, 3:52:28 AM8/17/22
to FEDforum
Hi Lex!

Updating my FED3 library to v1.14.0 did the job, thank you so much! 
But when I did the update all programs we had written and that were saved in Documents->Arduino got lost. Lucky I had saved most of them somewhere else!
So good to know to check that every program is saved somewhere safe before updating maybe.

Best,
Marie

Lex Kravitz

unread,
Aug 18, 2022, 9:21:53 AM8/18/22
to FEDforum
Whoops!  I should have specified that updating the library will overwrite any customizations you have made to the Arduino\libraries\FED3\ folder,. 

For this reason it is recommended not to save custom code in the Documents\Arduino\libraries\ folder, and use this only for libraries.  You can save custom code in Documents\Arduino\ (or anywhere else on your computer) just not in the \libraries folder.

Glad you had backups!
Reply all
Reply to author
Forward
0 new messages