تفاصيل العمل

This code is an ESP-IDF I²C example that demonstrates how to configure and use the ESP32 as an I²C master, and optionally as an I²C slave, to communicate with external devices. The main focus is reading data from a BH1750 light intensity sensor over the I²C bus and displaying the measured light value in lux.

The code initializes the I²C master interface, sends commands to the BH1750 sensor to start a measurement, then reads the sensor data and converts it into a lux value. When the hardware supports more than one I²C controller, the code also includes test functions for master–slave communication between two ESP32 devices, demonstrating data read and write operations.

FreeRTOS tasks are used to run periodic I²C tests, while mutexes ensure synchronized access to the serial output. Overall, this example shows practical usage of I²C configuration, data transmission, sensor interfacing, and multitasking on ESP32-based systems.

هذا الكود مثال باستخدام ESP-IDF يوضح كيفية استخدام بروتوكول I²C على متحكم ESP32. يقوم المتحكم بالعمل كـ Master للتواصل مع حساس BH1750 لقياس شدة الإضاءة.

يقوم الكود بتهيئة واجهة I²C، ثم يرسل أمرًا للحساس لبدء القياس، وبعد ذلك يقرأ بيانات الإضاءة ويحوّلها إلى قيمة Lux ويتم عرضها على الشاشة التسلسلية.

في حال كان المتحكم يدعم أكثر من واجهة I²C، يتضمن الكود أيضًا اختبارًا للتواصل بين ESP32 كـ Master وESP32 آخر كـ Slave لقراءة وكتابة البيانات.

يستخدم الكود مهام FreeRTOS لتنفيذ العمليات بشكل دوري، مع استخدام Mutex لتنظيم الطباعة ومنع التعارض. بشكل عام، يوضح المثال أساسيات التعامل مع I²C، قراءة الحساسات، والتعامل مع المهام في أنظمة ESP32.

بطاقة العمل

اسم المستقل
عدد الإعجابات
0
عدد المشاهدات
11
تاريخ الإضافة