Advertisement
Guest User

Untitled

a guest
Feb 11th, 2021
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | None | 0 0
  1. //Credits: Simion Logos
  2.  
  3. /*ST7735 TFT SPI display pins for Arduino Uno/Nano:
  4. * LED = 3.3V
  5. * SCK = 13
  6. * SDA = 11
  7. * A0 = 8
  8. * RESET = 9
  9. * CS = 10
  10. * GND = GND
  11. * VCC = 5V*/
  12.  
  13. /* SPI pin names can be confusing. These are the alternative names for the SPI pins:
  14. MOSI = DIN = R/W = SDO = DI = SI = MTSR = SDA = D1 = SDI
  15. CS = CE = RS = SS
  16. DC = A0 = DO = DOUT = SO = MRST
  17. RESET = RST
  18. SCLK = CLK = E = SCK = SCL = D0*/
  19.  
  20.  
  21. #include <Adafruit_GFX.h>
  22. #include <Adafruit_ST7735.h>
  23.  
  24. #define TFT_CS 10
  25. #define TFT_RST 8
  26. #define TFT_DC 9
  27.  
  28. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
  29.  
  30. #include <Fonts/FreeSerif18pt7b.h>
  31. #include <Fonts/FreeSerifBoldItalic12pt7b.h>
  32.  
  33.  
  34. //Temperature sensor data
  35.  
  36. #include "DHT.h" // Library for DHT sensors
  37.  
  38. #define dhtPin 2 // data pin
  39.  
  40. /*
  41. * Uncomment the correct DHT chip
  42. */
  43. #define dhtType DHT11 // DHT 11
  44. //#define dhtType DHT22 // DHT 22 (AM2302), AM2321
  45. //#define dhtType DHT21 // DHT 21 (AM2301)
  46.  
  47. DHT dht(dhtPin, dhtType); // Initialise the DHT library
  48.  
  49. float humidityVal; // humidity
  50. int tempValC; // temperature in degrees Celcius
  51. float tempValF; // temperature in degrees Fahrenheit
  52. float heatIndexC; // windchill in degrees Celcius
  53. float heatIndexF; // windchill in degrees Fahrenheit
  54.  
  55. // Comment this whole code to use without temperature sensor
  56.  
  57.  
  58. String inputString = "";
  59. String cpuLoadString;
  60. String cpuTempString;
  61. String cpuClockString;
  62. String ramString;
  63. String gpuTempString;
  64. String gpuLoadString;
  65. String ramLoadString;
  66. String ramPerString;
  67.  
  68. char buf[30];
  69. int cpuLoad;
  70. int cpuClock;
  71. int cpuTemp;
  72. int usedRam;
  73. int gpuTemp;
  74. int gpuLoad;
  75. int ramLoad;
  76. int ramPer;
  77. int totalRam = 16;
  78. int inp=0;
  79.  
  80. //String gpuLoadString;
  81. //String gpuTempString;
  82. //int gpuLoad;
  83. //int gpuTemp;
  84.  
  85. #define NUM_VAL (12+1)
  86. int tempTab[NUM_VAL];
  87. int loadTab[NUM_VAL];
  88. int clockTab[NUM_VAL];
  89. int ramTab[NUM_VAL];
  90. int i,v,ght=60-8-2;
  91.  
  92. void setup() {
  93. // put your setup code here, to run once:
  94. tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab
  95.  
  96. tft.fillScreen(ST7735_BLACK); //Fill screen with Black
  97.  
  98. tft.setRotation(0); //Set rotation to display. Can be from 0 to 3
  99.  
  100. tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
  101.  
  102.  
  103. Serial.begin(9600);
  104. dht.begin(); // start with reading the DHT sensor //Comment this whole code to use without temperature sensor
  105.  
  106.  
  107.  
  108.  
  109. tft.setFont(); //set custom font
  110. tft.setCursor(20,55); //set position (x,y)
  111. tft.setTextColor(ST7735_YELLOW); //set color of text
  112. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  113. tft.println("Please turn on"); //print the tex
  114.  
  115. tft.setFont(); //set custom font
  116. tft.setCursor(25,65); //set position (x,y)
  117. tft.setTextColor(ST7735_YELLOW); //set color of text
  118. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  119. tft.println("the program"); //print the tex
  120.  
  121. delay(5000);
  122.  
  123.  
  124. tft.fillScreen(ST7735_BLACK);
  125.  
  126. tft.setFont(); //set custom font
  127. tft.setCursor(20,55); //set position (x,y)
  128. tft.setTextColor(ST7735_YELLOW); //set color of text
  129. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  130. tft.println("Connecting..."); //print the text
  131. delay(10000);
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. void loop() {
  150. // put your main code here, to run repeatedly:
  151.  
  152. int tMC = digitalRead(2);
  153. int i = map(tMC, 0, 100,6, 116);
  154.  
  155.  
  156. while (Serial.available()) {
  157. char ch = (char)Serial.read();
  158. inputString += ch;
  159.  
  160. if(ch == '|') { // full info chunk received
  161. int st,en;
  162. st = inputString.indexOf("CHC"); // CPU clock: "CHC1768"
  163. if(st>=0) {
  164. en = inputString.indexOf("|", st);
  165. cpuClockString = inputString.substring(st+3, en);
  166. cpuClock = cpuClockString.toInt();
  167. inp=3;
  168. } else {
  169.  
  170. st = inputString.indexOf("R"); // used RAM: "R6.9"
  171. if(st>=0) {
  172. en = inputString.indexOf("|", st);
  173. ramString = inputString.substring(st+1 , en-1);
  174. st = ramString.indexOf(",");
  175. if(st>=0) ramString.setCharAt(st,'.');
  176. usedRam = ramString.toFloat()*1024;
  177. inp=2;
  178. }
  179.  
  180. int cpuTempStart = inputString.indexOf("C"); // CPU temperature: "C52"
  181. int cpuLoadStart = inputString.indexOf("c"); // CPU load: "c18%"
  182. if(cpuLoadStart>=0 && cpuTempStart>=0) {
  183. en = inputString.indexOf("|");
  184. cpuTempString = inputString.substring(cpuTempStart+1, cpuLoadStart);
  185. cpuLoadString = inputString.substring(cpuLoadStart+1, en-1);
  186. cpuTemp = cpuTempString.toInt();
  187. cpuLoad = cpuLoadString.toInt();
  188. inp=1;
  189.  
  190.  
  191. }
  192.  
  193. int gt,gr;
  194. int gpuTempStart = inputString.indexOf("G");
  195. int gpuLoadStart = inputString.indexOf("c");
  196. if (gpuLoadStart>=0 && gpuTempStart>=0){
  197. gt = inputString.indexOf("|");
  198. gpuTempString = inputString.substring(gpuTempStart+1, gpuLoadStart);
  199. gpuLoadString = inputString.substring(cpuLoadStart+1, en-1);
  200. gpuTemp = gpuTempString.toInt();
  201. gpuLoad = gpuLoadString.toInt();
  202. inp=1;
  203.  
  204.  
  205. }
  206.  
  207. int gy, we;
  208. int ramLoadStart = inputString.indexOf("R");
  209. int ramLoadStop = inputString.indexOf("GB");
  210. if (ramLoadStart>=0 && ramLoadStop>=0){
  211. gy = inputString.indexOf("|");
  212. ramLoadString = inputString.substring(ramLoadStart + 1, ramLoadStop );
  213. ramLoad = ramLoadString.toFloat();
  214. }
  215.  
  216.  
  217. int re;
  218. int ramPStart = inputString.indexOf("L");
  219. int ramPStop = inputString.indexOf("|G");
  220.  
  221. if (ramPStart>=0 && ramPStop>=0 ){
  222. re = inputString.indexOf("|");
  223. ramPerString = inputString.substring(ramPStart + 1, ramPStop - 2);
  224. ramPer = ramPerString.toInt();
  225. }
  226. inputString = "";
  227. return 1;
  228. }
  229. }
  230. }
  231.  
  232.  
  233. int percentageRam = (ramLoad*100)/totalRam;
  234.  
  235. tft.fillScreen(ST7735_BLACK);
  236.  
  237. tft.setFont(&FreeSerif18pt7b); //set custom font
  238. tft.setCursor(35,34); //set position (x,y)
  239. tft.setTextColor(ST7735_WHITE); //set color of text
  240. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  241. tft.println("CPU"); //print the text
  242.  
  243.  
  244.  
  245.  
  246.  
  247. tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
  248. // It draws from the location to down-right
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. tft.setFont();
  258. tft.setCursor(6, 48);
  259. tft.setTextColor(ST7735_BLUE);
  260. tft.setTextSize(1);
  261. tft.println(" TEMPERATURE:");
  262.  
  263. tft.setFont();
  264. tft.setCursor(85, 48);
  265. tft.setTextColor(ST7735_WHITE);
  266. tft.setTextSize(1);
  267. tft.println(cpuTemp);
  268.  
  269. tft.fillRect(8, 62, cpuTemp, 22, ST7735_WHITE);
  270.  
  271. tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
  272.  
  273. tft.setFont();
  274. tft.setCursor(6, 90);
  275. tft.setTextColor(ST7735_BLUE);
  276. tft.setTextSize(1);
  277. tft.println(" USAGE:");
  278.  
  279. tft.setFont();
  280. tft.setCursor(50, 90);
  281. tft.setTextColor(ST7735_WHITE);
  282. tft.setTextSize(1);
  283. tft.println(cpuLoad);
  284.  
  285. tft.fillRect(8, 104, cpuLoad, 22, ST7735_WHITE);
  286.  
  287. delay(5000);
  288.  
  289. tft.fillScreen(ST7735_BLACK);
  290.  
  291. tft.setFont(&FreeSerif18pt7b); //set custom font
  292. tft.setCursor(35,34); //set position (x,y)
  293. tft.setTextColor(ST7735_WHITE); //set color of text
  294. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  295. tft.println("GPU"); //print the text
  296.  
  297.  
  298. tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
  299. // It draws from the location to down-right
  300. tft.setFont();
  301. tft.setCursor(6, 48);
  302. tft.setTextColor(ST7735_BLUE);
  303. tft.setTextSize(1);
  304. tft.println(" TEMPERATURE:");
  305.  
  306. tft.setFont();
  307. tft.setCursor(85, 48);
  308. tft.setTextColor(ST7735_WHITE);
  309. tft.setTextSize(1);
  310. tft.println(gpuTemp);
  311.  
  312. tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
  313. tft.fillRect(8, 62, gpuTemp, 22, ST7735_WHITE);
  314.  
  315. tft.setFont();
  316. tft.setCursor(6, 90);
  317. tft.setTextColor(ST7735_BLUE);
  318. tft.setTextSize(1);
  319. tft.println(" USAGE:");
  320.  
  321. tft.setFont();
  322. tft.setCursor(50, 90);
  323. tft.setTextColor(ST7735_WHITE);
  324. tft.setTextSize(1);
  325. tft.println(gpuLoad);
  326. tft.fillRect(8, 104, gpuLoad, 22, ST7735_WHITE);
  327.  
  328. delay(5000);
  329.  
  330. tft.fillScreen(ST7735_BLACK);
  331.  
  332. tft.setFont(&FreeSerif18pt7b); //set custom font
  333. tft.setCursor(29,34); //set position (x,y)
  334. tft.setTextColor(ST7735_WHITE); //set color of text
  335. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  336. tft.println("RAM"); //print the text
  337.  
  338.  
  339. tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
  340. tft.fillRect(8, 62, percentageRam, 22, ST7735_WHITE); // It draws from the location to down-right
  341.  
  342.  
  343. tft.setFont();
  344. tft.setCursor(6, 48);
  345. tft.setTextColor(ST7735_BLUE);
  346. tft.setTextSize(1);
  347. tft.println(" USAGE:");
  348.  
  349. tft.setFont();
  350. tft.setCursor(85, 48);
  351. tft.setTextColor(ST7735_WHITE);
  352. tft.setTextSize(1);
  353. tft.println(ramLoadString);
  354.  
  355. //tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
  356.  
  357. //tft.setFont();
  358. //tft.setCursor(6, 90);
  359. //tft.setTextColor(ST7735_BLUE);
  360. //tft.setTextSize(1);
  361. //tft.println(" USAGE:");
  362.  
  363. delay(5000);
  364.  
  365. tft.fillScreen(ST7735_BLACK);
  366.  
  367. humidityVal = dht.readHumidity(); // get the humidity from the DHT sensor
  368. tempValC = dht.readTemperature(); // get the temperature in degrees Celcius from the DHT sensor
  369. tempValF = dht.readTemperature(true); // get the temperature in degrees Fahrenheit from the DHT sensor
  370.  
  371. // Check if all values are read correctly, if not try again and exit loop()
  372. if (isnan(humidityVal) || isnan(tempValC) || isnan(tempValF)) {
  373. Serial.println("Reading DHT sensor failed!");
  374.  
  375. // end the loop() function
  376. return;
  377. }
  378.  
  379. // Calculate the windchill in degrees Celcius
  380. heatIndexC = dht.computeHeatIndex(tempValC, humidityVal, false);
  381.  
  382. // Calculate the windchill in degrees Fahrenheit
  383. heatIndexF = dht.computeHeatIndex(tempValF, humidityVal);
  384.  
  385. // Print all values to the serial monitor
  386. // \t prints a tab character, \n a newline
  387. Serial.print(humidityVal);
  388. Serial.print("\t");
  389. Serial.print(tempValC);
  390. Serial.print("\n");
  391.  
  392. delay(10);
  393.  
  394. tft.setFont(&FreeSerif18pt7b); //set custom font
  395. tft.setCursor(23,34); //set position (x,y)
  396. tft.setTextColor(ST7735_WHITE); //set color of text
  397. tft.setTextSize(1); //set text size. Can be from 0 to 20.
  398. tft.println("CASE"); //print the text
  399. tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
  400. // It draws from the location to down-right
  401.  
  402. //tft.drawRect(7, 63, 18, 20, ST7735_WHITE);
  403.  
  404. tft.setFont();
  405. tft.setCursor(6, 48);
  406. tft.setTextColor(ST7735_BLUE);
  407. tft.setTextSize(1);
  408. tft.println(" TEMPERATURE:");
  409.  
  410. tft.setFont();
  411. tft.setCursor(85, 48);
  412. tft.setTextColor(ST7735_WHITE);
  413. tft.setTextSize(1);
  414. tft.println(tempValC);
  415.  
  416.  
  417. tft.fillRect(8, 62, tempValC *3, 22, ST7735_WHITE);
  418.  
  419.  
  420. //tft.setFont();
  421. //tft.setCursor(85, 64);
  422. //tft.setTextColor(ST7735_WHITE);
  423. //tft.setTextSize(1);
  424. //tft.println(cpuTemp);
  425. //
  426. //tft.setFont();
  427. //tft.setCursor(85, 75);
  428. //tft.setTextColor(ST7735_WHITE);
  429. //tft.setTextSize(1);
  430. //tft.println(cpuLoad);
  431.  
  432. //tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
  433.  
  434. //tft.setFont();
  435. //tft.setCursor(6, 90);
  436. //tft.setTextColor(ST7735_BLUE);
  437. //tft.setTextSize(1);
  438. //tft.println(" USAGE:");
  439.  
  440.  
  441.  
  442.  
  443. delay(5000);
  444.  
  445.  
  446.  
  447.  
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement