Components and supplies
USB-A to B Cable
Rotary Potentiometer, 1 Mohm
LCD 16X2
Arduino UNO
Jumper wires (generic)
Project description
Code
yes.py
python
this is the python file i use to get the data and send it to serial. first, you need to install all the library needed - serial - psutil - GPUtil and make sure to use com port your arduino use
1import serial 2import psutil 3import GPUtil 4 5ser=serial.Serial('COM7',9600,timeout=1) 6#change the port accordingly 7 8while True: 9 a=psutil.cpu_percent(interval=1) 10 b=psutil.virtual_memory().percent 11 c=GPUtil.getGPUs() 12 d=c[0].memoryUtil 13 c=c[0].load 14 c*=100 15 d*=100 16 a=round(a) 17 # print(a) 18 b=round(b) 19 # print(b) 20 d=round(d) 21 a=str(a) 22 b=str(b) 23 c=str(c) 24 d=str(d) 25 x=b+'-'+a+'-'+d+'-'+c 26 x=bytes(x,'ascii') 27 ser.write(x)
yes.py
python
this is the python file i use to get the data and send it to serial. first, you need to install all the library needed - serial - psutil - GPUtil and make sure to use com port your arduino use
1import serial 2import psutil 3import GPUtil 4 5ser=serial.Serial('COM7',9600,timeout=1) 6#change 7 the port accordingly 8 9while True: 10 a=psutil.cpu_percent(interval=1) 11 12 b=psutil.virtual_memory().percent 13 c=GPUtil.getGPUs() 14 d=c[0].memoryUtil 15 16 c=c[0].load 17 c*=100 18 d*=100 19 a=round(a) 20 # print(a) 21 22 b=round(b) 23 # print(b) 24 d=round(d) 25 a=str(a) 26 b=str(b) 27 28 c=str(c) 29 d=str(d) 30 x=b+'-'+a+'-'+d+'-'+c 31 x=bytes(x,'ascii') 32 33 ser.write(x)
lcd_work2.ino
arduino
1/* 2 LiquidCrystal Library - Serial Input 3 4 Demonstrates the use a 16x2 LCD display. The LiquidCrystal 5 library works with all LCD displays that are compatible with the 6 Hitachi HD44780 driver. There are many of them out there, and you 7 can usually tell them by the 16-pin interface. 8 9 This sketch displays text sent over the serial port 10 (e.g. from the Serial Monitor) on an attached LCD. 11 12 The circuit: 13 * LCD RS pin to digital pin 12 14 * LCD Enable pin to digital pin 11 15 * LCD D4 pin to digital pin 5 16 * LCD D5 pin to digital pin 4 17 * LCD D6 pin to digital pin 3 18 * LCD D7 pin to digital pin 2 19 * LCD R/W pin to ground 20 * 10K resistor: 21 * ends to +5V and ground 22 * wiper to LCD VO pin (pin 3) 23 24 Library originally added 18 Apr 2008 25 by David A. Mellis 26 library modified 5 Jul 2009 27 by Limor Fried (http://www.ladyada.net) 28 example added 9 Jul 2009 29 by Tom Igoe 30 modified 22 Nov 2010 31 by Tom Igoe 32 modified 7 Nov 2016 33 by Arturo Guadalupi 34 35 This example code is in the public domain. 36 37 http://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay 38 39*/ 40 41// include the library code: 42#include <LiquidCrystal.h> 43 44// initialize the library by associating any needed LCD interface pin 45// with the arduino pin number it is connected to 46const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 47 48char sheh; 49LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 50char heh=0; 51char input[99]={}; 52int count=0; 53int realsize=0; 54//char dummy[99]={}; 55String dummy; 56int cnt=0; 57int cnt2=0; 58int parsed[4]={}; 59float parsedbar[4]={}; 60 61byte blocks0[8] = { 62 0b10000, 63 0b10000, 64 0b10000, 65 0b10000, 66 0b10000, 67 0b10000, 68 0b10000, 69 0b10000 70 }; 71byte blocks1[8] = { 72 0b11000, 73 0b11000, 74 0b11000, 75 0b11000, 76 0b11000, 77 0b11000, 78 0b11000, 79 0b11000 80 }; 81byte blocks2[8] = { 82 0b11100, 83 0b11100, 84 0b11100, 85 0b11100, 86 0b11100, 87 0b11100, 88 0b11100, 89 0b11100 90 }; 91byte blocks3[8] = { 92 0b11110, 93 0b11110, 94 0b11110, 95 0b11110, 96 0b11110, 97 0b11110, 98 0b11110, 99 0b11110 100 }; 101byte blocks4[8] = { 102 0b11111, 103 0b11111, 104 0b11111, 105 0b11111, 106 0b11111, 107 0b11111, 108 0b11111, 109 0b11111 110 }; 111byte cpu[8] = { 112 0b00000, 113 0b11111, 114 0b10001, 115 0b10101, 116 0b10001, 117 0b11111, 118 0b00000, 119 0b00000 120 }; 121byte ram[8] = { 122 0b10101, 123 0b10101, 124 0b10101, 125 0b10101, 126 0b10101, 127 0b10101, 128 0b10101, 129 0b10101 130 }; 131byte gpu[8] = { 132 0b00000, 133 0b00000, 134 0b11111, 135 0b11111, 136 0b10000, 137 0b00000, 138 0b00000, 139 0b00000 140 }; 141byte internet[8] = { 142 0b00000, 143 0b00100, 144 0b01010, 145 0b10001, 146 0b00100, 147 0b01010, 148 0b10001, 149 0b00000 150 }; 151void setup() { 152 153 // set up the LCD's number of columns and rows: 154 lcd.begin(16, 2); 155 lcd.createChar(0,blocks0); 156 lcd.createChar(1,blocks1); 157 lcd.createChar(2,blocks2); 158 lcd.createChar(3,blocks3); 159 lcd.createChar(4,blocks4); 160 lcd.createChar(5,cpu); 161 lcd.createChar(6,ram); 162 lcd.createChar(7,gpu); 163 // initialize the serial communications: 164 lcd.setCursor(0,0); 165 lcd.write(byte(6)); 166 lcd.setCursor(8,0); 167 lcd.write(byte(5)); 168 lcd.setCursor(0,1); 169 lcd.print("V"); 170 lcd.setCursor(8,1); 171 lcd.write(byte(7)); 172// lcd.createChar(4,blocks4); 173 Serial.begin(9600); 174} 175 176void loop() { 177 // when characters arrive over the serial port... 178 cnt=0; 179 cnt2=0; 180 memset(input, 0, sizeof(input)); 181 memset(parsed, 0, sizeof(parsed)); 182 dummy=""; 183// memset(dummy, 0, sizeof(dummy)); 184 count=0; 185 realsize=0; 186 187 if (Serial.available()) { 188 // wait a bit for the entire message to arrive 189 delay(100); 190 // clear the screen 191// lcd.clear(); 192 // read all the available characters 193 while (Serial.available() > 0) { 194 195 // display each character to the LCD 196 heh=Serial.read(); 197 if(heh!='\n'){ 198 input[count]=heh; 199// Serial.print("count = "); 200// Serial.print(count); 201// Serial.print(heh); 202 count++; 203// lcd.write(heh); 204 Serial.print(heh); 205 } 206 207 } 208 for(int i=0;i<sizeof(input);i++){ 209 if(input[i]){ 210 realsize++; 211// Serial.print(input[i]); 212 } 213 else{ 214 break; 215 } 216 217 } 218 for(int i=0;i<=realsize;i++){ 219 if(input[i]=='-'||i==realsize){ 220 Serial.println("space"); 221 cnt=0; 222 parsed[cnt2]=dummy.toInt(); 223 Serial.println(parsed[cnt2]); 224 dummy=""; 225// memset(dummy, 0, sizeof(dummy)); 226 cnt2++; 227 } 228 else{ 229 Serial.println("data"); 230 dummy+=input[i]; 231 Serial.println(dummy); 232 } 233 } 234 Serial.print("realsize= "); 235 Serial.println(realsize); 236 Serial.println(sizeof(input)); 237 Serial.println("parsed results:"); 238 for(int i=0;i<4;i++){ 239 Serial.println(parsed[i]); 240 } 241 cnt=0; 242 243 // loop over the columns:\\ 244 cnt=0; 245 for (int thisRow = 0; thisRow < 2; thisRow++) { 246 // loop over the rows: 247 for (int thisCol = 1; thisCol < 16; thisCol+=8) { 248 // set the cursor position: 249 lcd.setCursor(thisCol, thisRow); 250 // print the letter: 251 if(parsed[cnt]>99){ 252 lcd.print("XX"); 253 } 254 else{ 255 if(parsed[cnt]<10){ 256 lcd.print(" "); 257 } 258 lcd.print(parsed[cnt]); 259 } 260 cnt++; 261 262 } 263 } 264 cnt=0; 265 266 for(int i=0;i<2;i++){ 267 for(int j=3;j<16;j+=8){ 268 parsedbar[cnt]=parsed[cnt]*25; 269 parsedbar[cnt]/=100; 270 Serial.print("before round"); 271 Serial.println(parsedbar[cnt]); 272 parsedbar[cnt]=ceil(parsedbar[cnt]); 273 Serial.print("after round"); 274 Serial.println(parsedbar[cnt]); 275 lcd.setCursor(j, i); 276 cnt2=0; 277 while(true){ 278 if(parsedbar[cnt]>5){ 279 lcd.write(byte(4)); 280 parsedbar[cnt]-=5; 281 cnt2++; 282 } 283 else if(parsedbar[cnt]>0){ 284 lcd.write(byte(parsedbar[cnt]-1)); 285 cnt2++; 286 break; 287 } 288 else{ 289 break; 290 } 291 } 292 Serial.print(cnt2); 293 Serial.print("asdf"); 294 295 cnt2=5-cnt2; 296 Serial.print(cnt2); 297 for(int k=0;k<cnt2;k++){ 298 lcd.print(" "); 299 } 300// lcd.print(parsedbar[cnt]); 301 cnt++; 302 } 303 } 304 305 memset(parsed, 0, sizeof(parsed)); 306 } 307} 308
Downloadable files
image_2022-07-16_142937414_XTeOYaJOsg.png
image_2022-07-16_142937414_XTeOYaJOsg.png
image_2022-07-16_142937414_XTeOYaJOsg.png
image_2022-07-16_142937414_XTeOYaJOsg.png
Comments
Only logged in users can leave comments
agus_prayogo
0 Followers
•0 Projects
0