Tracking Raspberry Pi Internal Temperatures in Computer Vision Apps
by Lila Mullany | Mar 24, 2020 | Computer Vision | 10 minute read
by Lila Mullany | Mar 24, 2020 | Computer Vision | 10 minute read
Running computer vision applications (or AI applications in general) can put a strain on an edge device, especially when combining models. Using a heat sink in conjunction with a fan is probably sufficient to keep the device from throttling, but it would be helpful to be notified before your device becomes this hot. Being alerted to potentially unsafe temperature enables you to stop your app before the device burns out, and to continue to monitor the temperature — giving you the option to restart the program when the device has sufficiently cooled off.
To that end, we have created a utility class that enables you to track and record temperature readings, and which provides a summary of the collected data.
This tutorial uses a Raspberry Pi 4 and the package ‘gpiozero’, which comes installed by default on the Raspbian OS image. For more information on this package, see the following link.
To complete the tutorial, you must have:
Please see the alwaysAI blog to learn more about computer vision, developing models, how to change models, and more.
All of the code from this tutorial is available on GitHub.
There will be two main parts to this tutorial:
Let’s get started!
After you have your free account and have set up your developer environment, you’ll need to download all of the starter apps; do so using this link before proceeding with the rest of the tutorial.
The app that was modified for this tutorial was the ‘Object Detector’ app, so cd into the starter apps folder and then into the ‘realtime_object_detector’ folder.
NOTE: if your Pi is not connected to wifi, it will not be able to download the requirements in requirements.txt
2. Updating the app.py file to use the TemperatureTracker:
from temperature_tracker import TemperatureTracker
temperature_tracker = TemperatureTracker()
temperature_tracker.start()
temperature_tracker.update()
NOTE: I added a blank line for readability after the ‘for prediction in predictions’ loop and before the temperature statements. This can be done any time you want more readability in the streamer text output with ‘text.append(“”)’.
now = temperature_tracker.now()
# log block showing current temperature
text.append(“{:1.2f}C/{:1.2f}F at time {}\n”.format(now[0], ((now[0]*(9 / 5)) + 32),time.strftime(‘%Y-%m-%d %H:%M:%S’, now[1])))# details whether the temperature is safe for a Raspberry Pi 4
if now[0] < temperature_tracker.MAX_TEMP_RASP4:
text.append(“Temperature is safe”)
else:
text.append(“TEMPERATURE IS NO LONGER SAFE”)
NOTE: If you do not see the warning message on the streamer before the application stops, this means that the browser feed did not refresh before the application stopped. You will still see this warning message on the console once the program stops.
if now[0] >= temperature_tracker.MAX_TEMP_RASP4:
print(“Maximum safe temperature reached, stopping program”)
break
temperature_tracker.stop()
summary = temperature_tracker.summary()
print(summary)
That’s it! Now you can build and start your app to see it in action. You may want to configure the app first, especially if you changed edge devices or created a new folder from scratch. You can do this with the following command, and enter the desired configuration input when prompted:
aai app configure
Now, to see your app in action, first build the app by typing into the command line:
aai app install
And once it is done building, start the app with the command:
aai app start
Open the browser to localhost:5000 to see the app in action, and watch the console after terminating the program for a summary of your temperature data, as shown below.