MHI-AC-Ctrl-ESPHome icon indicating copy to clipboard operation
MHI-AC-Ctrl-ESPHome copied to clipboard

ESP32 - D1 Mini Pro

Open sanderlv opened this issue 1 year ago • 25 comments

Hi, I have tried to use a D1 Mini Pro ESP32 instead of an ESP8266. But to no avail, it just wont boot.

I want to use the advantage of also using the new bluetooth proxy component in the ESP32.

Is there any hard coding towards ESP8266?

Is it possible to use an ESP32?

board type: wemos_d1_mini32

sanderlv avatar Oct 27 '22 18:10 sanderlv

Some more info:

The ESP8266 (working): image

The ESP32 (not working): image

20221027_210715 20221027_210726

sanderlv avatar Oct 27 '22 19:10 sanderlv

First thing that comes to mind is that you should check the pins. The pin layout is different, and you may need to change some around in the core library's h and/or c files. Also, I think you can remove the CPU frequency option as it may be invalid for ESP32.

arpiecodes avatar Oct 28 '22 13:10 arpiecodes

I think, that the pin layout is pretty equal. The other tip I will try somewhere next weeks.

And about the other, I hope someone can confirm/deny that some programmatic changes are needed (not yaml, but the others: core library's h and/or c files).

sanderlv avatar Oct 28 '22 13:10 sanderlv

If you can't even get it to boot/join your WiFi, something is probably trying to do something that is not possible or causes an error on the ESP32. You might be able to hook-up the ESP32 to the serial monitor built-into the Arduino desktop app to debug a bit what error is triggered.

arpiecodes avatar Oct 28 '22 13:10 arpiecodes

PS: Pins are definitely different. Please see https://github.com/ginkage/MHI-AC-Ctrl-ESPHome/blob/master/MHI-AC-Ctrl-core.h#L33. They determine which pins to use for SPI communication. The ESP32 does not have specific purpose default pins (like the 8266 has) for SPI, you will have to tell it what to do on each pin.

If we look at the pinout for the one you have there, the edits should be something like this inside MHI-AC-Ctrl-core.h to get the SPI working;

#define SCK_PIN  18
#define MOSI_PIN 23
#define MISO_PIN 19

Also, connect the ESP32 based variant entirely at your own risk. ;-) No guarantees given.

EDIT: Updated pins. Was looking wrong as ESP32 has two rows of pins. Please see below image for pinout reference used.

image

Note that it is not possible to mix both ESP8266 and ESP32 devices if you edit the core library pins. They are not pin-compatible. We may need to open a feature request to be able to set the pinout from library/core initialisation. Or simply copy the library files and include the correct variants into your projects.

arpiecodes avatar Oct 28 '22 13:10 arpiecodes

I think from now on ESP32 is the only viable option and most future proof. Lower power and better wifi and BLE.

I really would appreciate support for this 😀

sanderlv avatar Oct 28 '22 16:10 sanderlv

If you can test it out with above pinout and it works, the maintainer of the library could consider the possibility of setting the pins in such a way that it remains drop-in compatible with this project.

arpiecodes avatar Oct 30 '22 11:10 arpiecodes

Have you tested it out yet with above config? I also got intrigued by the possibilities of using an ESP32 instead of an 8266 and eventually extending the module in the AC with (for example) a PM2.5/PM10 sensor. So I've also ordered some ESP32 Mini's now.

arpiecodes avatar Nov 08 '22 20:11 arpiecodes

Hi, no not yet and no active plans. Since I discovered shelly plus which have esp32 and I can flash with esphome I do not really need them yet...

sanderlv avatar Nov 08 '22 20:11 sanderlv

Can you please elaborate on "how to submit" a feature request? Still would like to have ESP32's in my aircos...

sanderlv avatar Nov 19 '22 20:11 sanderlv

Little update for everybody else who might want to try to use an ESP32 D1 Mini. I got it running by changing the pin definitions in MHI-AC-Ctrl-core.h as pointed out by @synegic.

#define SCK_PIN  18
#define MOSI_PIN 23
#define MISO_PIN 19

My config in ESPHome looks like this:

esphome:
  name: some-name
  platform: ESP32
  board: esp32dev
  platformio_options:
    # Run CPU at 160Mhz to fix mhi_ac_ctrl_core.loop error: -2
    board_build.f_cpu: 160000000L
  includes:
    - mhi_ac_ctrl.h
    - MHI-AC-Ctrl-core.h
    - MHI-AC-Ctrl-core.cpp

Everything else is unchanged.

When the ESP32 is only connected via USB to my PC I get the same error as in #29. But as soon as I plug it into my indoor unit I can control my air conditioner via ESPHome/Home Assistant.

Hope this helps.

ElBarto333 avatar Jan 13 '23 17:01 ElBarto333

Hi all, I also like to help with this (as I would really like to use WPA3 WiFi features only available on ESP32), but to enlarge the success factor, I am wondering where you guys but your ESP32 boards, and what version? I am thinking on buying 5 pieces at once (to have some spare and for fiddling around).

I only have 2 TTGO devices left, which do not suffice for the MHI interface.

Any tips for decent price versus normal shipping times in Europe are greatly appreciated. I did find for example: amazon

I just want to buy the proper board so I can focus on the MHI side of things.

acfnews avatar Jan 15 '23 09:01 acfnews

Last time I bought an ESP it was from TinyTronics. I bought this one: https://www.tinytronics.nl/shop/nl/development-boards/microcontroller-boards/met-wi-fi/wemos-c3-mini-esp32-c3

Mind you this is not a D1 but C3 variant with the RiscV processor architecture and I'm not sure if it does WPA3. They have other variants too.

I also order from HobbyElectronica: https://www.hobbyelectronica.nl/product-categorie/wemos/boards-wemos/

I don't know too much about the success factor thought. I think the D1 mini V3 is pretty okay but heard people who order from sketchy sources getting bad clones with mixed results.

ervee avatar Jan 15 '23 09:01 ervee

I've got an Ai-Thinker ESP-C3-32S-Kit board. I'm rewriting the code to use hardware SPI on the IDF platform, which works fine :). So harware-wise that's possible

hberntsen avatar Jan 16 '23 08:01 hberntsen

That's nice! I also got an ESP32 C3 13U 2MB board a while ago . It was cheap but it does not have a wifi antenna on the board (you need an antenna with a wire) so keep that in mind. Also the small flash size is a pain but I got my project running on it with OTA capability but I'm pretty sure the MHI project is way too big for this board so...

ervee avatar Jan 16 '23 09:01 ervee

I've got an Ai-Thinker ESP-C3-32S-Kit board. I'm rewriting the code to use hardware SPI on the IDF platform, which works fine :). So harware-wise that's possible

Did you had any success with this? Are still using esphome with this modified code?

glsf91 avatar Feb 07 '23 11:02 glsf91

Yes, I've got two running in my home right now, works great. I'm not on full feature parity with this repo yet but works fine so far. I'm looking at the developments in https://github.com/absalom-muc/MHI-AC-Ctrl/issues/77 to implement those as well.

@glsf91 are you interested? My code needs some cleaning but I can upload whatever I already have if that helps

hberntsen avatar Feb 07 '23 12:02 hberntsen

@hberntsen Yes, I'm interested. If you can upload your code somewhere (github?) that would be nice. I already used an esp32 with MHI-AC-Ctrl code (not esphome) but experience too much mhi_ac_ctrl_core.loop errors. I managed to make a better but I'm not satisfied yet. Have also to take a look again. So I was interested if IDF and hw SPI was doing a lot better.

glsf91 avatar Feb 07 '23 12:02 glsf91

I'm also tracking Bluetooth advertisements on both ESPs (for temperature), the one with 8 temperature sensors attached to it sometimes generates frame errors: screenshot-2023-02-07-134558

The other one with just one sensor a lot less (0 since last boot). I did not investigate the cause of them. Given that we receive a new frame every 40ms the error rate is quite low :). I'm planning to report the Bluetooth temperature to the AC as reference temp.

The trick with Hardware SPI on my ESP32-C3 was to generate a CS signal on the ESP itself, and loop it back to the hardware SPI CS pin. Otherwise It would never receive a frame. The ESP docs say that it should be able to operate without CS signal but I could not get that to work at all.

I've dumped my code at https://github.com/hberntsen/mhi-ac-ctrl-esp32-c3 :)

hberntsen avatar Feb 07 '23 14:02 hberntsen

A lot of work to change this. I'm not familiar with IDF, so takes some time to try to understand your code. I also want tracking Bluetooth advertisements.

The trick with Hardware SPI on my ESP32-C3 was to generate a CS signal on the ESP itself, and loop it back to the hardware SPI CS pin. Otherwise It would never receive a frame. The ESP docs say that it should be able to operate without CS signal but I could not get that to work at all.

Strange that the other project you referring to (homekit) is not using a CS.

glsf91 avatar Feb 07 '23 16:02 glsf91

Strange that the other project you referring to (homekit) is not using a CS.

Indeed, though that project is targeting the ESP32, not the C3 variant.

hberntsen avatar Feb 08 '23 04:02 hberntsen

I have an ESP32 (D1 mini ESP32 clone). So this means it maybe could work without CS and therefore I can use the mhi-ac-ctrl PCB. I will give it a try later. First trying some other stuff.

glsf91 avatar Feb 08 '23 06:02 glsf91

@ElBarto333

Little update for everybody else who might want to try to use an ESP32 D1 Mini.

Can anyone comment on the long term stability, I am considering using a ESP32 as it's a lot better option in most contexts in 2023.

Did you encounter any issues? Apart from setting the pin definitions and CPU frequency, did everything else simply 'work'?

HarrisonPace avatar Aug 20 '23 10:08 HarrisonPace

@thehaxxa

Can anyone comment on the long term stability, I am considering using a ESP32 as it's a lot better option in most contexts in 2023.

I have ESP32s and and 8266 running in my units. None of them had any issues until now.

ElBarto333 avatar Aug 20 '23 12:08 ElBarto333