ProjectsProjeler / IOT-01
Wireless · MicroPython · display driverKablosuz · MicroPython · ekran sürücüsü
ESP32 smart notification displayESP32 akıllı bildirim ekranı
An ESP32 running MicroPython acts as a Bluetooth Low Energy device. My phone sends it the text of a notification, and the ESP32 draws it on a 0.96″ SSD1306 OLED connected over I²C.
MicroPython çalıştıran bir ESP32, Bluetooth Low Energy cihazı gibi davranıyor. Telefonum ona bir bildirimin metnini gönderiyor, ESP32 de bunu I²C ile bağlı 0.96″ SSD1306 OLED ekrana çiziyor.
Why this project
It is a small build, but it touches two protocols that show up everywhere in embedded work, and I wanted to understand both on a real board instead of only in a datasheet: BLE for the wireless side and I²C for the wired side.
The BLE side
BLE does not work like a serial cable. A device exposes services, each service has characteristics, and a characteristic is basically a small value with an ID (a UUID) and permissions such as read, write or notify. This structure is called GATT.
On the ESP32 I set up a peripheral that advertises itself and exposes one writable characteristic. When the phone writes bytes to it, MicroPython raises an interrupt-style event, the handler reads the value, decodes it as UTF-8 and passes the text to the display code. The phone is the central, the ESP32 is the peripheral.
The I²C side
I²C needs only two wires, SDA (data) and SCL (clock), plus power and ground. Both lines are open-drain, so they need pull-up resistors; most OLED breakout boards already have them. Each device has a 7-bit address, and the SSD1306 is usually at 0x3C. Running i2c.scan() first and seeing that address come back is the quickest way to know the wiring is right.
from machine import Pin, I2C
import ssd1306
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
print(i2c.scan()) # expect [60] → 0x3C
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0); oled.text("hello", 0, 0); oled.show()
The display is 128×64 pixels and the built-in font is 8×8, so one screen fits 16 characters × 8 lines. Long notifications have to be wrapped or scrolled, which was a nice small exercise in string handling.
Concepts used
BLE advertising, GATT services and characteristics, event callbacks, UTF-8 decoding, I²C addressing and pull-ups, framebuffers. See the notes page.
Neden bu proje
Küçük bir proje ama gömülü sistemlerde her yerde karşıma çıkan iki protokole dokunuyor ve ikisini de sadece datasheet'ten değil, gerçek bir kart üzerinde anlamak istedim: kablosuz taraf için BLE, kablolu taraf için I²C.
BLE tarafı
BLE bir seri kablo gibi çalışmıyor. Bir cihaz servisler sunuyor, her servisin karakteristikleri var; bir karakteristik de temelde bir kimliği (UUID) ve okuma, yazma ya da bildirim gibi izinleri olan küçük bir değer. Bu yapıya GATT deniyor.
ESP32'de kendini duyuran (advertising) ve yazılabilir tek bir karakteristik sunan bir peripheral kurdum. Telefon buna byte yazdığında MicroPython kesme benzeri bir olay üretiyor, handler değeri okuyor, UTF-8 olarak çözüyor ve metni ekran koduna veriyor. Telefon central, ESP32 ise peripheral rolünde.
I²C tarafı
I²C, güç ve toprağa ek olarak sadece iki kablo istiyor: SDA (veri) ve SCL (saat). İki hat da open-drain olduğu için pull-up dirençlerine ihtiyaç var; çoğu OLED modülünde bunlar zaten takılı geliyor. Her cihazın 7 bitlik bir adresi var ve SSD1306 genelde 0x3C adresinde. Önce i2c.scan() çalıştırıp bu adresin geldiğini görmek, kablolamanın doğru olduğunu anlamanın en hızlı yolu.
from machine import Pin, I2C
import ssd1306
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
print(i2c.scan()) # [60] bekleniyor → 0x3C
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0); oled.text("merhaba", 0, 0); oled.show()
Ekran 128×64 piksel ve yerleşik font 8×8, yani bir ekrana 16 karakter × 8 satır sığıyor. Uzun bildirimlerin satıra bölünmesi ya da kaydırılması gerekiyor; bu da metin işleme açısından güzel bir küçük alıştırma oldu.
Kullanılan kavramlar
BLE advertising, GATT servisleri ve karakteristikleri, olay callback'leri, UTF-8 çözme, I²C adresleme ve pull-up'lar, framebuffer. Notlar sayfasına bakabilirsiniz.