Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on Pi Pico W #169

Open
sfozz opened this issue Sep 9, 2024 · 5 comments
Open

Building on Pi Pico W #169

sfozz opened this issue Sep 9, 2024 · 5 comments

Comments

@sfozz
Copy link

sfozz commented Sep 9, 2024

Couple of build issues when building for this target.

I've added the following to allow the builds to get started

diff --git a/components/mitsubishi_heatpump/climate.py b/components/mitsubishi_heatpump/climate.py
index da16834..b9c4d74 100644
--- a/components/mitsubishi_heatpump/climate.py
+++ b/components/mitsubishi_heatpump/climate.py
@@ -53,6 +53,8 @@ def valid_uart(uart):
         uarts = ["UART0"]  # UART1 is tx-only
     elif CORE.is_esp32:
         uarts = ["UART0", "UART1", "UART2"]
+    elif CORE.is_rp2040:
+        uarts = ["UART0", "UART1"]
     else:
         raise NotImplementedError

Following this I had to add the build options from here but the builds were still failing... so I added the following as suggested by g++

diff --git a/components/mitsubishi_heatpump/espmhp.h b/components/mitsubishi_heatpump/espmhp.h
index 110d6be..3f6ff7a 100644
--- a/components/mitsubishi_heatpump/espmhp.h
+++ b/components/mitsubishi_heatpump/espmhp.h
@@ -23,6 +23,7 @@
 #include <chrono>

 #include "HeatPump.h"
+#include <optional>

 #ifndef ESPMHP_H
 #define ESPMHP_H

I'm now getting the following errors, which are well outside of my c++ chops

src/esphome/components/mitsubishi_heatpump/espmhp.cpp: In member function 'virtual void MitsubishiHeatPump::setup()':
src/esphome/components/mitsubishi_heatpump/espmhp.cpp:703:13: error: cannot convert 'MitsubishiHeatPump::setup()::<lambda()>' to 'void (*)()'
  703 |             [this]() {
      |             ^~~~~~~~~~
      |             |
      |             MitsubishiHeatPump::setup()::<lambda()>
  704 |                 this->hpSettingsChanged();
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~
  705 |             }
      |             ~
In file included from src/esphome/components/mitsubishi_heatpump/espmhp.h:25,
                 from src/esphome.h:23,
                 from src/esphome/components/mitsubishi_heatpump/espmhp.h:20,
                 from src/esphome/components/mitsubishi_heatpump/espmhp.cpp:21:
.piolibdeps/heatpump/HeatPump/src/HeatPump.h:40:52: note:   initializing argument 1 of 'void HeatPump::setSettingsChangedCallback(void (*)())'
   40 | #define SETTINGS_CHANGED_CALLBACK_SIGNATURE void (*settingsChangedCallback)()
      |                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
.piolibdeps/heatpump/HeatPump/src/HeatPump.h:291:37: note: in expansion of macro 'SETTINGS_CHANGED_CALLBACK_SIGNATURE'
  291 |     void setSettingsChangedCallback(SETTINGS_CHANGED_CALLBACK_SIGNATURE);
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/esphome/components/mitsubishi_heatpump/espmhp.cpp:709:13: error: cannot convert 'MitsubishiHeatPump::setup()::<lambda(heatpumpStatus)>' to 'void (*)(heatpumpStatus)'
  709 |             [this](heatpumpStatus currentStatus) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |             |
      |             MitsubishiHeatPump::setup()::<lambda(heatpumpStatus)>
  710 |                 this->hpStatusChanged(currentStatus);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |             }
      |             ~
.piolibdeps/heatpump/HeatPump/src/HeatPump.h:41:50: note:   initializing argument 1 of 'void HeatPump::setStatusChangedCallback(void (*)(heatpumpStatus))'
   41 | #define STATUS_CHANGED_CALLBACK_SIGNATURE void (*statusChangedCallback)(heatpumpStatus newStatus)
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.piolibdeps/heatpump/HeatPump/src/HeatPump.h:292:35: note: in expansion of macro 'STATUS_CHANGED_CALLBACK_SIGNATURE'
  292 |     void setStatusChangedCallback(STATUS_CHANGED_CALLBACK_SIGNATURE);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@sfozz
Copy link
Author

sfozz commented Sep 9, 2024

esphome:
  platformio_options:
    build_unflags:
      - "-std=gnu++11"
    build_flags:
      - "-std=gnu++17"
  name: heatpump
  friendly_name: HeatPump

rp2040:
  board: rpipicow
  framework:
    platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "***"

ota:
  - platform: esphome
    password: "***"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Heatpump Fallback Hotspot"
    password: "***"

external_components:
  - source: github://sfozz/esphome-mitsubishiheatpump

climate:
  - platform: mitsubishi_heatpump
    name: "${friendly_name}"

    horizontal_vane_select:
      name: Horizontal Vane

    hardware_uart: UART1
    baud_rate: 4800
    

@ngist
Copy link

ngist commented Jan 4, 2025

Man I wish i found this a few hours ago as I just went through this myself and repeated your work. Although rather than adding the #include i changed the references to std::optional in espmhp.h to esphome::optional

I made it one step further though. In the SwiCago/HeatPump library it defines STATUS_CHANGED_CALLBACK_SIGNATURE based on what chip is being used. You'll want to change #if defined(ESP8266) || defined(ESP32) to #if defined(ESP8266) || defined(ESP32) || defined(USE_RP2040) link

I've got a fork with the change here, you'll need to edit

repository="https://github.com/SwiCago/HeatPump#5d1e146771d2f458907a855bf9d5d4b9bf5ff033",

All i can say is with that addtional change I was able to compile it and load it on the PicoW, I still need to physically connect it to a heatpump to see if it actually works.

@ngist
Copy link

ngist commented Jan 16, 2025

The above changes were enough to compile but not enough to get it to work apparently.

One more change i've identified:
serial = HARDWARE_UART_TO_SERIAL[PLATFORM_ESP8266][config[CONF_HARDWARE_UART]]

Needs to properly select when PLATFORM is RP2040 otherwise the wrong serial will be selected.

Here's my attempt though it seems to have stopped me from doing wireless updates after making this change.

if CORE.is_rp2040:
    serial = HARDWARE_UART_TO_SERIAL[PLATFORM_RP2040][config[CONF_HARDWARE_UART]]
else:
    serial = HARDWARE_UART_TO_SERIAL[PLATFORM_ESP8266][config[CONF_HARDWARE_UART]]

See here:

serial = HARDWARE_UART_TO_SERIAL[PLATFORM_ESP8266][config[CONF_HARDWARE_UART]]

https://github.com/esphome/esphome/blob/b4a804cc779bcb8a3b1480a44741bf9f29caa33c/esphome/components/logger/__init__.py#L111

@sfozz
Copy link
Author

sfozz commented Jan 16, 2025

@ngist thanks for looking into this... I'll have a look this weekend and update here!

@ngist
Copy link

ngist commented Jan 16, 2025

No problem, one other thing worth mentioning before you hook this up to your unit. Do you have an interface circuit for the PicoW? As I understand it the CN105 uses 5v for the serial lines for the PicoW-TX->CN105-RX connection you should be able to wire it directly no need to step up the voltage as the output level is above the standard Vih 2v threshold, same with the 5V power and ground.

For the CN105-TX->PicoW-RX, you'll want something to step down the voltage from 5V to 3V a resistor divider, diode solution, level shifter or whatever. The PicoW inputs are not 5V tolerant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants