# Calibration value out of range

**URL:** <https://forums.openmv.io/t/calibration-value-out-of-range/6306>\
**Category:** OpenMV Boards\
**Created:** [September 6, 2021, 9:30am UTC](https://forums.openmv.io/t/calibration-value-out-of-range/6306 "2021-09-06T09:30:14Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [September 12, 2021, 3:38pm UTC](https://forums.openmv.io/t/calibration-value-out-of-range/6306/23 "2021-09-12T15:38:31Z")

</div>

I got a DS3231 module finally and I tested it and there’s nothing wrong with the library, you’re either using it wrong or the module you have is broken or doesn’t have a battery (does it have a battery ?)

Initially you have to set the external RTC time once, using the internal RTC:

```nohighlight
from ds3231_port import DS3231
from machine import Pin, I2C, RTC

i2c = I2C(sda = Pin('P5'), scl=Pin('P4'))
ds3231 = DS3231(i2c)

# Set Internal RTC time.
# (year, month, day, weekday, hours, minutes, seconds, subseconds)
RTC().datetime((2021, 9, 12, 1, 5, 20, 0, 0))

# Update External RTC time form the internal RTC.
ds3231.save_time()

print("DS3231 RTC Time:", ds3231.get_time())

```

Output:

```auto
>>> Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead
DS3231 RTC Time: (2021, 9, 12, 5, 20, 0, 0, 0)

```

Then disconnect the cam, leave it off for say 5 minutes and connect and run this:

```nohighlight
from ds3231_port import DS3231
from machine import Pin, I2C, RTC

i2c = I2C(sda = Pin('P5'), scl=Pin('P4'))
ds3231 = DS3231(i2c)

print("DS3231 RTC Time:", ds3231.get_time())

```

Output:

```nohighlight
>>> Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead
DS3231 RTC Time: (2021, 9, 12, 5, 25, 12, 0, 0)

```

You should something like this which is as expected.

You can also set the internal RTC from the external one, in boot.py/main.py and read it back with `time.localtime()`

`NOTE : This time will only be kept while the cam is connected to a power source.`

```nohighlight
from ds3231_port import DS3231
from machine import Pin, I2C, RTC

i2c = I2C(sda = Pin('P5'), scl=Pin('P4'))
ds3231 = DS3231(i2c)

# Set internal RTC from external RTC.
ds3231.get_time(set_rtc=True)

import time
print("Local time", time.localtime())

```

Note: the STM32 can use the hardware I2C (there’s no need to use the software I2C) in this case it’s I2C 2, to remove those warnings, for example:

```nohighlight
ds3231 = DS3231(I2C(2))
print(ds3231.get_time())

```

The only thing that I had issues with is the calibration, for some reason it returns a value way outside the range:

```auto
Pyboard 1.x. Waiting 5 minutes for calibration factor.
Error -37253823.3ppm -70894012.5mins/year. Cal factor 39050128
Calibration factor is 39050128

```

---

_[View the full topic](https://forums.openmv.io/t/calibration-value-out-of-range/6306)._
