# Openmv H7 plus device fail

**URL:** <https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943>\
**Category:** OpenMV Boards\
**Created:** [November 17, 2023, 8:27am UTC](https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943 "2023-11-17T08:27:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YanHe](https://avatars.discourse-cdn.com/v4/letter/y/ecb155/32.png) [@YanHe](https://forums.openmv.io/u/YanHe)\
**Post date:** [November 17, 2023, 8:27am UTC](https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943/1 "2023-11-17T08:27:18Z")

</div>

Hello Sir,  
We use H7 plus in our project. And we got a situation when we connect with USB port in win11.

 ![螢幕擷取畫面 2023-11-08 105537](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/0/01653d639491efe26c042bf05a126941ad8762b7.png)

Do you have any suggestion why and how it’s happened?

---

<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:** [November 17, 2023, 1:11pm UTC](https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943/2 "2023-11-17T13:11:07Z")

</div>

There can be any number of reasons why the flash drive is corrupted. However, it’s not a firmware issue as we have logged thousands upon thousands of hours now without issues with the flash drive.

It’s probably related to what you are doing in your firmware. I’d try to reduce your program to the minimum size to cause the error. Then post that.

---

<div class="post-metadata">

**Author:** ![YanHe](https://avatars.discourse-cdn.com/v4/letter/y/ecb155/32.png) [@YanHe](https://forums.openmv.io/u/YanHe)\
**Post date:** [November 20, 2023, 5:53am UTC](https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943/3 "2023-11-20T05:53:34Z")

</div>

Here is our program. This code is try to find a line.

> import sensor, image  
> from pyb import Pin  
> def DoImageProcess(frame, anchors, pi7, pi6):  
> standard\_length = 300  
> kernel\_size = 1  
> kernel = [1, 0, -1, 2, 0, -2, 1, 0, -1]  
> anchor\_count = 5  
> min\_angle = 30  
> img = sensor.snapshot()  
> stat = img.get\_statistics()  
> labValue = (stat.l\_mean(), stat.a\_mean(), stat.b\_mean())  
> rgbValue = image.lab\_to\_rgb(labValue)  
> grayValue = 0.299_rgbValue[0] + 0.587_rgbValue[1] + 0.114_rgbValue[2]  
> if (grayValue \< 50):  
> print(frame, 6, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> if (grayValue \> 230):  
> print(frame, 7, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> resetFlag = pi6.value()  
> if(resetFlag == 1):  
> print(frame, 2, -1, 0, 0, 0, 0, 0, 0, 0)  
> anchors = []  
> return img, anchors  
> #jumpFlag = pi7.value()  
> jumpFlag = 0  
> if (jumpFlag == 1):  
> print(frame, 3, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> img.morph(kernel\_size, kernel)  
> img.erode(2)  
> img.lens\_corr(0.6)  
> stat = img.get\_statistics()  
> labValue = (stat.l\_stdev(), stat.a\_stdev(), stat.b\_stdev())  
> rgbValue = image.lab\_to\_rgb(labValue)  
> stdevValue = 0.299_rgbValue[0] + 0.587_rgbValue[1] + 0.114_rgbValue[2]  
> all\_lines = img.find\_lines(threshold = 500)  
> if (len(all\_lines) \< 1):  
> print(frame, 4, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> if (len(anchors) \>= anchor\_count) :  
> anchors\_x, anchors\_angle, anchors\_m, anchors\_lsq = GetAnchors(anchors, standard\_length)  
> anchors\_x = int(anchors\_x)  
> select\_line = SelectLine(all\_lines, anchors\_x, img.width(), min\_angle)  
> if select\_line == -1:  
> print(frame, 5, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> del anchors[0]  
> select\_x = int((select\_line.x1() + select\_line.x2()) / 2)  
> angle = select\_line.theta()  
> if (angle \> 90):  
> angle -= 180  
> distance = abs(anchors\_x - select\_x)  
> if ( anchors\_x \> select\_x):  
> count = round(distance / standard\_length)  
> else:  
> count = -round(distance / standard\_length)  
> anchors.append((select\_x, angle , count))  
> select\_x += count _standard\_length  
> print(frame, 1, select\_x, angle, count, anchors\_m, anchors\_lsq, grayValue, stdevValue, 0)  
> img.draw\_line(anchors\_x, 0, anchors\_x, img.height() - 1, color = (255, 0, 0), thickness=3)  
> img.draw\_line(select\_line.x1(), 0, select\_line.x2(), img.height() - 1, color = (255, 0, 255),thickness=1)  
> else:  
> anchors\_search = 0  
> if (len(anchors) \< anchor\_count / 2):  
> anchors\_search = img.width() / 2  
> else:  
> anchors\_search, anchors\_angle, anchors\_m, anchors\_lsq = GetAnchors(anchors, standard\_length)  
> anchors\_search = int(anchors\_search)  
> select\_line = SelectLine(all\_lines, anchors\_search, img.width(), min\_angle)  
> if select\_line != -1:  
> x = int((select\_line.x1() + select\_line.x2()) / 2)  
> angle = select\_line.theta()  
> if (angle \> 90):  
> angle -= 180  
> anchors.append((x, angle, 0))  
> img.draw\_line(select\_line.line(), color = (0, 255, 0),thickness=3)  
> print(frame, 0, -1, 0, 0, 0, 0, 0, 0, 0)  
> return img, anchors  
> def SelectLine(lines, anchors\_x, width, min\_angle):  
> min\_distance = 999999  
> select\_line = -1  
> for i in range(len(lines)):  
> l = lines[i]  
> x = int(( l.x1() + l.x2()) / 2)  
> distance = abs(x - anchors\_x)  
> if (l.theta() \> 90):  
> angle = 180 - l.theta()  
> else:  
> angle = l.theta()  
> if (distance \< min\_distance) and (angle \< min\_angle) :  
> min\_distance = distance  
> select\_line = l  
> return select\_line  
> def GetAnchors(anchors, standard\_length):  
> if len(anchors) \< 1:  
> return 0, 0  
> x = 0  
> angle = 0  
> avg\_x = 0  
> avg\_y = 0  
> avg\_xy = 0  
> avg\_xx = 0  
> for i in range(len(anchors)):  
> temp = anchors[i][0] + standard\_length \* anchors[i][2]  
> x += temp  
> angle += anchors[i][1]  
> avg\_x += i  
> avg\_y += temp  
> avg\_xy += i \* temp  
> avg\_xx += i \* i  
> x /= len(anchors)  
> angle /= len(anchors)  
> avg\_x /= len(anchors)  
> avg\_y /= len(anchors)  
> avg\_xy /= len(anchors)  
> avg\_xx /= len(anchors)  
> m = (avg\_xy - avg\_x_avg\_y) / (avg\_xx - avg\_x \* avg\_x)  
> b = avg\_y - m \* avg\_x  
> lsq = 0  
> for i in range(len(anchors)):  
> temp = anchors[i][0] + standard\_length \* anchors[i][2]  
> lsq += abs((m \* i + b) - temp)  
> return x, angle, m, lsq  
> if **name** == ‘ **main** ’:  
> sensor.reset()  
> sensor.set\_pixformat(sensor.RGB565)  
> sensor.set\_framesize(sensor.VGA)  
> sensor.set\_auto\_exposure(False, 50000)  
> sensor.set\_auto\_gain(False)  
> sensor.set\_auto\_whitebal(False)  
> sensor.set\_windowing((540, 320))  
> pi7 = Pin(“P7”, Pin.IN)  
> pi6 = Pin(“P6”, Pin.IN)  
> frame = -1  
> anchors =   
> while (True):  
> frame = (frame + 1) % 1000  
> img, anchors = DoImageProcess(frame, anchors, pi7, pi6 )

In hardware, we connect with USB port, 2 I/O port, and power connection.

---

<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:** [November 20, 2023, 2:39pm UTC](https://forums.openmv.io/t/openmv-h7-plus-device-fail/8943/4 "2023-11-20T14:39:18Z")

</div>

You need to reduce the program to just what causes the error for us to debug. Please do not provide your whole program and say “please fix”.
