Advertisement
safwan092

project-3152-new-code-ARABIC-COMMENTS

Nov 27th, 2020
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.18 KB | None | 0 0
  1. /*This is a project by Vrishak and Krishna Vemuri. This takes the temperature from the AMG8833 sensor and distance from HC-SR04. This corrects the temperature with the distance. Then, the pixels are shown on the SD card. The temperature is reported to NodeMcu, LCD, and SD card
  2. **************************************************************************
  3.   This is a library for the AMG88xx GridEYE 8x8 IR camera
  4.  
  5.   This sketch makes a 64 pixel thermal camera with the GridEYE sensor
  6.   and a 128x128 tft screen https://www.adafruit.com/product/2088
  7.  
  8.   Designed specifically to work with the Adafruit AMG88 breakout
  9.   ----> http://www.adafruit.com/products/3538
  10.  
  11.   These sensors use I2C to communicate. The device's I2C address is 0x69
  12.  
  13.   Adafruit invests time and resources providing this open source code,
  14.   please support Adafruit andopen-source hardware by purchasing products
  15.   from Adafruit!
  16.  
  17.   Written by Dean Miller for Adafruit Industries.
  18.   BSD license, all text above must be included in any redistribution
  19.  ***************************************************************************/
  20. // هذه المكتبات التي يتم استدعاءها في بداية الكود لتسهل عملية كتابة الكود
  21. #include <Adafruit_GFX.h>    // Core graphics library
  22. #include <Adafruit_ST7735.h> // Hardware-specific library
  23. #include <SPI.h>
  24. #include <LiquidCrystal_I2C.h>
  25. #include <Wire.h>
  26. #include <Adafruit_AMG88xx.h>
  27. #include <SR04.h>
  28. //#include <LiquidCrystal.h>
  29. #include <SD.h>
  30.  
  31. // هذه تعريفات لأماكن اتصال الحساسات بالأردوينو
  32. #define TFT_CS     53 //chip select pin for the TFT screen
  33. #define TFT_RST    9  // you can also connect this to the Arduino reset
  34. // in which case, set this #define pin to 0!
  35. #define TFT_DC     8
  36. #define trig 12
  37. #define echo 11
  38. int cardpin = 10;
  39.  
  40. //هذه أقل درجة يتم عرضها على الشاشة باللون الأزرق
  41. //low range of the sensor (this will be blue on the screen)
  42. #define MINTEMP 22
  43.  
  44. //هذه أعلى درجة يتم عرضها على الشاشة باللون الأحمر
  45. //high range of the sensor (this will be red on the screen)
  46. #define MAXTEMP 34
  47.  
  48. //هذا الأمر يقوم بتعريف عنصر حساس قياس المسافة ومكان اتصاله مع الأردوينو
  49. SR04 sr04 = SR04(echo, trig);
  50.  
  51. //هذا الأمر يقوم بتعريف عنصر الشاشة الصغيرة لعرض الكلام وتحديد حجمها وعدد الأسطر وترميزها
  52. LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  53. //LiquidCrystal lcd(27, 28, 29, 30, 31, 32);
  54.  
  55. File file;
  56.  
  57. // هذا متغير يتم استخدامه من عدة توابع يتم حفظ المسافة فيه
  58. long dist;
  59.  
  60. // هذه مصفوفة تحتوي على جميع الألوان التي يمكن عرضها على الشاشة الحرارية
  61. //the colors we will be using
  62. const uint16_t camColors[] = {0x480F,
  63.                               0x400F, 0x400F, 0x400F, 0x4010, 0x3810, 0x3810, 0x3810, 0x3810, 0x3010, 0x3010,
  64.                               0x3010, 0x2810, 0x2810, 0x2810, 0x2810, 0x2010, 0x2010, 0x2010, 0x1810, 0x1810,
  65.                               0x1811, 0x1811, 0x1011, 0x1011, 0x1011, 0x0811, 0x0811, 0x0811, 0x0011, 0x0011,
  66.                               0x0011, 0x0011, 0x0011, 0x0031, 0x0031, 0x0051, 0x0072, 0x0072, 0x0092, 0x00B2,
  67.                               0x00B2, 0x00D2, 0x00F2, 0x00F2, 0x0112, 0x0132, 0x0152, 0x0152, 0x0172, 0x0192,
  68.                               0x0192, 0x01B2, 0x01D2, 0x01F3, 0x01F3, 0x0213, 0x0233, 0x0253, 0x0253, 0x0273,
  69.                               0x0293, 0x02B3, 0x02D3, 0x02D3, 0x02F3, 0x0313, 0x0333, 0x0333, 0x0353, 0x0373,
  70.                               0x0394, 0x03B4, 0x03D4, 0x03D4, 0x03F4, 0x0414, 0x0434, 0x0454, 0x0474, 0x0474,
  71.                               0x0494, 0x04B4, 0x04D4, 0x04F4, 0x0514, 0x0534, 0x0534, 0x0554, 0x0554, 0x0574,
  72.                               0x0574, 0x0573, 0x0573, 0x0573, 0x0572, 0x0572, 0x0572, 0x0571, 0x0591, 0x0591,
  73.                               0x0590, 0x0590, 0x058F, 0x058F, 0x058F, 0x058E, 0x05AE, 0x05AE, 0x05AD, 0x05AD,
  74.                               0x05AD, 0x05AC, 0x05AC, 0x05AB, 0x05CB, 0x05CB, 0x05CA, 0x05CA, 0x05CA, 0x05C9,
  75.                               0x05C9, 0x05C8, 0x05E8, 0x05E8, 0x05E7, 0x05E7, 0x05E6, 0x05E6, 0x05E6, 0x05E5,
  76.                               0x05E5, 0x0604, 0x0604, 0x0604, 0x0603, 0x0603, 0x0602, 0x0602, 0x0601, 0x0621,
  77.                               0x0621, 0x0620, 0x0620, 0x0620, 0x0620, 0x0E20, 0x0E20, 0x0E40, 0x1640, 0x1640,
  78.                               0x1E40, 0x1E40, 0x2640, 0x2640, 0x2E40, 0x2E60, 0x3660, 0x3660, 0x3E60, 0x3E60,
  79.                               0x3E60, 0x4660, 0x4660, 0x4E60, 0x4E80, 0x5680, 0x5680, 0x5E80, 0x5E80, 0x6680,
  80.                               0x6680, 0x6E80, 0x6EA0, 0x76A0, 0x76A0, 0x7EA0, 0x7EA0, 0x86A0, 0x86A0, 0x8EA0,
  81.                               0x8EC0, 0x96C0, 0x96C0, 0x9EC0, 0x9EC0, 0xA6C0, 0xAEC0, 0xAEC0, 0xB6E0, 0xB6E0,
  82.                               0xBEE0, 0xBEE0, 0xC6E0, 0xC6E0, 0xCEE0, 0xCEE0, 0xD6E0, 0xD700, 0xDF00, 0xDEE0,
  83.                               0xDEC0, 0xDEA0, 0xDE80, 0xDE80, 0xE660, 0xE640, 0xE620, 0xE600, 0xE5E0, 0xE5C0,
  84.                               0xE5A0, 0xE580, 0xE560, 0xE540, 0xE520, 0xE500, 0xE4E0, 0xE4C0, 0xE4A0, 0xE480,
  85.                               0xE460, 0xEC40, 0xEC20, 0xEC00, 0xEBE0, 0xEBC0, 0xEBA0, 0xEB80, 0xEB60, 0xEB40,
  86.                               0xEB20, 0xEB00, 0xEAE0, 0xEAC0, 0xEAA0, 0xEA80, 0xEA60, 0xEA40, 0xF220, 0xF200,
  87.                               0xF1E0, 0xF1C0, 0xF1A0, 0xF180, 0xF160, 0xF140, 0xF100, 0xF0E0, 0xF0C0, 0xF0A0,
  88.                               0xF080, 0xF060, 0xF040, 0xF020, 0xF800,
  89.                              };
  90. //هذا الأمر يقوم بتعريف عنصر الشاشة الحرارية ومكان اتصالها مع الأردوينو
  91. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);
  92.  
  93. //هذا الأمر يقوم بتعريف عنصر الكاميرا الحرارية
  94. Adafruit_AMG88xx amg;
  95.  
  96. //هذه متغيرات لتحديد حجم الكاميرا الحرارية
  97. unsigned long delayTime;
  98. float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
  99. uint16_t displayPixelWidth, displayPixelHeight;
  100.  
  101.  
  102. //هذا التابع يعمل لمرة واحد عند تشغيل الأردوينو
  103. void setup() {
  104.   // هذا الأمر يقوم بفتح منفذ تسلسلي بين الأردوينو والكمبيوتر لحل الأخطاء وعرض البيانات التي يتم اتسقبالها من الحساسات
  105.   Serial.begin(9600);
  106.  
  107.   Serial1.begin(9600);
  108.   ////////////////////////////////////////////////////////////
  109.   // هذه الأوامر تقوم بتشغيل الشاشة الصغيرة لعرض البيانات عليها
  110.   ////////////////////////////////////////////////////////////
  111.   lcd.init();
  112.   lcd.init();
  113.   lcd.backlight();
  114.   ////////////////////////////////////////////////////////////
  115.  
  116.   //هذا الأمر يقوم بعرض جملة على شاشة الكمبيوتر توضح أن الكاميرا الحرارية متصلة
  117.   Serial.println(F("AMG88xx thermal camera!"));
  118.  
  119.   ////////////////////////////////////////////////////////////
  120.   //هذه الأوامر تقوم بتشغيل الشاشة الحرارية وتحديد طولها وعرضها
  121.   ////////////////////////////////////////////////////////////
  122.   tft.initR(INITR_144GREENTAB);   // initialize ST7735S chip
  123.   tft.fillScreen(ST7735_BLACK);
  124.   displayPixelWidth = tft.width() / 8;
  125.   displayPixelHeight = tft.height() / 8;
  126.   //tft.setRotation(3);
  127.   ////////////////////////////////////////////////////////////
  128.  
  129.   // هذا متغير يتم حفظ حالة الكاميرا الحرارية تعمل/لا تعمل
  130.   bool status;
  131.  
  132.   //هذا الأمر يقوم بالتأكد من عمل الكاميرا الحرارية وعرض جملة الخطأ إذا كانت الكاميرا غير متصلة بشكل صحيح مع الأردوينو
  133.   // default settings
  134.   status = amg.begin();
  135.   if (!status) {
  136.     Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
  137.     while (1);
  138.   }
  139.  
  140.   Serial.println("-- Thermal Camera Test --");
  141.   //lcd.begin(16, 2);
  142.   delay(100); // let sensor boot up
  143.  
  144.   /////////////////////////////////////////////////////////
  145.   //هذه أوامر تختص بحفظ البيانات على كرت الذاكرة الخارجية
  146.   /////////////////////////////////////////////////////////
  147.   pinMode(cardpin, OUTPUT);
  148.   if (!SD.begin(cardpin)) {
  149.     Serial.println("SD card initialization failed");
  150.   }
  151.  
  152.   if (SD.exists("data.txt")) {
  153.     Serial.println("data.txt exists.");
  154.     if (SD.remove("data.txt")) {
  155.       Serial.println("Successfully removed file.");
  156.     } else {
  157.       Serial.println("Could not remove data file.");
  158.     }
  159.   }
  160.   //////////////////////////////////////////////////////////
  161.  
  162. }// END OF SETUP
  163.  
  164. //هذا التابع يعمل بشكل مستمر بعد الانتهاء من عمل التابع الأول
  165. // يتكرر تنفيذ الأوامر بداخل هذا التابع إلى أن يتم توفيق عمل الأردوينو
  166. void loop() {
  167.   //هذا الأمر يقوم بقراءة جميع النقاط الحرارية من الكاميرا
  168.   //read all the pixels
  169.   amg.readPixels(pixels);
  170.  
  171.   ////////////////////////////////////////////////////////////////////////////////
  172.   //هذه الأوامر تقوم بعرض النقاط الحرارية على الشاشة الحرارية
  173.   ////////////////////////////////////////////////////////////////////////////////
  174.   float maxx = -99.9;
  175.   for (int i = 0; i < AMG88xx_PIXEL_ARRAY_SIZE; i++) {
  176.     uint8_t colorIndex = map(pixels[i], MINTEMP, MAXTEMP, 0, 255);
  177.     colorIndex = constrain(colorIndex, 0, 255);
  178.  
  179.     //draw the pixels!
  180.     tft.fillRect(displayPixelHeight * floor(i / 8), displayPixelWidth * (i % 8),
  181.                  displayPixelHeight, displayPixelWidth, camColors[colorIndex]);
  182.     if (pixels[i] > maxx) {
  183.       maxx = pixels[i];
  184.     }
  185.   }
  186.   ////////////////////////////////////////////////////////////////////////////////
  187.  
  188.   // هذا الأمر يقوم بقياس المسافة من حساس المسافة ووضع النتيجة في المتغير dist المسافة تقاس بالـ(cm)
  189.   dist = sr04.Distance();
  190.  
  191.   //هذه جملة شرطية اذا كانت المسافة أعلى من 40سم سيتم تنفيذ الأوامر التالية
  192.   if (dist > 40) {
  193.  
  194.     // هذا الأمر يظهر على شاشة الكمبيوتر جملة "أقترب من الحساس"
  195.     Serial.println("Come closer");
  196.  
  197.     // هذا الأمر يظهر على الشاشة الصغيرة جملة "أقترب من الحساس"
  198.     lcd.print("Come closer");
  199.   }
  200.   else {
  201.  
  202.     //هذه جملة شرطية اذا كانت المسافة أقل من 6سم سيتم تنفيذ الأوامر التالية
  203.     if (dist < 6) {
  204.       // هذا الأمر يظهر على شاشة الكمبيوتر جملة "أبتعد عن الحساس"
  205.       Serial.println("Go farther");
  206.  
  207.       // هذا الأمر يظهر على الشاشة الصغيرة جملة "أبتعد عن الحساس"
  208.       lcd.print("Go farther");
  209.     }
  210.  
  211.     // هذه الجملة الشرطية ستتنفذ إذا كانت المسافة أعلى من 6سم وأقل من 40سم سيتم تنفيذ الأوامر التالية
  212.     else {
  213.  
  214.       // هذه الأوامر تظهر على شاشة الكمبيوتر المسافة بالـ(cm)
  215.       Serial.print(dist);
  216.       Serial.println(" cm");
  217.  
  218.       // هذه الأوامر تقوم بحساب درجة الحرارة بالدرجة المئوية
  219.       float newmax = round((maxx + 5.25 + (dist / 9)) * 100);
  220.       float new2 = newmax / 100;
  221.       float degreesF = (new2);//(1.8*new2+32)*100;
  222.       int intF = (int) degreesF;
  223.  
  224.       //هذا الأمر يقوم بعرض درجة الحرارة بالدرجة المئوية  بفواصل عشرية على شاشة الكمبيوتر
  225.       // مثال 36.24 درجة مئوية
  226.       Serial.println(degreesF);
  227.  
  228.       //هذا الأمر يقوم بعرض درجة الحرارة بالدرجة المئوية بدون فواصل عشرية على شاشة الكمبيوتر
  229.       //مثال 36 درجة مئوية
  230.       Serial.println(intF);
  231.  
  232.       //هذا الأمر يقوم بتحديد محرف الكتابة على المحرف الأول في السطر الأول
  233.       lcd.setCursor(0, 0);
  234.  
  235.       //lcd.print("Temp: "+String(degreesF/100));
  236.  
  237.       //هذا الأمر يقوم بعرض درجة الحرارة على الشاشة الصغيرة بعد تحويل درجة الحرارة الى مصفوفة محارف STRING
  238.       lcd.print("Temp: " + String(degreesF));
  239.  
  240.       Serial1.println(intF);
  241.  
  242.       //هذا الأمر يقوم بتحديد محرف الكتابة على المحرف الأول في السطر الثاني
  243.       lcd.setCursor(0, 1);
  244.  
  245.       //هذه جملة شرطية إذا كانت حرارة الشخص أقل من الحرارة هذه يتم تنفيذ الأوامر التالية
  246.       //Degrees F is the degree measure without the decimal point.
  247.       if (degreesF < 10040) {
  248.         // هذا الأمر يظهر على الشاشة الصغيرة جملة "هذا الشخص سليم"
  249.         lcd.print("Person is safe");
  250.  
  251.       }
  252.       else {
  253.         //هذه جملة شرطية إذا كانت حرارة الشخص أقل من الحرارة هذه يتم تنفيذ الأوامر التالية
  254.         if (degreesF <= 10220) {
  255.           // هذا الأمر يظهر على الشاشة الصغيرة جملة "إذهب إلى المنزل"
  256.           lcd.print("Send person home");
  257.  
  258.         }
  259.         //هذه جملة شرطية إذا كانت حرارة الشخص أعلى من الحرارة المذكورة في الشرط السابق يتم تنفيذ الأوامر التالية
  260.         else {
  261.           // هذا الأمر يظهر على الشاشة الصغيرة جملة "إذهب إلى الطوارئ"
  262.           lcd.print("Person go to ER");
  263.  
  264.         }
  265.       }
  266.       ////////////////////////////////////////////////////////////////////////////////
  267.       //هذه الأوامر تقوم بفتح ملف داخل كرت الذاكرة وتقوم بحفظ درجة الحرارة بداخله
  268.       ////////////////////////////////////////////////////////////////////////////////
  269.       file = SD.open("data.txt", FILE_WRITE);
  270.       if (file) {
  271.         String fulldata = "Temp: " + String(degreesF);
  272.         file.println(fulldata);
  273.         file.close();
  274.       }
  275.  
  276.       else {
  277.         // هذا الأمر يظهر على شاشة الكمبيوتر وجود خطأ في كتابة البيانات على كرت الذاكرة
  278.         Serial.println("Error in writing data file");
  279.  
  280.       }
  281.       ////////////////////////////////////////////////////////////////////////////////
  282.     }
  283.   }
  284.   // هذا الأمر يقوم بتوقيف الكود لمدة 200 ميلي ثانية حتى يستقر المتحكم
  285.   delay(200);
  286.   //هذا الأمر يقوم بمسح المحتويات من الشاشة
  287.   lcd.clear();
  288.  
  289. }//END OF LOOP
  290.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement