Skip to content

Instantly share code, notes, and snippets.

@Benargee
Last active August 20, 2017 22:39
Show Gist options
  • Save Benargee/8cca454d9a5551d1e4c22cb75f7fe3aa to your computer and use it in GitHub Desktop.
Save Benargee/8cca454d9a5551d1e4c22cb75f7fe3aa to your computer and use it in GitHub Desktop.
Arduino CPU and RAM usage monitor. Credit goes to this post: https://www.reddit.com/r/arduino/comments/6uwkv5/cpu_and_ram_usage_monitor/
//CPU&RAM counter by Sharpy
using System;
using System.Windows.Forms;
using System.IO.Ports;
using System.Diagnostics;
namespace WindowsFormsApplication14
{
public partial class Form1 : Form
{
SerialPort port;
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
public Form1()
{
InitializeComponent();
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
}
private void button1_Click(object sender, EventArgs e)
{
port = new SerialPort(textBox1.Text, 9600);
port.Open();
}
private void button2_Click(object sender, EventArgs e)
{
Timer t = new Timer();
t.Interval = 2000;
t.Start();
t.Tick += (ev, s) => { giveStats(); };
}
public string getCurrentCpuUsage
{
get
{
return (int)cpuCounter.NextValue() + "%";
}
}
public string getAvailableRAM
{
get
{
return ramCounter.NextValue() + "MB";
}
}
public void giveStats()
{
port.WriteLine((checkBox1.Checked ? "CPU:" + getCurrentCpuUsage : string.Empty));
port.WriteLine((checkBox3.Checked ? "RAM:" + getAvailableRAM : string.Empty));
}
private void button3_Click(object sender, EventArgs e)
{
port.Close();
}
}
}
/////////////////////////////////////////
//Universal serial comunicator by Sharp//
/////////////////////////////////////////
#include <gfxfont.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
String val;
int preval;
int x = 0, y = 0;
void cleart(){
display.clearDisplay();
display.display();
}
void setup()
{
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setRotation(2);
}
void loop()
{
if (Serial.available()>0)
{
val = Serial.readString();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(x, y);
display.print(val);
display.display();
}
else{
display.clearDisplay();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment