lucsmall / BetterWH2

An improved Arduino sketch for decoding packets from the WH2 outdoor temperature and humidity sensor from Fine Offset Electronics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arduino mega

Maraecek opened this issue · comments

Hi
The Arduino uno works well.
why not funkcion arduino mega 2560?

My code is manually configuring TIMER1 and is also using its interrupt handler. The registers and interrupt handler names tend to vary between AVR models. So I suspect the ATMEGA2560 has a slightly different way of configuring the registers and/or the interrupt. Unfortunately I don't have an ATMEGA2560 on hand to test it out on.

I'm also reading AVR pins directly for improved performance. On the Mega PIND2 on the AVR may not map to Arduino digital pin 2, so that could also be the issue.

Are you getting errors when compiling the code? If so, can you paste an error log?

There is no problem compiling.
No error.
ATMEGA328 (uno) and ATmega 2560 (mega) have the same registers TCCRe and TIMSK.
This works
https://github.com/lucsmall/WH2-Weather-Sensor-Library-for-Arduino

I have tried BetterWH2 on original uno, chinese mega (both ordinary and ch340 version) and russian leonardo clone and there was no problem. But you need external power 7 volts or above. When you use power from usb only one type of receiver works - SRX882 Superheterodyne receiver. With external power all cheaper rx works well.
Now I have working prototype with mega clone, SRX882 and power from pc usb and there is no issues with better wh2.

Looking at https://www.arduino.cc/en/Hacking/PinMapping2560 it seems arduino digital pin 2 maps to AVR port PE4 on the mega.

So I suggest trying to change lines 15 and 16 to:

#define RF_IN_RAW PINE4
#define RF_IN_PIN PINE

And seeing if that fixes the issue.

I changed
#define RF_IN_RAW PINE4
#define RF_IN_PIN PINE
It works, thank