Advertisement
Python253

pico_temp

Mar 2nd, 2024
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.79 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: pico_temp.py
  4. # Author: Jeoi Reqi
  5.  
  6.  
  7. """
  8. This CircuitPython script performs a one-minute scan of the CPU temperature and voltage.
  9. It prints real-time values for each 0.25-second interval, providing a dynamic view of the CPU's thermal & electrical characteristics.
  10. The script concludes by displaying the average temperature and voltage over the scanning period.
  11. Use it to assess how your CircuitPython device handles temperature and voltage under various conditions.
  12. Enjoy monitoring the 🔥temperature🔥 and ⚡voltage⚡ of your CircuitPython device!
  13.  
  14. Requirements:
  15. - CircuitPython compatible device
  16. - microcontroller library
  17. - time library
  18.  
  19. Usage:
  20. 1. Connect your CircuitPython compatible device to your computer.
  21. 2. Copy the script to the device's storage.
  22. 3. Run the script using a CircuitPython-compatible IDE or command-line interface.
  23. 4. Observe the real-time CPU temperature and voltage readings for one minute.
  24. 5. Analyze the average temperature and voltage values at the end of the scan.
  25.  
  26. Features:
  27. - Real-time monitoring: Displays temperature and voltage every 0.25 seconds during the scan.
  28. - Dynamic view: Provides a dynamic view of the CPU's thermal and electrical characteristics.
  29. - Average values: Concludes with the display of average temperature and voltage over the scanning period.
  30. - Insightful assessment: Helps assess how your CircuitPython device responds to temperature and voltage variations.
  31.  
  32.  
  33. Note: This script is specifically designed for Raspberry Pi Pico. Ensure dependencies are met before execution.
  34. """
  35.  
  36. import microcontroller
  37. from time import sleep
  38.  
  39. def temp():
  40.     return microcontroller.cpu.temperature * (9 / 5) + 32
  41.  
  42. def voltage():
  43.     return microcontroller.cpu.voltage
  44.  
  45. art = '''
  46.  *   )                    *   )          )  
  47. ` )  /(  (    )          ` )  /(  (    ( /(  
  48. ( )(_))))\ (    `  )    ( )(_))))\(  )\())
  49. (_(_())/((_) )\ '/(/(   (_(_())/((_)\(_))/  
  50. |_   _(_)) _((_))((_)_\ |_   _(_))((_) |_  
  51.  | | / -_) '  \() '_ \)   | | / -_|_-<  _|  
  52.  |_| \___|_|_|_|| .__/    |_| \___/__/\__|  
  53.                 |_|    + ⚡ VOLTAGE TEST⚡                    
  54. '''
  55.  
  56. print(art)
  57. print("Running 1 Minute Temp & Voltage Scan Now... \n")
  58.  
  59. temperatures = [temp() for _ in range(240)]
  60. voltages = [voltage() for _ in range(240)]
  61. for i, (temperature, voltage) in enumerate(zip(temperatures, voltages)):
  62.     print(f"TMP-{i+1:03d}: {temperature:.2f}° (🔥Fahrenheit🔥), VLT-{i+1:03d}: {voltage:.2f} (⚡Volts⚡)")
  63.     sleep(0.25)
  64.  
  65. print(art)
  66.  
  67. average_temp = sum(temperatures) / len(temperatures)
  68. average_volt = sum(voltages) / len(voltages)
  69. print(f"\nAverage Temperature: {average_temp:.2f}° (🔥Fahrenheit🔥), :: Average Voltage: {average_volt:.2f} (⚡Volts⚡)\n")
  70. print("Done!")
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement