بسم الله الرحمن الرحيم
بعد ان قمنا في احد المشاريع السابقة بتصميم مثل هذه المشاريع للإطلاع عليه اضغط هنا
لكن سنقوم اليوم بتصميم هذا المشروع بإستبدال شاشة lcd بشاشة oled
اولا الأدوات :
Arduino nano
mlx sensor
oled screen
Arduino nano
المتحكم الذي سنستخدمه للقيام بعمليات العرض و قياس درجة الحرارة
mlx sensor
حساس الحرارة الذي يميزه عن الحساس التقليدي انه يمكنه قياس درجة الحرارة بدون لمسه
oled screen
شاشة oled التي تتميز عن lcd بحيث انه يمكنها عرض صور اكثر دقة عن شاشة lcd وانها تتميز بصغر حجمها
ثانيا التوصيلات :
تعتمد حساس mlx و شاشة oled في اتصالهم علي بروتوكول i2c
الذي يتعامل مع sda , sck
ويتم توصيل منافذ الطاقة الي الأردوينو
الموجب الي منفذ الطاقة 5 فولت ومنفذ السالب الي سالب اردوينو
ثالثا الكود :
في البداية يجب ان تقوم بتحميل المكتبات الأساسية
Adafruit_MLX90614
Adafruit_GFX
Adafruit_SSD1306
يمكن اضافة كل هذه المكتبات من manage library في محرر كود arduino ide
ونتجه الأن الي الكود
#include <Adafruit_MLX90614.h> //for infrared thermometer
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
#include <Fonts/FreeMonoBold18pt7b.h> // Add a custom font
Adafruit_SSD1306 display(128, 64); //Create display
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); //for infrared thermometer
int temp; // Create a variable to have something dynamic to show on the display
void setup()
{
delay(100); // This delay is needed to let the display to initialize
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
mlx.begin(); //start infrared thermometer
}
void loop()
{
temp++; // Increase value for testing
if(temp > 43) // If temp is greater than 150
{
temp = 0; // Set temp to 0
}
temp = mlx.readObjectTempC(); //comment this line if you want to test
display.clearDisplay(); // Clear the display so we can refresh
// Print text:
display.setFont();
display.setCursor(45,10); // (x,y)
display.println("TEMPERATURE"); // Text or value to print
// Print temperature
char string[10]; // Create a character array of 10 characters
// Convert float to a string:
dtostrf(temp, 3, 0, string); // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)
display.setFont(&FreeMonoBold18pt7b); // Set a custom font
display.setCursor(20,50); // (x,y)
display.println(string); // Text or value to print
display.setCursor(90,50); // (x,y)
display.println("C"); // Text or value to print
display.setCursor(77,32); // (x,y)
display.println("."); // Text or value to print
// Draw a filled circle:
display.fillCircle(18, 55, 7, WHITE); // Draw filled circle (x,y,radius,color). X and Y are the coordinates for the center point
// Draw rounded rectangle:
display.drawRoundRect(16, 3, 5, 49, 2, WHITE); // Draw rounded rectangle (x,y,width,height,radius,color)
// It draws from the location to down-right
// Draw ruler step
for (int i = 6; i<=45; i=i+3){
display.drawLine(21, i, 22, i, WHITE); // Draw line (x0,y0,x1,y1,color)
}
//Draw temperature
temp = temp*0.43; //ratio for show
display.drawLine(18, 46, 18, 46-temp, WHITE); // Draw line (x0,y0,x1,y1,color)
display.display(); // Print everything we set previously
}
يحتوي الكود علي تفصيل له بجانب كل امر ولن نتطرق الي شرحه
لتحميل الكود اضغط هنا
تصميم : بلال حسان سعدي
لا يوجد تعليقات
أضف تعليق