Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adafruit mlx90640_camtest.py example does a "black screen" in RPi4 #22

Open
Pedalbo opened this issue Nov 26, 2020 · 9 comments
Open

Adafruit mlx90640_camtest.py example does a "black screen" in RPi4 #22

Pedalbo opened this issue Nov 26, 2020 · 9 comments

Comments

@Pedalbo
Copy link

Pedalbo commented Nov 26, 2020

The example from adafruit (mlx90640_camtest.py) crashes the RPi4 all the time! This means that when I run the example, the screen goes black and I need to shut down the RPi4. Don't even have time to get the error. The example mlx90640_simpletest.py and also mlx90640_pil.py works good though... any thoughts?

@Pedalbo Pedalbo changed the title adafruit mlx90640_camtest.py example crashes in the RPi4 Adafruit mlx90640_camtest.py example craches in RPi4 Nov 26, 2020
@Pedalbo Pedalbo changed the title Adafruit mlx90640_camtest.py example craches in RPi4 Adafruit mlx90640_camtest.py example does a "black screen" in RPi4 Nov 26, 2020
@ladyada
Copy link
Member

ladyada commented Nov 26, 2020

you need to run it from a command line or something to get the error message

@ladyada ladyada transferred this issue from adafruit/Adafruit_Blinka Nov 26, 2020
@Paul760
Copy link

Paul760 commented Apr 24, 2021

I have the same problem. I got an adafruit MLX90640 today. Testing it now with my Raspberry Pi 4 with 4gb RAM gives an working mlx90640_simpletest.py. From the command line is nice and smooth. I can see my face :-)

But the mlx90640_camtest.py is not working. It gives a black screen. The error I see is:

pi@desktop1:~/Adafruit_CircuitPython_MLX90640/examples $ python3 mlx90640_camtest.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
<VideoInfo(hw = 0, wm = 1,video_mem = 0
         blit_hw = 0, blit_hw_CC = 0, blit_hw_A = 0,
         blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
         bitsize  = 32, bytesize = 4,
         masks =  (16711680, 65280, 255, 0),
         shifts = (16, 8, 0, 0),
         losses =  (0, 0, 0, 8),
         current_w = 2560, current_h = 1440
>

MLX addr detected on I2C, Serial # ['0x1223', '0xb6ea', '0x189']
6
Refresh rate:  32 Hz
Traceback (most recent call last):
  File "mlx90640_camtest.py", line 124, in <module>
    mlx.getFrame(frame)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mlx90640.py", line 126, in getFrame
    status = self._GetFrameData(mlx90640Frame)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mlx90640.py", line 155, in _GetFrameData
    raise RuntimeError("Too many retries")
RuntimeError: Too many retries

@BLIII
Copy link
Contributor

BLIII commented May 7, 2021

I have experienced the same issue that @Paul760 referenced above. My implementation is custom and actually does not output anything to a screen; it just reads temps. I am running my code on a Raspberry Pi 3 B+.

At first, I thought this may have been a frequency issue because I was trying to run the camera at 32Hz however it also happens at 16Hz and 8Hz as well.

I know that the runtime error is getting thrown from this section of code but I don't quite understand the reason behind keeping a count within the while loop and then raising a runtime error of "too many retries". I will say that if I remove the following two lines from the code, the implementation seems to work just fine. I just don't know the history behind it so I am not comfortable pushing a PR to remove it unless I am confident it is not needed. Does anyone know the reason for why it exists?

        if cnt > 4:
            raise RuntimeError("Too many retries")

@renegade2k
Copy link

renegade2k commented Nov 4, 2021

Well, as i was just stuck at the same point and was searching for a workaround for lot of time now, there it goes:
simply change the refresh rate for the "working on image"-code of the example to a lower rate.
There for you must change the line:
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_8_HZ # set refresh rate
to
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ # set refresh rate

This will make the code work at least for the beginning phase.
Also this will result in a 0.2 fps video, so don't expect too much.

@ladyada
Copy link
Member

ladyada commented Nov 5, 2021

unclear why some pi+camera combos are fine at higher rate and some are not (we wrote the code on a pi 4 originally so it ought to still work?) .

if someone can update the example to put a hint about trying different refresh rates, and submit a PR, that would be great!

@BLIII
Copy link
Contributor

BLIII commented Nov 6, 2021

Is this what you had in mind, @ladyada? I figured adding the comment to the main README would be a better spot than adding comments to each example in the examples directory. If you would like to see that though, let me know and I can re-submit.

#27

@ladyada
Copy link
Member

ladyada commented Nov 6, 2021

sure, seems fine - other folks in this thread can check it out too

@Chimajero
Copy link

hi!, recently I have acquired two mlx modules,
At first, I also had errors between 8 and 64 hz on Raspberry Pi Zero 2 W.

On melexis github, there is a closed issue that talks about "of too many retries":

melexis/mlx90640-library#57

A commit was made in April 2020 to solve it.
There are changes in:

int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData);

and two new method:

int ValidateFrameData(uint16_t *frameData)
int ValidateAuxData(uint16_t *auxData)

I tried to do the same on my local library:

def _GetFrameData(self, frameData):
        dataReady = 0
        cnt = 0
        statusRegister = [0]
        controlRegister = [0]
        data =[0]*64
        while dataReady == 0:
            self._I2CReadWords(0x8000, statusRegister)
            dataReady = statusRegister[0] & 0x0008
            # print("ready status: 0x%x" % dataReady)
        self._I2CWriteWord(0x8000, 0x0030)
        self._I2CReadWords(0x0400, frameData, end=768)
        self._I2CReadWords(0x0700, data, end=64)
        self._I2CReadWords(0x800D, controlRegister)
        frameData[832] = controlRegister[0]
        frameData[833] = statusRegister[0] & 0x0001
        
        returned_data = self._ValidateAuxData(data)
       
        if returned_data == 0:
            for cnt in range(0,64):
                frameData[cnt+768]= data[cnt]
                
        returned_data = self._ValidateFrameData(frameData)
        if returned_data != 0:
            raise RuntimeError("_ValidateFrameData_error",-2)
        return frameData[833]
def _ValidateAuxData(self, auxData):
        if auxData[0] == 0x7FFF:
            return -8
        for i in range(8,19):
            if(auxData[i] == 0x7FFF):
                return -8
        for i in range(20,23):
            if(auxData[i] == 0x7FFF):
                return -8
        for i in range(24,33):
            if(auxData[i] == 0x7FFF):
                return -8
        for i in range(40,51):
            if(auxData[i] == 0x7FFF):
                return -8
        for i in range(52,55):
            if(auxData[i] == 0x7FFF):
                return -8
        for i in range(56,64):
            if(auxData[i] == 0x7FFF):
                return -8
        return 0;
    def _ValidateFrameData(self, frameData):
        line = 0
        for i in range(0,768,32):
            if (frameData[i] == 0x7FFF) and (line%2 == frameData[833]):
                return -8
            line = line + 1
        return 0

Now I can increase the frequency, but the frame rate is slow. That's why I have added in /boot/config.txt, this line

dtparam=i2c_arm_baudrate=1000000

(Beware, if there are other modules on the same i2c they may dont like the line on /boot/config.txt )

Now works in 8hz, 16hz, 34hz, 62hz, but sometimes there are other errors: I2c, math errors in sqrt, division by zero..( on high frequencies ). I added a block "try-except-continue" on my main to "hide those errors" and when they occur i read a new frame again. Maybe someone can do this better, I'm a python newbie.

(There are other new methods on melexis API)

@ladyada
Copy link
Member

ladyada commented Jul 10, 2022

thanks, if someone is up for adding the new validation functions to a PR we can review and add them to the library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants