-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicofetch.py
More file actions
64 lines (54 loc) · 2.28 KB
/
picofetch.py
File metadata and controls
64 lines (54 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Imports
import machine
from machine import Pin
import utime
import sys
import os
import micropython
import gc
import time
# Switch the pico on-board led on.
led = Pin("LED", Pin.OUT)
led.value(1)
# Print ASCII Art
print('\033[1m' + r"""
PPPP III CCC OOO FFFFF EEEEE TTTTT CCC H H
P P I C C O O F E T C C H H
PPPP I C O O FFFF EEEE T C HHHHH
P I C C O O F E T C C H H
P III CCC OOO F EEEEE T CCC H H
---------------------------------------------------""" + '\033[0m')
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)
reading = sensor_temp.read_u16() * conversion_factor
# The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel
# Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree.
temperature = 27 - (reading - 0.706)/0.001721
def print_color_blocks():
BLOCK = ' ' # Or '\u2588' * 3 for solid blocks
# Standard colors
print(''.join(f"\033[4{i}m{BLOCK}\033[0m" for i in range(8)))
cause = machine.reset_cause()
print('\033[1m' + "Board Variant:" + '\033[0m', os.uname().machine)
print('\033[1m' + "Serial Number:" + '\033[0m', machine.unique_id().hex())
print('\033[1m' + "Platform:" + '\033[0m', sys.platform)
print('\033[1m' + "Firmware Version:" + '\033[0m', sys.version)
print(f"\033[1mTemperature:\033[0m {temperature:.2f} °C")
print(f"\033[1mUptime:\033[0m {time.ticks_ms() / 1000:.2f}s")
print('\033[1m' + "CPU Frequency:" + '\033[0m', machine.freq() // 1000000, "MHz")
print(f"\033[1mAllocated RAM:\033[0m {gc.mem_alloc() / 1024:.2f} KB")
print(f"\033[1mFree RAM:\033[0m {gc.mem_free() / 1024:.2f} KB")
if cause == machine.PWRON_RESET:
print('\033[1m' + "Reset Cause:" + '\033[0m', "PWRON_RESET")
elif cause == machine.WDT_RESET:
print('\033[1m' + "Reset Cause:" + '\033[0m', "WDT_RESET")
elif cause == machine.DEEPSLEEP_RESET:
print('\033[1m' + "Reset Cause:" + '\033[0m', "DEEPSLEEP_RESET")
elif cause == machine.SOFT_RESET:
print('\033[1m' + "Reset Cause:" + '\033[0m', "SOFT_RESET")
elif cause == machine.HARD_RESET:
print('\033[1m' + "Reset Cause:" + '\033[0m', "HARD_RESET")
else:
print('\033[1m' + "Reset Cause:" + '\033[0m', "N/A")
print()
print_color_blocks()