fin código microbit, inicio documento
This commit is contained in:
11
README.md
11
README.md
@@ -1,3 +1,12 @@
|
||||
# microbit-temps
|
||||
|
||||
"Robot" que enseña información del sistema bajo petición.
|
||||
"Robot" que enseña información del sistema bajo petición.
|
||||
|
||||
## Inspiración
|
||||
|
||||
|
||||
|
||||
## Requisitos
|
||||
|
||||
- micro:bit
|
||||
- ordenador (windows, mac, linux)
|
||||
21
microbit.py
Normal file
21
microbit.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from microbit import *
|
||||
|
||||
uart.init(115200)
|
||||
display.show(Image.SILLY)
|
||||
|
||||
while True:
|
||||
if uart.any():
|
||||
received_bytes = uart.read()
|
||||
if received_bytes:
|
||||
received_list = received_bytes.decode('utf-8').split(',')
|
||||
|
||||
# cpu
|
||||
if button_a.was_pressed():
|
||||
display.scroll(received_list[0])
|
||||
# ram
|
||||
if button_b.was_pressed():
|
||||
display.scroll(received_list[1])
|
||||
|
||||
display.show(Image.SILLY)
|
||||
|
||||
sleep(100)
|
||||
16
pc.py
16
pc.py
@@ -1,23 +1,23 @@
|
||||
from pc_utils import get_cpu_usage, get_memory_usage, get_cpu_temp
|
||||
#import serial
|
||||
from pc_utils import get_cpu_usage, get_memory_usage
|
||||
import serial
|
||||
from time import sleep
|
||||
|
||||
# connect to microbit
|
||||
#ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
||||
#ser.flush()
|
||||
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
||||
ser.flush()
|
||||
print("Connected to microbit.")
|
||||
|
||||
while True:
|
||||
sleep(1)
|
||||
cpu_usage = get_cpu_usage()
|
||||
memory_usage = get_memory_usage()
|
||||
cpu_temp = get_cpu_temp()
|
||||
print(f"CPU Usage: {cpu_usage}%")
|
||||
print(f"Memory Usage: {memory_usage}%")
|
||||
print(f"CPU Temperature: {cpu_temp}°C")
|
||||
print('--------')
|
||||
|
||||
data = [cpu_usage, memory_usage, cpu_temp]
|
||||
data = [cpu_usage, memory_usage]
|
||||
data_str = ','.join(map(str, data))
|
||||
#send_serial_data(data_str, ser)
|
||||
ser.write(data_str.encode('utf-8'))
|
||||
ser.write(b'\n')
|
||||
print(data_str.encode('utf-8'))
|
||||
|
||||
|
||||
@@ -5,14 +5,6 @@ def get_cpu_usage():
|
||||
def get_memory_usage():
|
||||
memory = psutil.virtual_memory()
|
||||
return round(memory.percent)
|
||||
def get_cpu_temp():
|
||||
try:
|
||||
# linux / mac
|
||||
temp = psutil.sensors_temperatures()['coretemp'][0].current
|
||||
except KeyError:
|
||||
# windows
|
||||
temp = psutil.sensors_temperatures()['cpu_thermal'][0].current
|
||||
return round(temp)
|
||||
|
||||
def send_serial_data(data, ser):
|
||||
if ser.is_open:
|
||||
|
||||
Reference in New Issue
Block a user