Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By loloToster
#90243 Hi,
I want to use wemos d1 mini to communicate with my python program and im struggling with a problem. I want to have custom "No signal" sign displayed on my ili9341 display, when python is running everything works but as soon as wemos dont receive anything it starts to send some weird stuff:

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffc30 end: 3fffffc0 offset: 01a0
3ffffdd0: 3ffe8675 00000002 3ffefc88 402018be
3ffffde0: 3ffe866d 00000000 3ffefc88 40201a09
3ffffdf0: 00000007 00000000 00000080 40201b91
3ffffe00: 0098009e 00000000 40201e08 fffffffe
3ffffe10: 00000000 0000009d 3ffefc88 40201c61
3ffffe20: 3f000000 00000000 00000001 fffffffe
3ffffe30: 00000000 3ffefca8 3ffefc88 40201ed5
3ffffe40: 3ffefd38 0000007e 3ffefc88 402018a2
3ffffe50: 3ffefc88 3ffefca8 3ffefc88 402020f3
3ffffe60: 00000000 000000af 3ffefc88 40202b90
3ffffe70: 00000000 00000052 3ffefc88 40202e71
3ffffe80: 3ffefc88 00000002 3ffefc88 4020263b
3ffffe90: 00000000 00000052 3ffefc88 4020246d
3ffffea0: 3ffe9d92 00000001 00000000 00000001
3ffffeb0: 00000008 00000001 00000000 000000da
3ffffec0: 000000af 00000003 00000000 3ffefc88
3ffffed0: 00000052 000000da 00000000 40202f3c
3ffffee0: 0000004e 00000002 3ffefc88 000000af
3ffffef0: 00000001 3ffefc88 00000001 3ffe861b
3fffff00: 3ffe8628 3ffefc80 3ffefc80 40204269
3fffff10: 00000072 000000ac 00000003 40206aa2
3fffff20: 00000071 0000000e 000000ac 3ffefdc0
3fffff30: 40206a70 3ffefc80 3ffe8617 40204585
3fffff40: 3ffe84cc 3ffefc80 3ffefc88 4020459c
3fffff50: 3ffe84cc 3ffefc80 3ffefc88 4020338a
3fffff60: 00f42400 00000000 3ffefc88 40203b0d
3fffff70: 00000000 000000e4 3ffefc88 402035c0
3fffff80: 00000000 00000000 00000001 40100154
3fffff90: 3fffdad0 00000000 3ffefd80 3ffefdc0
3fffffa0: 3fffdad0 00000000 3ffefd80 40204d14
3fffffb0: feefeffe feefeffe 3ffe84ec 40100bed
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

And i dont want it because my arduino code thinks that Serial is available and i dont want that

here is my arduino IDE code:

Code: Select all#include <SPI.h>
#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);
  }*/


and my python code:

Code: Select allimport serial
import time
import wmi
import math

global w
w = wmi.WMI(namespace="root\OpenHardwareMonitor")


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)


help would be apricciated :DD