CPU / Memory analog meters

Last Updated or created 2022-05-30

Today i used some analog meters to display cpu load and memory usage.

Using below 12 bit DAC (MCP4725 ) and a Wemos Mini

Usage: (Anything you can come up with, if you got a value, you can display it)

curl http://IP/specificArgs?dac_value=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*1000} END {print usage }' |cut -f1 -d.)

Arduino code

#include <ESP8266WiFi.h>            
#include <ESP8266WebServer.h>
#include <Wire.h>
#include <Adafruit_MCP4725.h>
#define MCP4725 0x62   

unsigned int adc;
byte buffer[3];          
Adafruit_MCP4725 dac;

char dac_value_tmp[6] = "0";
int dac_value = 0;
ESP8266WebServer server(80);   //Web server

void setup() {
WiFi.begin("accesspoint", "accesspointpass"); 
while (WiFi.status() != WL_CONNECTED) { 
Serial.println("Waiting to connect…");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());  //Print IP 
server.on("/genericArgs", handleGenericArgs); 
server.on("/specificArgs", handleSpecificArg);  
server.begin();                        //Start the server
Serial.println("Server listening");   
 dac.begin(0x60); // The I2C Address
void loop() {

    uint32_t dac_value;
    int adcValueRead = 0;
    float voltageRead = 0;

void handleGenericArgs() { //Handler
String message = "Number of args received:";
message += server.args();     //Get number of parameters
message += "\n";                 

for (int i = 0; i < server.args(); i++) {
message += "Arg nº" + (String)i + " –> "; 
message += server.argName(i) + ": ";    
message += server.arg(i) + "\n";         
server.send(200, "text/plain", message);   
void handleSpecificArg() { 
String message = "";
if (server.arg("dac_value")== ""){     //Parameter not found
message = "dac_value Argument not found";
message = "dac_value = ";
message += server.arg("dac_value");     //Gets the value of the query parameter
int dac_value = server.arg("dac_value").toInt();  
      Serial.print("DAC Value: ");

 buffer[0] = 0b01000000;   
  buffer[1] = dac_value >> 4;              //Puts the most significant bit values
  buffer[2] = dac_value << 4;              //Puts the Least significant bit values
  Wire.beginTransmission(MCP4725);         //Joins I2C bus with MCP4725 with 0x61 address
  Wire.write(buffer[0]);            //Sends control byte 
  Wire.write(buffer[1]);            //Sends the MSB to I2C 
  Wire.write(buffer[2]);            //Sends the LSB to I2C
  Wire.endTransmission();           //Ends the transmission
server.send(200, "text/plain", message);          //Returns the HTTP response
Little different image MCP4725 .. Analog meter between resistor and white.

Resistor depends on the range of your analog meters

Spread the love