# Lepton 3.5 Activating AGC

**URL:** <https://forums.openmv.io/t/lepton-3-5-activating-agc/7440>\
**Category:** OpenMV Boards\
**Created:** [August 26, 2022, 8:02am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440 "2022-08-26T08:02:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 26, 2022, 8:02am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/1 "2022-08-26T08:02:40Z")

</div>

Hi,  
According to my researchings, Lepton Sensor s AGC mode is disabled by default. There are 4 modes and I want to try each option. I found this code and I dont know what should I do right now. How should I suppose to change the variable in this code I changed this header and loaded.Now OpenMV Lepton vision kinda broken 😃

[https://github.com/openmv/openmv/blob/master/src/drivers/lepton/include/LEPTON\_AGC.h#L82](https://github.com/openmv/openmv/blob/master/src/drivers/lepton/include/LEPTON_AGC.h#L82)

Edit: Should I change LEP\_AGC\_ENABLE = 1 and delete LEP\_AGC\_DISABLE to enable AGC?

```auto
typedef enum LEP_AGC_ENABLE_TAG
{
   LEP_AGC_DISABLE = 0,
   LEP_AGC_ENABLE,
   LEP_END_AGC_ENABLE,
   LEP_AGC_ENABLE_MAKE_32_BIT_ENUM = 0x7FFFFFFF
}LEP_AGC_ENABLE_E, *LEP_AGC_ENABLE_E_PTR;

/* AGC Policy Enum
*/
typedef enum LEP_AGC_POLICY_TAG
{
   LEP_AGC_LINEAR = 0,
   LEP_AGC_HEQ,
   LEP_END_AGC_POLICY,
   LEP_AGC_POLICY_MAKE_32_BIT_ENUM = 0x7FFFFFFF
}LEP_AGC_POLICY_E, *LEP_AGC_POLICY_E_PTR;

```

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 26, 2022, 1:19pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/2 "2022-08-26T13:19:36Z")

</div>

yes I upgraded myself but im literally stuck now 😃

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 26, 2022, 2:11pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/3 "2022-08-26T14:11:43Z")

</div>

Hi, editing enums directly in a C header is not how one changes behavior… please reload the default firmware.

As for disabling AGC. We have an Ioctl in the sensor module that’s documented for doing this…

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 26, 2022, 2:32pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/4 "2022-08-26T14:32:38Z")

</div>

but you were said that FFC shutter mode can be changeable in firmware. And I thought that i can enable the AGC in firmware.

I couldnt activate the AGC in the script. And i thought that i can do in firmware. Probably i am totally wrong isnt it?  
If you know the solution could you please advice me?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 26, 2022, 3:46pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/5 "2022-08-26T15:46:39Z")

</div>

I sent you the command to execute in the other post. You didn’t have to change any firmware. You just needed to craft a byte array to give to the function call.

What exactly are you trying to do? You’re asking questions about modifying low level behavior versus just asking how to actually make application X happen.

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 29, 2022, 10:28am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/6 "2022-08-29T10:28:18Z")

</div>

Sorry I just have to complete my project for my school and I have not much time. I may be stressful in the forums. I really appreciative for your help. @kwagyeman @iabdalkader

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 29, 2022, 2:42pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/7 "2022-08-29T14:42:45Z")

</div>

But what did you need help with?

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 30, 2022, 9:46pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/9 "2022-08-30T21:46:52Z")

</div>

I need to detect alive creatures in the thermal image as fast as possible. But I have some issues about that:

Some thermal images are not enough good because of the cold and hot objects temperature difference. This issue can be resolve with activating AGC. So Im trying to activate AGC.

When the code executed, the lepton camera starting and this Lepton is activating the FFC mode immediately and according to this, the FFC mode is delaying to start to recordi g about 2.5 seconds. So I have to disable the FFC. Yes this can be cause some issues after 15 seconds. But i will record 100 frames at most. I dont think there will be a problem but if this will be a problem, I can enable the FFC shutter at the end of the code.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 30, 2022, 10:33pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/10 "2022-08-30T22:33:42Z")

</div>

Okay, I don’t have a fix for turning FFC off. If you want to do that you need to use a better sensor. The FLIR camera isn’t really something that works without FFC. I’d use an Melexis sensor. However, the resolution will be just 32x24.

As for turning AGC off: [sensor — camera sensor — MicroPython 1.15 documentation](https://docs.openmv.io/library/omv.sensor.html?highlight=flir#sensor.sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE)

AGC is on by default on the FLIR. You have to disable this explicitly in our code via an IOCTL to get actual temperature readings.

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 31, 2022, 11:09am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/11 "2022-08-31T11:09:57Z")

</div>

Thanks I searched the docs of `ioctl()` but I couldn’t find any function or command about turn on/off AGC.  
Maybe I couldnt see the command or there is a different way to disable or enable the AGC which is like `sensor.IOCTL_LEPTON_SET_ATTRIBUTE`.

Do you know the actual codeline about that?

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [August 31, 2022, 12:17pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/12 "2022-08-31T12:17:05Z")

</div>

dear friend … unfortunately flir sensor must start with ffc cause is the way it calibrate itself. The idea to turn on ffc after 15 sec will not help cause the sensor will be out of calibration…

Lets tell that you will do this… why dont you worry about the ffc after the 15 sec from power up?

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 31, 2022, 12:28pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/13 "2022-08-31T12:28:36Z")

</div>

@oramafanis Thanks for your reply. The reason that I do not worry about the FFC after 15 secs is that I should not lose the image in the very beginning of my record, however I may lose the one at the end. I mean, the first capture is the capture that I mainly want to have but after 15 secs, my system will go to sleep mode and there will be no problem if I lose 2.5 secs at the end.

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 31, 2022, 12:35pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/14 "2022-08-31T12:35:32Z")

</div>

Hi @kwagyeman @oramafanis @iabdalkader ,  
I did something like this and I think that maybe will this format i think.

```auto
sensor.ioctl(sensor.IOCTL_LEPTON_SET_MEASUREMENT_MODE, True)
data1 = struct.pack(">HH", 0,1) 
sensor.ioctl(sensor.IOCTL_LEPTON_SET_ATTRIBUTE, 0x0100, data1)

```

According to this struct:

 ![Ekran Alıntısı](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/4/4574af05b0b9d2dcb20d36d462c40fb8801442fb.png)

I think I set the values of ` LEP_AGC_ENABLE = 1 LEP_AGC_DISABLE = 0`

Result image is kinda broken 😃 where is the problem?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 31, 2022, 1:41pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/15 "2022-08-31T13:41:30Z")

</div>

Set measurement mode literal does this for you. It turns AGC off when you call it.

Just use the ioctl set attribute to turn off the FFC process.

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 31, 2022, 1:46pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/16 "2022-08-31T13:46:01Z")

</div>

Yes I know this and I wrote a code block and it doesnt work. Also I do know that I can turn off the FFC with ioctl but i dont know exactly how.(Set attribute what, set variables what etc )

---

<div class="post-metadata">

**Author:** ![oramafanis](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/oramafanis/32/1783_2.png) [@oramafanis](https://forums.openmv.io/u/oramafanis)\
**Post date:** [August 31, 2022, 2:08pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/17 "2022-08-31T14:08:52Z")

</div>

> [@BehicMV](#):
>
> w this and I wrote a code block and it doesnt work. Also I do know that I can turn off the FFC with ioctl but i dont know exactly how.(Set attribute what, set variables what etc )

so as i understand you first have a proximity sensor that wakes up camera. then camera must see some temp so to decide that there is an animal. and then it sleeps again waiting the next trigger.

What you dont understand is that the image will never be the same with the sensor uncalibrated. you cant rely on this image unfortunately…

A solution maybe is a sensor that you manually calibrated with a plate. I think that lepton 2 series doesn’t have auto calibrate fuction … have a look at them…

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [August 31, 2022, 2:15pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/18 "2022-08-31T14:15:57Z")

</div>

@oramafanis You understood it end-to-end correctly. Thanks a lot for your reply. I’d love to ask one more further question to make everything clear for myself.

My system will remain its position for a long time which means the temperature of the environment will not be changing. As far as I know, FFC/Shutter mode exists to calibrate the temperature and the objects’ temperature around the environment. Since the temperatures of every object remains same, I believe I will not need a shutter for every wake-up, will I?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [August 31, 2022, 2:56pm UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/19 "2022-08-31T14:56:15Z")

</div>

Yes, so, I previously gave you a link to the command you’ll need to execute to turn FFC off. I don’t know the argument necessary however as I don’t think the sensor will continue to work if you do this and this I have never tried. But, you can try and maybe you might get a result you will like.

If you look through the API there’s no straight forward disable FFC option though…

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [September 1, 2022, 5:27am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/20 "2022-09-01T05:27:36Z")

</div>

Alright @kwagyeman I ll keep trying this. However, since this is enabling/disabling AGC topic, I wonder how to enable/disable AGC like I wodered in FFC topic.

I ve done like that as I said before: [Lepton 3.5 Activating AGC - #14 by BehicMV](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/14)

However this code broke my image. So, anyone have an idea of code line?

---

<div class="post-metadata">

**Author:** ![BehicMV](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/behicmv/32/2233_2.png) [@BehicMV](https://forums.openmv.io/u/BehicMV)\
**Post date:** [September 1, 2022, 5:50am UTC](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440/21 "2022-09-01T05:50:53Z")

</div>

Here are my codes and the results with cold water and hot water tests:

Measurement mode and unpack struct:

 ![Screenshot_1](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/b/b2f2f0368ff12df207939e759d9e4e751028e683.png)

Only unpack the struct

 ![Screenshot_2](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/3/373b39a48d48c4086f49eed5f0f2cca1475d0150.png)

Only the Measurement mode:

 ![Screenshot_3](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/c/c166726775ad754183975ebdfa34c3375012681f.png)

What should I do @kwagyeman @iabdalkader @oramafanis?

[Next page](https://forums.openmv.io/t/lepton-3-5-activating-agc/7440.md?page=2)
