Created
November 14, 2015 19:03
-
-
Save jossef/bf2bd4c0acf1477384c9 to your computer and use it in GitHub Desktop.
arduino i2c lcd pc stats https://arduino-info.wikispaces.com/LCD-Blue-I2C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include <LiquidCrystal_I2C.h> | |
| LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| lcd.begin(20, 4); | |
| lcd.backlight(); | |
| lcd.setCursor(0, 0); | |
| } | |
| void loop() | |
| { | |
| if (Serial.available()) { | |
| delay(100); | |
| lcd.clear(); | |
| int rowCounter = 0; | |
| int charactersRead = 0; | |
| while (Serial.available() > 0) { | |
| if (charactersRead && charactersRead % 20 == 0) | |
| { | |
| rowCounter = (rowCounter + 1) % 4; | |
| lcd.setCursor(0, rowCounter); | |
| } | |
| charactersRead ++; | |
| lcd.write(Serial.read()); | |
| } | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import serial | |
| import time | |
| from serial.tools import list_ports | |
| import random | |
| import psutil | |
| ports = list(list_ports.comports()) | |
| arduino_port = None | |
| for port_id, port_name, port_address in ports: | |
| if 'arduino' in port_name.lower(): | |
| arduino_port = port_id | |
| if not arduino_port: | |
| raise Exception('arduino not detected') | |
| arduino_port = arduino_port[3:] | |
| arduino_port = int(arduino_port) - 1 | |
| ser = serial.Serial(arduino_port) | |
| counter = 0 | |
| while True: | |
| usage = psutil.cpu_percent(interval=1) | |
| usage = int(usage) | |
| lines = [] | |
| lines.append('CPU: {0}%'.format(usage)) | |
| lines.append('RAM: {0}GB'.format(random.randint(2,4))) | |
| lines.append('STORAGE: {0}GB'.format(random.randint(100,200))) | |
| lines.append('PROCESSES: {0}'.format(random.randint(50,60))) | |
| message = '' | |
| for line in lines: | |
| if len(line) >= 10: | |
| message += line + ' ' * (20-len(line)) | |
| elif len(line) >= 5: | |
| message += line + ' ' * (10-len(line)) | |
| elif len(line) > 0: | |
| message += line + ' ' * (5-len(line)) | |
| ser.write(message) | |
| counter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment