adafruit / Adafruit_CircuitPython_MLX90640

A pure Python MLX90640 driver
MIT License
65 stars 20 forks source link

New example of mlx90640 on PyGamer #5

Closed dglaude closed 4 years ago

dglaude commented 4 years ago

This example does the following: 1) Create a color gradient into a palette of 64 colors ( using code from http://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients )

In Loop: 2) Scan the mlx90640 at 4HZ (works for me with a refresh ever 0.4x seconds) 3) Map the temperature to palette index in a min to max range (anything below min goes to index 0 and above max to index 63) 4) While mapping the color, compute a new min and a new max for adjusting the color scale. 5) Display the min and max temperature and the color scale below the image

dglaude commented 4 years ago

I don't have access to that hardware for the moment... Sorry, it might take a while before I can make the change suggested by the automatic test (and verify it still works). Anyway, my suggestion would be for someone from Adafruit to test this code on their hardware and confirm it is working. If the person doing that want to make any kind of change, that's fine.

There are a lot of possible enhancement for this code to fully use the PyGamer capabilities: 1) Show (one way or another) on the screen the hotspot (or cold spot). 2) Use the button of the PyGamer to let the user switch from one color gradian to another. 3) Let the user freeze/re-enable the auto-scaling of the temperature range. 4) Use the joystic to select one of the sensor point and display the temperature of that specific location. 5) Have a "printscreen" button to take a capture as file of the current screen for future reference.

siddacious commented 4 years ago

hey @dglaude , awesome work! This is a great example. I'm happy to test this when my MLX90640 arrives if someone doesn't beat me to it. I'll go ahead and test on the PyBadge/Edge Badge and HalloWing M4 as well as I think it should work on them.

Regarding the PyLint errors, it's just a bit of formatting that needs to be tweaked. No rush on our end; you can work on fixing them when you've got access to hardware again. The warning messages are fairly self explanatory. We've got a great guide on PyLint that you can refer to: https://learn.adafruit.com/improve-your-code-with-pylint/overview

Additionally feel free to ask any questions here and I'm glad to help.

dglaude commented 4 years ago

Hi @siddacious,

No doubt this would work on PyBadge and Edge Badge as it is the same resolution. While the screen is 160128, I use less than that. Initial code was using a scale of 5 to make 325 x 24*5 for a 160 x 120 leaving only 8 pixel unused.

But that was not leaving enough space for displaying min and max. So now this is 32x4 x 24x4 for 128x96. (scale 4 of 32x24). One line of text in terminalio.FONT (8 pixels). In addition to that you need a 128x2 pixel for the gradian (scale 2 of 64x1).

That fit on a HalloWingM0 kind of screen 128x128 (this is what I have used in the past on a PiZero. Now to fit on your HalloWingM4 (more likely to work I guess) you would want to fill 240x240. You could take a scale 7 of 32x24 to make 224x168 and scale of 3 for the gradian to have 192x3. And maybe center horizontally both. I don't know how to scale a font, so you may want a bigger font to make things more readable.

Here are my original source code (various version with enhancement and link to video/image on Twitter where I do microblogging): https://gist.github.com/dglaude/2d21262b1c776e7279f39258876d32d6

However be aware that there is competition on the PyBadger and Eduardo has shown his own version on "Show and Tell" of 2020/1/1: https://www.youtube.com/watch?v=ENVEeFbJBQ8&t=925 He seems to use the A and B button, B for menu and A for capture !!! Also he display a frame number or something, and the average (or median) temperature. I would love to see his code, there might be room for cross sharing feature.

dglaude commented 4 years ago

Sorry, my local install of pylint was reporting more than the one running here... so it took a few try to pass the test (and it still work on the hardware).

siddacious commented 4 years ago

Awesome, thanks @dglaude . Unfortunately I make a mistake and didn't order the mlx when I thought I did so there may be a delay in testing unless I can find someone else to test.

jepler commented 4 years ago

I mentioned on Discord that I'd made something similar but it looks like @dglaude 's is more polished. I'll grab it and take a look this evening.