close

夏天到了想要開啟冷氣才發現遙控器螢幕黑屏了,本想丟掉換新的,後來google一下,發現黑屏是可以救的,於是死馬當活馬醫,反正壞了也沒關係~~

IMG_2328.jpg

首先把遙控器拆開,LCD的背板已經黑黑的,粉紅色的是導電膠條,要對應基板金手指不要弄掉了~

IMG_2330.jpg

用美工刀尖端把背膠撕開,注意平均施力避免玻璃破裂

IMG_2332.jpg

IMG_2333.jpg

撕掉後看起來就是一塊透明玻璃(背膠太黏,黑線都掉漆了....)

IMG_2334.jpg

找銀龍貼紙(背膠面是銀色的可以反光),裁切適合大小貼合在LCD玻璃上

IMG_2335.jpg

注意表面清潔,避免異物及氣泡

IMG_2337.jpg

完成~~(技術不好表面還是有氣泡 >_<)

IMG_2338.jpg

把LCD跟基板組合好,注意導電膠跟金手指的位置,上電測試,可以正常顯示,已經沒有黑屏了~~

IMG_2339.jpg

忽然間有個大膽的想法,遙控器基板按鍵的兩端都有獨立的pad,那是否可另外拉線來控制遙控器呢?

第一個我就想到用Siri來控制遙控器開啟/關閉冷氣,還可以調溫度,因此只要控制3個按鈕,因此要設計一個HomeKit裝置控制3個Switch

之前有設計一個ESP8266 HomeKit裝置,3個GPIO 控制3個光偶,模擬開關可以控制鐵捲門遙控器,就直接拿來套用

IMG_1882.jpg

線路圖

esp8266.PNG

ESP8266 HomeKit 程式庫選用這個,目前使用上比較穩定 Arduino-HomeKit-ESP8266

可以用這個範例2去修改

ESP8266_Homekit.png

example2.png

範例只有一個Switch,因此要再增加兩個,程式修改如下,請參考

wifi_info.h 可以刪除,我已經修改為WiFiManager,不用每次修改WiFi密碼

Example02_Switch

==================================================================


/*
 * switch.ino
 *
 *  Created on: 2020-05-15
 *      Author: Mixiaoxiao (Wang Bin)
 *
 * HAP section 8.38 Switch
 * An accessory contains a switch.
 *
 * This example shows how to:
 * 1. define a switch accessory and its characteristics (in my_accessory.c).
 * 2. get the switch-event sent from iOS Home APP.
 * 3. report the switch value to HomeKit.
 *
 * You should:
 * 1. read and use the Example01_TemperatureSensor with detailed comments
 *    to know the basic concept and usage of this library before other examples。
 * 2. erase the full flash or call homekit_storage_reset() in setup()
 *    to remove the previous HomeKit pairing storage and
 *    enable the pairing with the new accessory of this new HomeKit example.
 */
#include "Arduino.h"
#include "arduino_homekit_server.h"
#include "ArduinoOTA.h"
#include "EEPROM.h"
#include "WiFiManager.h"
#include "Ticker.h"
Ticker ticker;
#define LOG_D(fmt, ...)   printf_P(PSTR(fmt "\n") , ##__VA_ARGS__);
const int OTA_Pin = 12;//OTA
const int ledPin = 2;//LED
//const int downPin = 4;//DOWN
//const int upPin = 5;  //UP
//const int stopPin = 13; //STOP
bool ota_flag = false;
void tick()
{
  digitalWrite(ledPin, !digitalRead(ledPin));     // set pin to the opposite state
}
void setup() {
	Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(OTA_Pin, INPUT_PULLUP);
  //WiFi
  WiFi.mode(WIFI_STA);
  WiFiManager wifiManager;
  wifiManager.autoConnect("Remote_Control");
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);
  if(WiFi.isConnected()){
  for (int i = 0; i < 2 ; i++) {
        digitalWrite(ledPin, HIGH);
        delay(200);
        digitalWrite(ledPin, LOW);
        delay(200);
      }
      digitalWrite(ledPin, HIGH);
  }
 //Start OTA 按住OTA鈕 藍燈閃3下放開進入OTA模式
  if (digitalRead(OTA_Pin) == LOW) {
      for (int i = 0; i < 3 ; i++) {
        digitalWrite(ledPin, HIGH);
        delay(500);
        digitalWrite(ledPin, LOW);
        delay(500);
      }
      delay(3000);
    if (digitalRead(OTA_Pin) == HIGH) {
      Serial.println("OTA.....");
      ota_flag = true;
      ArduinoOTA.onStart([]() {
        String type;
        if (ArduinoOTA.getCommand() == U_FLASH) {
          type = "sketch";
        } else { // U_FS
          type = "filesystem";
        }

        // NOTE: if updating FS this would be the place to unmount FS using FS.end()
        Serial.println("Start updating " + type);
      });
      ArduinoOTA.onEnd([]() {
        Serial.println("\nEnd");
      });
      ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
      });
      ArduinoOTA.onError([](ota_error_t error) {
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) {
          Serial.println("Auth Failed");
        } else if (error == OTA_BEGIN_ERROR) {
          Serial.println("Begin Failed");
        } else if (error == OTA_CONNECT_ERROR) {
          Serial.println("Connect Failed");
        } else if (error == OTA_RECEIVE_ERROR) {
          Serial.println("Receive Failed");
        } else if (error == OTA_END_ERROR) {
          Serial.println("End Failed");
        }
      });
      ArduinoOTA.begin();
      Serial.println("Ready");
      Serial.print("IP address: ");
      Serial.println(WiFi.localIP());
    }
    delay(1000);
    if (digitalRead(OTA_Pin) == LOW) {//長按OTA鈕直到快閃6下,清除所有設定
      Serial.println("Reset.....");
      wifiManager.resetSettings();
      homekit_storage_reset();
      for (int i = 0; i < 6 ; i++) {
        digitalWrite(ledPin, HIGH);
        delay(100);
        digitalWrite(ledPin, LOW);
        delay(200);
      } 
     ESP.restart();   
   }
  }
  else {
	//homekit_storage_reset(); // to remove the previous HomeKit pairing storage when you first run this new HomeKit example
	my_homekit_setup();
  ticker.attach(1, tick);
  }
}

void loop() {
  if (ota_flag) {
    ArduinoOTA.handle();
  }
  else{
	my_homekit_loop();
	delay(10);
 }
}

//==============================
// HomeKit setup and loop
//==============================

// access your HomeKit characteristics defined in my_accessory.c
extern "C" homekit_server_config_t config;
extern "C" homekit_characteristic_t cha_switch_on;  //第1組SW
extern "C" homekit_characteristic_t cha_switch_on2; //第2組SW
extern "C" homekit_characteristic_t cha_switch_on3; //第3組SW

static uint32_t next_heap_millis = 0;

#define PIN_SWITCH 5   //up
#define PIN_SWITCH2 4  //down
#define PIN_SWITCH3 13 //On/OFF
//Called when the switch value is changed by iOS Home APP
void cha_switch_on_setter(const homekit_value_t value) {
	bool on = value.bool_value;
	cha_switch_on.value.bool_value = on;	//sync the value
	LOG_D("Switch: %s", on ? "ON" : "OFF");
	digitalWrite(PIN_SWITCH, on ? HIGH : LOW); //顯示SW狀態
  delay(200);
  digitalWrite(PIN_SWITCH, LOW); //每次按下200ms後恢復低電平模擬短按按鈕
 // bool switch_is_on = false;
 // cha_switch_on.value.bool_value = switch_is_on;
 // homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value);
}
void cha_switch_on2_setter(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on2.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  digitalWrite(PIN_SWITCH2, on ? HIGH : LOW);
  delay(200);
  digitalWrite(PIN_SWITCH2, LOW);
//  bool switch_is_on2 = false;
//  cha_switch_on2.value.bool_value = switch_is_on2;
//  homekit_characteristic_notify(&cha_switch_on2, cha_switch_on2.value);
}
void cha_switch_on3_setter(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on3.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  if(on == true){  //當開關狀態為on,顯示為開
    digitalWrite(PIN_SWITCH3, on ? HIGH : LOW);
    delay(500);
    digitalWrite(PIN_SWITCH3, LOW);//每次按下500ms後恢復低電平模擬短按按鈕
  }
  else{   //當開關狀態為off,顯示為關
    digitalWrite(PIN_SWITCH3, on ? HIGH : LOW);
    delay(200);
    digitalWrite(PIN_SWITCH3, HIGH);//每次按輸出高電平,500ms後恢復低電平模擬短按按鈕
    delay(500);
    digitalWrite(PIN_SWITCH3, LOW);
  }
  //bool switch_is_on3 = false;
  //cha_switch_on3.value.bool_value = switch_is_on3;
  //homekit_characteristic_notify(&cha_switch_on3, cha_switch_on3.value);
}
void my_homekit_setup() {
	pinMode(PIN_SWITCH, OUTPUT);
	digitalWrite(PIN_SWITCH, LOW);
  pinMode(PIN_SWITCH2, OUTPUT);
  digitalWrite(PIN_SWITCH2, LOW);
  pinMode(PIN_SWITCH3, OUTPUT);
  digitalWrite(PIN_SWITCH3, LOW);
	//Add the .setter function to get the switch-event sent from iOS Home APP.
	//The .setter should be added before arduino_homekit_setup.
	//HomeKit sever uses the .setter_ex internally, see homekit_accessories_init function.
	//Maybe this is a legacy design issue in the original esp-homekit library,
	//and I have no reason to modify this "feature".
	cha_switch_on.setter = cha_switch_on_setter;
  cha_switch_on2.setter = cha_switch_on2_setter;
  cha_switch_on3.setter = cha_switch_on3_setter;
	arduino_homekit_setup(&config);

	//report the switch value to HomeKit if it is changed (e.g. by a physical button)
	//bool switch_is_on = false;
	//cha_switch_on.value.bool_value = switch_is_on;
	//homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value);
}

void my_homekit_loop() {
	arduino_homekit_loop();
	const uint32_t t = millis();
	if (t > next_heap_millis) {
		// show heap info every 5 seconds
		next_heap_millis = t + 3 * 1000;
		LOG_D("Free heap: %d, HomeKit clients: %d",
		ESP.getFreeHeap(), arduino_homekit_connected_clients_count());

	}
}
	
	

修改裝置敘述

Line 22~30可以修改裝置顯示的名稱

my_accessory

==================================================================


/*
 * my_accessory.c
 * Define the accessory in C language using the Macro in characteristics.h
 *
 *  Created on: 2020-05-15
 *      Author: Mixiaoxiao (Wang Bin)
 */

#include "homekit/homekit.h"
#include "homekit/characteristics.h"

void my_accessory_identify(homekit_value_t _value) {
	printf("accessory identify\n");
}

// Switch (HAP section 8.38)
// required: ON
// optional: NAME

// format: bool; HAP section 9.70; write the .setter function to get the switch-event sent from iOS Home APP.
homekit_characteristic_t cha_switch_on = HOMEKIT_CHARACTERISTIC_(ON, false);
// format: string; HAP section 9.62; max length 64
homekit_characteristic_t cha_name = HOMEKIT_CHARACTERISTIC_(NAME, "SW_UP");
//switch2
homekit_characteristic_t cha_switch_on2 = HOMEKIT_CHARACTERISTIC_(ON, false);
homekit_characteristic_t cha_name2 = HOMEKIT_CHARACTERISTIC_(NAME, "SW_DOWN");
//switch2
homekit_characteristic_t cha_switch_on3 = HOMEKIT_CHARACTERISTIC_(ON, false);
homekit_characteristic_t cha_name3 = HOMEKIT_CHARACTERISTIC_(NAME, "SW_ONOFF");
homekit_accessory_t *accessories[] = {
    HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) {
        HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
            HOMEKIT_CHARACTERISTIC(NAME, "SW_UP"),
            HOMEKIT_CHARACTERISTIC(MANUFACTURER, "ESP HomeKit"),
            HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "123456"),
            HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"),
            HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"),
            HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
            NULL
        }),
		HOMEKIT_SERVICE(SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){
			&cha_switch_on,
			&cha_name,
			NULL
		}),
        NULL
    }),
    HOMEKIT_ACCESSORY(.id=2, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) {
        HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
            HOMEKIT_CHARACTERISTIC(NAME, "SW_DOWN"),
            HOMEKIT_CHARACTERISTIC(MANUFACTURER, "ESP HomeKit"),
            HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"),
            HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"),
            HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"),
            HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
            NULL
        }),
    HOMEKIT_SERVICE(SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){
      &cha_switch_on2,
      &cha_name2,
      NULL
    }),
        NULL
    }),
    HOMEKIT_ACCESSORY(.id=3, .category=homekit_accessory_category_switch, .services=(homekit_service_t*[]) {
        HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
            HOMEKIT_CHARACTERISTIC(NAME, "SW_STOP"),
            HOMEKIT_CHARACTERISTIC(MANUFACTURER, "ESP HomeKit"),
            HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"),
            HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"),
            HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"),
            HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
            NULL
        }),
    HOMEKIT_SERVICE(SWITCH, .primary=true, .characteristics=(homekit_characteristic_t*[]){
      &cha_switch_on3,
      &cha_name3,
      NULL
    }),
        NULL
    }),
    NULL
};

homekit_server_config_t config = {
		.accessories = accessories,
		.password = "111-11-111"
};

燒錄好程式就可以測試配對,配對代碼 111-11-111 (8個1)

IMG_1885.PNG

配對好就會顯示在"家庭"裡面

IMG_2349.PNG

接下來就是DIY時間了,因為遙控器種類太多,所以依現況改造

把相對應按鍵的Pad 焊上漆包線(選擇較細軟的訊號線,避免影響實體按鍵操作)

用紙膠帶固定漆包線避免干擾按鍵,一共4條訊號線,對應按鍵:

ON/OFF : 對應Pin 1- 2

升溫 : 對應Pin 2- 4

降溫 : 對應Pin 3- 4

IMG_2343.jpg

確認完成後把訊號線拉到背面,就可以先將按鍵組裝起來

IMG_2345.jpg

將訊號線跟ESP8266 裝置組裝起來,遙控器電源一般為3V,所以可以直接使用ESP的電源即可

IMG_2347.jpg

組裝完成,上電測試一下,顯示功能正常

IMG_2346.jpg

接下來看看測試的影片~~

 

 

arrow
arrow
    創作者介紹
    創作者 terrywu5 的頭像
    terrywu5

    IoT 智慧生活的異想世界

    terrywu5 發表在 痞客邦 留言(1) 人氣()