# Unexpected import problem RT1062 and SD card

**URL:** <https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124>\
**Category:** OpenMV Boards\
**Created:** [January 19, 2024, 4:09pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124 "2024-01-19T16:09:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 19, 2024, 4:09pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/1 "2024-01-19T16:09:47Z")

</div>

Hi,

I am upgrading the Wifi RTSP example to provide some more functions. When importing machine(for IO) and socket (for NTP) and running in the IDE everything works fine. However if you save to openmv SD card the script then fails to get started (I have also added an LED step as the first thing to prove it)

To replicate simply take your sample WLAN RTSP and add these after the other imports:  
import machine  
import socket

Save to openmv with an SD card connected, restart the camera and the script will not start. The UI also starts behaving oddly with errors trying to connect to the camera.

---

<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:** [January 19, 2024, 6:49pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/2 "2024-01-19T18:49:52Z")

</div>

Hi, I just did that and it’s working fine with the latest firmware.

Did you update to the latest? We released an emergency patch about a month ago that fixed a serious issue with the main.py script being saved to an SD card.

Also, potentially install the latest dev firmware.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 20, 2024, 4:32pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/3 "2024-01-20T16:32:59Z")

</div>

Hi,

I was running 4.5.2. However, upgrading to latest has fixed it!

Thanks very much!

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 22, 2024, 11:29am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/4 "2024-01-22T11:29:53Z")

</div>

Hi,

I have more info as I tested again using the camera settings I need (HD 720P). I add an LED to indicate when the camera is ready to stream. The modified sample runs fine in the IDE with HD as the resolution, it runs fine when saved to the internal disk, but fails to run from the SD. No LED or stream. NB all works fine without the HD or without the LED. Occasionally it does work though. I guess it depends on the scene as to how much memory is needed.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 22, 2024, 11:34am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/5 "2024-01-22T11:34:28Z")

</div>

[rtsp\_video\_server\_wlan\_3.py](https://forums.openmv.io/uploads/short-url/2zSrmZQ3aWmBVrnSqrVOOasZm2e.py) (3.2 KB)

---

<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:** [January 22, 2024, 7:23pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/6 "2024-01-22T19:23:07Z")

</div>

Yeah, I am getting the same error…

Not sure what’s wrong. However, this works instead and better. You should be able to do 30 FPS at 1280x720 from the OV5640:

Replace the sensor code with this:

```auto
sensor.set_pixformat(sensor.JPEG)
sensor.set_framesize(sensor.HD)
sensor.set_quality(80)

```

And use this binary for the RT1062.  
[firmware.zip](https://forums.openmv.io/uploads/short-url/AiKGzWKHqZ0vWeDPK1LM1eyciOX.zip) (1.3 MB)

Once this PR is merged [port/mimxrt: Improve Sensor Driver. by kwagyeman · Pull Request #2102 · openmv/openmv (github.com)](https://github.com/openmv/openmv/pull/2102) JPEG support will be mainlined.

I can also start on eDMA offload support afterwards for the RT1062 which should bring the performance generally up to the STM32H7 when the system is loaded at larger resolutions. This will remove the CPU load from copying image lines to the frame buffer as the image streams in.

---

<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:** [January 22, 2024, 7:24pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/7 "2024-01-22T19:24:50Z")

</div>

The issue may have been this: [port/mimxrt: Improve Sensor Driver. by kwagyeman · Pull Request #2102 · openmv/openmv (github.com)](https://github.com/openmv/openmv/pull/2102)

The Frame Buffer Memory sizes are set way too small.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 22, 2024, 9:46pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/8 "2024-01-22T21:46:20Z")

</div>

Again, thanks very much for the alternative approach. Unfortunately I am overlaying text on the image, so compression must be by CPU. (1 FPS is enough for the application.)

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 22, 2024, 10:18pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/9 "2024-01-22T22:18:44Z")

</div>

Also, if it is a buffer size issue, why does the large frame size stream work in the ide? (And on the internal disk)

---

<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:** [January 22, 2024, 10:42pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/10 "2024-01-22T22:42:00Z")

</div>

Mmm, it wouldn’t explain that.

Sorry, I am responding to the multiple threads you have at the same time. For VGA AprilTags we’d allocate 8-10x at minimum before the heap the amount of frame size in RAM. So, it would explain that running low on resources.

However, this is unrelated. Let me re-check with the new firmware if the issue still happens.

---

<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:** [January 22, 2024, 10:52pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/11 "2024-01-22T22:52:53Z")

</div>

It works now with that PR compiled in.

It might be this: [openmv/src/omv/ports/mimxrt/sensor.c at master · openmv/openmv (github.com)](https://github.com/openmv/openmv/blob/master/src/omv/ports/mimxrt/sensor.c#L184)

I found a bug in the sensor driver that can lead to a null pointer deference that the PR fixes.

I noticed that when it crashed it was immediate which is usually a null pointer issue in the code since you get a bus fault when you do things like that which cause an instant reset.

…

The above null pointer issue would be triggered only in very particular cases. In triple buffer mode it wouldn’t be. But, it would happen in double buffer mode.

---

<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:** [January 22, 2024, 10:54pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/12 "2024-01-22T22:54:42Z")

</div>

[firmware.zip](https://forums.openmv.io/uploads/short-url/dwLz9jzqccMGXZfNHn93MGudJsE.zip) (1.3 MB)

New firmware with deepsleep fix.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 23, 2024, 9:34am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/13 "2024-01-23T09:34:11Z")

</div>

Hi,

Thanks very for the deep sleep/wake fix. That’s now working again.

I am still getting a crash when using the SD card with the resolution set to VGA. I have cut my code down to a minimum (there is NTP, & timer based overlay and saving/retrieving stills to SD I have cut out) to follow for you.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 23, 2024, 9:34am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/14 "2024-01-23T09:34:27Z")

</div>

[IP CAMERA rtsp\_video\_server\_wlan\_1 min reproduction for sd.py](https://forums.openmv.io/uploads/short-url/oKvD3oGsWVs1ZOF0GZejBRC4Mqu.py) (4.3 KB)

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 23, 2024, 9:35am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/15 "2024-01-23T09:35:50Z")

</div>

It goes into deep sleep when the client disconnects, so the next time it runs will be from the SD card. Now it does wake, but instantly crashes.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 23, 2024, 9:37am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/16 "2024-01-23T09:37:36Z")

</div>

NB I was using double buffered initially, but that I commented out pretty early on yesterday in case it was a memory issue.

---

<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:** [January 23, 2024, 7:29pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/17 "2024-01-23T19:29:06Z")

</div>

Hi, it’s working on my camera with the script you gave me. It handles going between off and on.

I would say though, it didn’t work initially. It appears my disk was corrupted slightly and windows needed to scan and fix it. So, you should probably mount the SD card on your laptop, scan and fix the drive. Then save the code to main.py there.

After I fixed the drive everything works as expected.

---

<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:** [January 23, 2024, 7:29pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/18 "2024-01-23T19:29:59Z")

</div>

Avoid using double buffering. The system will triple buffer by default as long as it has RAM. And with the firmware above it’s hard to run out now given you have all 32MB enabled.

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 23, 2024, 7:56pm UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/19 "2024-01-23T19:56:59Z")

</div>

Ok I will try that in the morning. Thanks for the tip. Then assuming it works I will try the whole script.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Stub](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stub](https://forums.openmv.io/u/Stub)\
**Post date:** [January 24, 2024, 9:55am UTC](https://forums.openmv.io/t/unexpected-import-problem-rt1062-and-sd-card/9124/20 "2024-01-24T09:55:28Z")

</div>

Hi, I tried the check disk. Still no joy. So I broke out a new SD card and all is well! (Oddly the PC seems OK with the original card. It must have a fault that the PC can’t/doesn’t report.) So all is well with the full version of the IP camera code too.

Thanks for the tip as it put me on the right track - faulty SD. And the wake fix.
