我想为我的电脑定制硬件监视器,但我遇到了一个问题。当我上传我的代码时,它不能正常工作,它停在一个随机的地方,wemos 上的 LED 开始闪烁,它通过串行传输一些东西:
----------------在这里剪切异常解码器--------------
软 WDT 复位
>>> 堆栈 >>>
ctx:cont
sp:3fffffce0 结束:3fffffc0 偏移量:01a0
3ffffe80:00000000 00000000 3ffefc88 40202d28
3ffffe90:3ffefd38 3ffffeb0 00002fffedb 4
4 :3FFEFC88 000000 ef 3FFEFC88 40201CA3
3FFFFEB0:40000000 3FFEFC80
3FFFFFFFFFEEEE 4020269C
3FFFFEC0:0000000032 3FFEFCA8 3FFEFCA8 3FFEFC888840201ED5 3FFFFFFFFFFFFFFFFFED0:000000000000000000000000000000000000000000000000000000000000000000000000000000来000000000000000000000000000000000000来万000000来00yysisisisisisisyyyyyyyyyyyyyyyyyty期取
3ffffee0: 00000000 3ffefca8 3ffefc88 402020f3
3ffffef0: 00000000 00000000 3ffefc88 40202b90
3fffff00: 3ffefc88 00000000 00000103 40202e71
3fffff10: 00f42400 7fced068 3ffefc88 4020266c
3fffff20: 3ffe84cc 00000000 3ffefc88 40201078
3fffff30: 000000f0 00000140 00000001 40202075
3fffff40: 00000000 014000f0 00000001 3ffefdc0
3fffff50: 3ffe84cc 00000000 3ffefc88 402010cf
3fffff60: 00f42400 7fced8d7 3ffefc88 40203b02
3fffff70: 00000000 00000033 80fefc88 402035c0
3fffff80: 00000000 00000000 00000001 40100154
3fffff90: 3fffdad0 00000000 3ffefd80 3ffefdc0
3fffffa0: 3fffdad0 00000000 3ffefd80 40204d14
3fffffb0: feefeffe feefeffe 3ffe84ec 40100bed
<<<堆栈<<<
-------------- 异常解码器在此处剪切 --------------
ets 2013 年 1 月 8 日,第一个原因: 2,启动模式:(3,6)
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
但是当我启动连接到 wemos 的 python 程序时,一切正常。我不想使用 wemos wifi 功能,我使用它是因为它比 examle arduino nano 更快,并且它适用于 3v3。
这是我的 arduino IDE 代码:
代码:
全选#include
#include "Ucglib.h"
#define tiME_TO_DISCONNECT 4000
#define DELAY 100
#define MINI_FONT ucg_font_7x13r //ucg_font_7x13r ucg_font_helvB12r
#define DEFAULT_FONT ucg_font_helvB24r
//Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 13, /*data=*/ 11, /*cd=*/ 9 , /*cs=*/ 5, /*reset=*/ 8);
Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 5 , /*cs=*/ 15, /*reset=*/ -1);
//Ucglib_ILI9341_18x240x320_HWSPI ucg(/*cd=*/ 9 , /*cs=*/ 5, /*reset=*/ 8);
byte CPUtemp = 0;
byte GPUtemp = 0;
float RAMload = 0;
//byte RAMloadI;
byte cpuRGB[] = {0, 255, 0};
byte gpuRGB[] = {0, 250, 255};
byte ramRGB[] = {40, 180, 255};
byte preGPUtemp;
byte preCPUtemp;
float preRAMload;
int countDis;
boolean startUpWhenCon = false;
boolean startUpWhenDis = true;
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay(1000);
ucg.begin(UCG_FONT_MODE_SOLID);
ucg.setRotate180();
ucg.setColor(255, 255, 255);
//ucg.clearScreen(); //this should be uncommented but wemos get stuck on it and wont go further
ucg.setFont(MINI_FONT);
drawMiniCPUicon();
drawGPUicon();
drawRAMicon();
ucg.setFont(DEFAULT_FONT);
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
String s = Serial.readString();
preCPUtemp = CPUtemp;
preGPUtemp = GPUtemp;
preRAMload = RAMload;
if (startUpWhenCon) {
ucg.setColor(0, 0, 0);
ucg.drawBox(60, 65, 189, 155);
startUpWhenCon = false;
startUpWhenDis = true;
ucg.setFont(MINI_FONT);
drawMiniCPUicon();
drawGPUicon();
drawRAMicon();
ucg.setFont(DEFAULT_FONT);
}
countDis = 0;
if (s.length() > 4) {
CPUtemp = s.toInt();
} else if (s.length() > 2) {
RAMload = s.toFloat();
} else {
GPUtemp = s.toInt();
}
byte mappedCPUtemp = map(CPUtemp, 10, 100, 239, 0);
byte mappedGPUtemp = map(GPUtemp, 10, 100, 239, 0);
byte mappedRAMload = map(RAMload * 10, 0, 170, 239, 0);
//////////CPU/////////////////////////////////////////////////////////////////////////
if (CPUtemp >= 10 && CPUtemp < 100 && preCPUtemp != CPUtemp)
updateInfo(0, mappedCPUtemp, cpuRGB, CPUtemp);
//////////GPU/////////////////////////////////////////////////////////////////////////
if (GPUtemp >= 10 && GPUtemp < 100 && preGPUtemp != GPUtemp)
updateInfo(80, mappedGPUtemp, gpuRGB, GPUtemp);
//////////RAM/////////////////////////////////////////////////////////////////////////
if (RAMload > 0 && preRAMload != RAMload) {
columns(160, mappedRAMload, ramRGB);
ucg.setColor(255, 255, 255);
if (RAMload < 10) {
ucg.setPrintPos(165, mappedRAMload - 6);
ucg.print(RAMload, 1);
printGB(mappedRAMload, 217);
} else {
ucg.setPrintPos(168, mappedRAMload - 6);
ucg.print(RAMload, 0);
printGB(mappedRAMload, 211);
}
}
} else if (countDis >= TIME_TO_DISCONNECT) {
if (startUpWhenDis) {
CPUtemp = 0;
GPUtemp = 0;
RAMload = 0;
ucg.clearScreen();
ucg.setFont(MINI_FONT);
drawSleepingToster();
ucg.setFont(DEFAULT_FONT);
startUpWhenDis = false;
startUpWhenCon = true;
}
sleepingAnimation();
} else {
countDis++;
delay(1);
}
}
//funkcje/////////////////////////////
void updateInfo(byte x, byte mappedValue, byte rgb[], byte temp) {
columns(x, mappedValue, rgb);
ucg.setColor(255, 255, 255);
ucg.setPrintPos(x + 5, mappedValue - 6);
ucg.print(temp);
ucg.print(" C");
ucg.drawDisc(x + 45, mappedValue - 26, 4, UCG_DRAW_ALL);
ucg.setColor(0, 0, 0);
ucg.drawDisc(x + 45, mappedValue - 26, 1, UCG_DRAW_ALL);
}
void columns(byte x, byte mappedValue, byte rgb[]) {
ucg.setColor(0, 0, 0, 0);
ucg.drawBox(x, 0, 80, mappedValue + 1);
ucg.setColor(0, rgb[0], rgb[1], rgb[2]);
for (byte i = 239; i > mappedValue; i--) {
ucg.drawHLine(x, i, 80);
}
}
void sleepingAnimation() {
//poczatkowa/nizsza pozycja
ucg.drawBox(137, 98, 7, 7);
ucg.setColor(0, 0, 0);
ucg.drawBox(137, 94, 7, 4);
ucg.setColor(255, 255, 255);
delay(DELAY);
ucg.setPrintPos(147, 100);
ucg.print("z");
delay(DELAY);
ucg.setPrintPos(167, 95);
ucg.print("Z");
ucg.setColor(0, 0, 0);
ucg.drawBox(167, 66, 20, 4);
delay(DELAY);
//wyzsza pozycja
ucg.setColor(255, 255, 255);
ucg.drawBox(137, 94, 7, 7);
ucg.setColor(0, 0, 0);
ucg.drawBox(137, 101, 7, 4);
delay(DELAY);
ucg.setColor(255, 255, 255);
ucg.setPrintPos(147, 96);
ucg.print("z");
delay(DELAY);
ucg.setPrintPos(167, 91);
ucg.print("Z");
delay(DELAY);
}
void drawSleepingToster() {
ucg.setColor(255, 255, 255);
ucg.drawRBox(61, 115, 118, 81, 19);
ucg.drawBox(61, 134, 30, 70);
ucg.drawBox(149, 134, 30, 70);
ucg.drawBox(179, 142, 8, 7);
ucg.setColor(0, 0, 0);
ucg.drawBox(84, 119, 73, 5);
ucg.drawRBox(86, 151, 22, 8, 1);
ucg.drawRBox(132, 151, 22, 8, 1);
ucg.drawRBox(113, 171, 14, 6, 1);
ucg.setColor(255, 255, 255);
ucg.setPrintPos(61, 218);
ucg.print("// No Signal...//");
}
void printGB(byte mappedValue, byte x) {
//G
ucg.drawDisc(x, mappedValue - 13, 6, UCG_DRAW_ALL);
ucg.setColor(0, 0, 0);
ucg.drawDisc(x, mappedValue - 13, 3, UCG_DRAW_ALL);
ucg.drawTriangle(/*right*/224, mappedValue - 13 ,/*top*/ 224, mappedValue - 25,/*mid*/ 216, mappedValue - 13);
ucg.setColor(255, 255, 255);
ucg.drawBox(x, mappedValue - 13, 4, 2);
//B
ucg.drawRBox(x + 9, mappedValue - 19, 9, 8, 3);
ucg.drawRBox(x + 9, mappedValue - 14, 9, 8, 3);
ucg.setColor(0, 0, 0);
ucg.drawRBox(x + 10, mappedValue - 17, 5, 4, 1);
ucg.drawRBox(x + 10, mappedValue - 12, 5, 4, 1);
ucg.setColor(255, 255, 255);
ucg.drawBox(x + 9, mappedValue - 19, 3, 13);
}
void drawRAMicon() {
ucg.setColor(ramRGB[0], ramRGB[1], ramRGB[2]);
ucg.drawBox(160, 240, 80, 80);
ucg.setColor(255, 255, 255);
ucg.drawBox(169, 262, 62, 27);
ucg.setColor(ramRGB[0], ramRGB[1], ramRGB[2]);
ucg.drawRBox(160, 266, 12, 5, 1);
ucg.drawRBox(228, 266, 12, 5, 1);
ucg.drawBox(175, 267, 9, 14);
ucg.drawBox(188, 267, 9, 14);
ucg.drawBox(201, 267, 7, 14);
ucg.drawBox(211, 267, 4, 6);
ucg.drawBox(211, 275, 4, 6);
ucg.drawBox(218, 267, 7, 14);
ucg.setColor(255, 255, 255);
for (byte i = 172; i < 200; i += 4) {
ucg.drawFrame(i, 288, 4, 5);
}
for (byte i = 204; i < 227; i += 4) {
ucg.drawFrame(i, 288, 4, 5);
}
ucg.setPrintPos(160, 236);
ucg.print("Init...");
}
void drawGPUicon() {
ucg.setColor(gpuRGB[0], gpuRGB[1], gpuRGB[2]);
ucg.drawBox(80, 240, 80, 80);
ucg.setColor(255, 255, 255);
ucg.drawRBox(89, 257, 61, 40, 8);
ucg.drawBox(89, 257, 20, 40);
ucg.drawBox(85, 254, 7, 3);
ucg.drawBox(89, 257, 3, 46);
for (byte i = 106; i < 137; i += 4) {
ucg.drawFrame(i, 296, 4, 5);
}
ucg.setColor(gpuRGB[0], gpuRGB[1], gpuRGB[2]);
ucg.drawLine(123, 300, 124, 300);
ucg.drawDisc(106, 276, 12, UCG_DRAW_ALL);
ucg.drawRBox(122, 268, 19, 6, 1);
ucg.drawRBox(122, 281, 19, 6, 1);
ucg.setColor(255, 255, 255);
ucg.drawRBox(103, 274, 7, 7, 1);
ucg.setPrintPos(80, 236);
ucg.print("Init...");
}
void drawMiniCPUicon() {
ucg.setColor(cpuRGB[0], cpuRGB[1], cpuRGB[2]);
ucg.drawBox(0, 240, 80, 80);
ucg.setColor(255, 255, 255);
for (byte i = 12; i < 40; i += 12) {
ucg.drawRBox(13, i + 253, 54, 6, 2);
ucg.drawRBox(i + 13, 253, 6, 54, 2);
}
ucg.drawRBox(19, 259, 42, 42, 2);
ucg.setColor(0, cpuRGB[0], cpuRGB[1], cpuRGB[2]);
ucg.drawRBox(25, 265, 30, 30, 2);
ucg.setColor(255, 255, 255);
ucg.drawRBox(31, 271, 18, 18, 2);
ucg.setPrintPos(0, 236);
ucg.print("Init...");
}
/*void drawBigCPUicon() {
ucg.setColor(0, cpuRGB[0], cpuRGB[1], cpuRGB[2]);
ucg.drawBox(0, 239, 79, 80);
ucg.setColor(0, 255, 255, 255);
for (int i = 12; i < 50; i += 12) {
ucg.drawRBox(7, i + 247, 66, 6, 2);
ucg.drawRBox(i + 7, 247, 6, 66, 2);
}
ucg.drawRBox(13, 253, 54, 54, 2);
ucg.setColor(0, cpuRGB[0], cpuRGB[1], cpuRGB[2]);
ucg.drawRBox(19, 259, 42, 42, 2);
ucg.setColor(0, 255, 255, 255);
ucg.drawRBox(25, 265, 30, 30, 2);
}*/
这是我的 python 代码:
代码:全选import serial
import time
import wmi
import math
global w
w = wmi.WMI(namespace="rootOpenHardwareMonitor")
global cpu
global gpu
global ram
"""
def getRamSize():
used = 0
free = 0
hw_infos = w.Sensor()
for sensor in hw_infos:
if sensor.SensorType==u'Data':
if sensor.Name == u'Used Memory':
used = int(math.ceil(sensor.Value))
elif sensor.Name == u'Available Memory':
free = int(math.ceil(sensor.Value))
return used + free
"""
def updateHWData():
global w
global cpu
global gpu
global ram
hw_infos = w.Sensor()
cpu = []
gpu = []
ram = []
for sensor in hw_infos:
#print (sensor.SensorType)
#print(sensor.Name)
#print(sensor.Value)
if sensor.SensorType==u'Temperature':
if sensor.Name == u'CPU Package':
cpu.insert(0, "000%d" % sensor.Value)
elif sensor.Name == u'GPU Core':
gpu.insert(0, "%d" % sensor.Value)
# if sensor.SensorType==u'Clock':
# if sensor.Name == u'CPU Core #1':
# cpu.insert(1, "CPU clk: %dMHz" % sensor.Value)
# elif sensor.Name == u'GPU Core':
# gpu.insert(1, "GPU clk: %dMHz " % sensor.Value)
if sensor.SensorType==u'Data':
if sensor.Name == u'Used Memory':
ram.insert(0, "%.1f" % sensor.Value)
def serial_ports():
ports = ['COM%s' % (i + 1) for i in range(256)] #['COM%s' % (i + 1) for i in range(256)] / ['COM%s' % (i + 1) for i in range(0,8,7)] dla COM8
result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result
arduino = serial.Serial(serial_ports()[1], 115200, timeout=.7)
#arduino = serial.Serial('COM8', 9600, timeout=.7)
time.sleep(2)
arduino.write("start".encode())
time.sleep(0.5)
while len(w.Sensor()) < 1:
time.sleep(1)
cpu = []
gpu = []
#ram = ["RAM total: {:2d}GB ".format(getRamSize())]
while True:
#startTime = int(round(time.time() * 1000))
for i in range(4):
updateHWData()
arduino.write(cpu[0].encode())
time.sleep(3)
arduino.write(gpu[0].encode())
time.sleep(3)
arduino.write(ram[0].encode())
time.sleep(3)
一切都适用于 arduino nano,我不明白为什么不能使用 wemos。请帮我。