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

Code adaptation for ESP32 ? #1

Closed
paulgreg opened this issue Jul 13, 2022 · 20 comments · Fixed by #2
Closed

Code adaptation for ESP32 ? #1

paulgreg opened this issue Jul 13, 2022 · 20 comments · Fixed by #2

Comments

@paulgreg
Copy link

Hello,

Thanks a lot for your library which works great with an Arduino Uno.

I would like to use it on an Espressif ESP32 to integrate it on my weather station.
I’ve tried to adapt your library but without success for now...

While debugging, it seems I am never entering isPulseInRange since _tPinHigh is around ~450 or ~2250 but never into the correct range of 5100 ~ 5900. It works on Arduino so the problem isn’t from my thermometer.

By any chance, do you have any idea what can be pose problem to ESP32 port or what to look for ?

Best regards
Grégory

@Erriez
Copy link
Owner

Erriez commented Jul 13, 2022

Hi @paulgreg,

Thanks for your feedback. Good to hear that you have it up and running with an Arduino Uno. That's what I also used for testing transmit and receive.

I did not test with an ESP32, so I looked at my code with dry-reading. I found one potential issue in the receive:

An additional IRAM_ATTR is needed for ESP32 pin interrupt functions. Can you change the following line in

void rfPinChange(void)
to:

void IRAM_ATTR rfPinChange(void)

@paulgreg
Copy link
Author

Thanks @Erriez for your answer and the the IRAM_ATTR piece of advice.

I’ve change it with a few minor adjustments in commit paulgreg@1dac24f.

However, I’m still not getting values. Your receive example sketch is only displaying « Oregon THN128 433MHz temperature receive » on my esp32.

I’ve seen a potential issue with micros on esp32 here and tried to replace it with esp_timer_get_time on paulgreg@7792a3c but it didn’t changed anything.

By the way, I’ve tried a few GPIO but I’m currently using GPIO 4 on the esp32. Also, I’ve connected my RF Module to the 5V output on my esp32. Connecting to 3V3 didn’t entered into rfPinChange. I’ve read that the ESP32 is 5V tolerant on input.

@paulgreg
Copy link
Author

Errata : it works ! 🎉
I tried again this morning and it’s displaying temperatures now like : « RX 14: Rol: 3, Channel 1, Temp: 26.6, Low batt: 0 (0x9302662b) »

I’ve merged my branch using esp_timer_get_time into master since it works with that.

Thanks again for your very nice library and help !

I can now adapt my esp32 weather station to display outside temperature.

@paulgreg
Copy link
Author

paulgreg commented Jul 14, 2022

The range is however very limited (a few centimeters) but that’s not a software issue but rather an hardware one :-)
I’ll try to work on an antenna.

@Erriez
Copy link
Owner

Erriez commented Jul 14, 2022

Hi @paulgreg, That's good news about your progress. RF is sometimes magic.

My suggestion is to start with an Uno board to determine the physical range of the RF receiver hardware. Some RF receivers simply have a short range. (and I've wasted a lot of time) The Uno has a stable 5V power source and less RF interference compared with the ESP32.

I’ve read that the ESP32 is 5V tolerant on input.

This is a gray area as the chip is 3.3V. It may work, but a level converter (or resistor network) is recommended.

I use STX882 transmitters and SRX882S receivers with corresponding external antenna and have a good range (depends on the environment). They work between 3.3V and 5V. I also suggest to add a capacitor on the power and experiment with placing the receiver away from the CPU. Also the enclosure has influence on the range. Just some hints.

Did you notice a difference between micros() and esp_timer_get_time()? I'm happy to add ESP32 support to my library when you think it is stable.

@paulgreg
Copy link
Author

Thanks for the hints. Indeed, it seems more stable with the Arduino Uno.
I will try to add a capacitor on the power. I may also try that kind of antenna instead of an helical copper one.

I tried again this morning using 3.3V and it works when the thermometer is near ! I may have tried when the thermometer was too far and thought that it didn’t work with 3.3V.

I’ve ordered 2 more receivers, including a SRX882 (but it will take a few weeks to arrive) to try with them.

I’ve also tried this morning with micros() and it is working (again, when the thermometer is near). So esp_timer_get_time() didn’t seems useful. I‘ll revert that commit and my master branch.

Thanks again for the help. I will post here progress but it may take weeks (or months) until I’ve got new hardware parts :/

@Erriez
Copy link
Owner

Erriez commented Jul 15, 2022

I will post here progress but it may take weeks (or months) until I’ve got new hardware parts :/

That would be great. You're working on an interesting project. :-)

@paulgreg
Copy link
Author

paulgreg commented Aug 9, 2022

Hello,

Using a « RF module 433Mhz superheterodyne receiver », I was able to get data from the sensor from a longer range (about ~8 meters) on an arduino, an ESP32 (using 3.3V) and an ESP8266 (using 3.3V). It’s too short however in my flat to use it on my weather station.

So I build a kind of relay, based on an esp8266, that I placed in sensor’s range. It gets temperature, displays it on an OLED display and post data as JSON to a custom server (using json-store, a simple server to save and get JSON).
I’ve made an hackaday page about that « relay ». (I’m still struggling with ESP.deepSleep but that’s another story).

My weather station then fetches that local temperature, after getting weather data from openweathermap.org.

I’m really grateful of your wonderful work about that library which made that possible.

I’ve only had to make a few changes to make it work on an ESP32 or ESP8266. So I think it should be possible to make an universal library. Here’s my changes, mainly due to renaming, to be able to use both library : master...paulgreg:ErriezOregonTHN128-esp32:master

@Erriez
Copy link
Owner

Erriez commented Aug 10, 2022

Hi @paulgreg,

Thanks for your update. ~8 meters is better than you started, but it is still a short range. I did not expect a similar range with different types of microcontrollers.

I’m still struggling with ESP.deepSleep but that’s another story

I'm curious, do you have a deepSleep problem on an ESP8266 or ESP32? I also spent a lot of time of research on ESP8266 as there are multiple causes for this.

Great project on Hackaday. 👍

I'll check your changes and will try to add it to this library. (This will take some time as I need to setup the hardware first)

Thanks for your contribution.

@paulgreg
Copy link
Author

About the range, there’s some walls between the sensor and the receiver and I live in a flat in a big city with, I think, many other sources of radio emission. So maybe that could be the cause ?

The deepSleep problem is on the esp8266. I’m using sleep on multiple esp32 without issues. So I don’t know why it doesn’t works... Sometimes, it sleeps correctly the first time but not after 🤯

@Erriez
Copy link
Owner

Erriez commented Aug 11, 2022

About the range, there’s some walls between the sensor and the receiver and I live in a flat in a big city with, I think, many other sources of radio emission. So maybe that could be the cause ?

Yes, walls and other equipment drops the range. Around 50m is feasible in open field with these transmit/receivers with antenna.

The deepSleep problem is on the esp8266. I’m using sleep on multiple esp32 without issues.

One open and long thread which maybe related to your issue: esp8266/Arduino#6007.

In my case I had bad luck with a counterfeit flash chip mounted on the ESP8266 PCB and it was not possible to fix by software. You can try some resistor tricks on the reset pin (don't have a link). Or maybe testing an ESP8266 from another batch and supplier which wakes correctly? Yes, the ESP32 works without issues, but requires a hardware redesign and porting the application (which is not 100% compatible with deepsleep).

@paulgreg
Copy link
Author

Thanks you for those tips. I’ll try to add a 220 resistor between MISO (d06) and 3.3V pin which seems to work for many people... 🤞

@Erriez
Copy link
Owner

Erriez commented Aug 13, 2022

@paulgreg I've created a new branch https://github.com/Erriez/ErriezOregonTHN128/tree/add-esp-support with AVR, ESP8266 and ESP32 support based on your reported changes. I did not test on hardware yet, because I encounter a platformio ci build problem reported in issue platformio/platformio-core#4393 to use build macro's in an Arduino sketch. As workaround I've copied the AVR examples to a new examples/ESP/ directory which is not my favorite. Building the examples works in the Arduino IDE.

@Erriez
Copy link
Owner

Erriez commented Aug 15, 2022

The previous reported issue has been resolved by adding build argument to command platform ci -O "lib_ldf_mode=chain+".

A new issue is introduced when calling a weak function from a C-Library on ESP32 espressif/arduino-esp32#7133.

Stay tuned.

@paulgreg
Copy link
Author

For your information, I wasn’t able to fix my sleep problem on my esp8266. However, I tried again to connect it directly on my weather station (based on esp32) and it worked when I put the receiver/antenna a little away the esp32... Strange but since that worked, it’s perfect for my case. I was able to get local temperature and display it on that weather station. I’ve updated my project page and code.

I would be happy to update my code to use and test your library when it’s available.

@Erriez
Copy link
Owner

Erriez commented Aug 19, 2022

I recognizable the behavior you describe.

Another suggestion for the wake problem (all magic, but fixed for two of my devices):
Erriez/ErriezArduinoExamples@486c9b9
The original posts on this issue are removed unfortunately.

I would be happy to update my code to use and test your library when it’s available.

Thanks! One remaining issue is the weak function callback from the C-library on ESP32. I did not see a reply yet.

@Erriez Erriez mentioned this issue Aug 19, 2022
@Erriez
Copy link
Owner

Erriez commented Aug 19, 2022

Finally I've added ESP8266 and ESP32 support in branch add-esp-support and tested all examples in combinations.

Note: I think I'll squash commits Add ESP8266 and ESP32 support and Fix ESP8266 and ESP32 support before merging to master as the first one was WIP.

Would it be possible for you to test it with your hardware and provide feedback? Then I'll merge MR #2. Thanks!

@paulgreg
Copy link
Author

I’ve just updated my 2 projects (one using an esp32, the other an esp8266) using your branch.

They both compiled perfectly and worked as before ! 🎉 So I think your branch is ready !

Thanks for the amazing work ! 🙏

@Erriez
Copy link
Owner

Erriez commented Aug 21, 2022

Thanks for testing and positive feedback! In the mean time I'm adding CI via Github Actions and automatically updating the documentation. I'll create a release soon and let you know.

@Erriez
Copy link
Owner

Erriez commented Aug 21, 2022

I've released v1.1.0! Thanks for your support! It was great to collaborate with you. 👍

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

Successfully merging a pull request may close this issue.

2 participants