Skip to content

New example of mlx90640 on PyGamer #5

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

Merged
merged 5 commits into from
Jan 8, 2020
Merged

New example of mlx90640 on PyGamer #5

merged 5 commits into from
Jan 8, 2020

Conversation

dglaude
Copy link
Contributor

@dglaude dglaude commented Jan 1, 2020

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

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.
@dglaude
Copy link
Contributor Author

dglaude commented Jan 1, 2020

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
Copy link
Contributor

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
Copy link
Contributor Author

dglaude commented Jan 2, 2020

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 32
5 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.

Make pylint happy ?
pylint will never like my use of global for min and max computation...
Remove the use of global to compute mini and maxi.
Require a1 and a2 as parameter and moving the min/max computation.
Also b1=0 to use all the color.
remove one more global
@dglaude
Copy link
Contributor Author

dglaude commented Jan 5, 2020

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
Copy link
Contributor

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.

@siddacious siddacious requested a review from a team January 7, 2020 01:15
@jepler
Copy link
Contributor

jepler commented Jan 7, 2020

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.

Copy link
Contributor

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great on my pygamer with the 110° FOV thermal camera. It could clearly be made more sophisticated, but that's not what examples are for.

@jepler jepler merged commit 874651c into adafruit:master Jan 8, 2020
@dglaude dglaude deleted the patch-1 branch January 8, 2020 01:25
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 15, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_HT16K33 to 2.6.0 from 2.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#47 from makermelissa/marquee
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#49 from makermelissa/matrix_scroll
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#41 from vdehors/master
  > Merge pull request adafruit/Adafruit_CircuitPython_HT16K33#46 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 2.0.0 from 1.0.0:
  > Update README.rst
  > Update README.rst
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#2 from adafruit/lsm6ds_refactor
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#1 from adafruit/dherrada-patch-1
  > added additional rates & sensor identifier

Updating https://github.com/adafruit/Adafruit_CircuitPython_MLX90640 to 1.0.2 from 1.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90640#7 from dglaude/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90640#8 from caternuson/iss2
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90640#5 from dglaude/patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_MLX90640#4 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing to 1.9.4 from 1.9.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_FeatherWing#51 from makermelissa/master
  > update pylint examples directive
  > Merge pull request adafruit/Adafruit_CircuitPython_FeatherWing#50 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_MotorKit to 1.3.3 from 1.3.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_MotorKit#24 from caternuson/iss23

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_LSM6DS
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

Successfully merging this pull request may close these issues.

3 participants