-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Atmega4809 board definitions #657
Conversation
That's great! I will test it asap. Which are the PINs for send/receive? |
for sending it should be the PWM pin D6 on the Arduino Nano Every. if you have a different board, you might need to look up where the chips pin PF4 is routed. for receiving just pick any analog pin yourself. looking forward to hearing from your test results. |
I have an |
boarddefs.h
Outdated
TCB0.CTRLA = (TCB_CLKSEL_CLKDIV1_gc) | (TCB_ENABLE_bm); \ | ||
}) | ||
|
||
#define TIMER_PWM_PIN 24 /* Uno Every */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment say Nano Every
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! I'll fix it.
also, I got the pin definition wrong. PWM Pin is actually D6 (the 24th pin on the board)
Unfortunately seems that I did not managed to make it work. Receiving is ok, but sending is not. I have tried with all PWM digital PINs on a WIFI Rev2 |
@eclipse1985 I found a mistake I made (thanks you both, you and @AnalysIR, for pointing me in the right direction! ). would you mind giving it another whirl? |
Unfortunately seems that is not working even with the updated version. This is the sketch I'm using, where rawData is a tested signal for shutdown my TV. Connected PIN is
|
It could be the signal you are using. (it looks problematic, in terms of timings) It appears as Samsung 32 bit Ir signal on AnalysIR. I have cleaned it up for you below. PS: Also increase the delay to 5 or 10 seconds. |
Sending does not work for me, too. I am testing this pull request using the following snippet and an IR-LED driven by a transistor connected to the The circuit works when using digitalWrite(..,HIGH): The IR-LED is visibly bright when viewed using a mobile camera, as long as the physical button is pushed, and the detector-LED lights up briefly when pushing/releasing the button. However using IRsend leaves the IR-LED dark when viewed using a camera and the detector-LED does not signal any activity while pushing/releasing the button. #include <Arduino.h>
#include "IRremote.h"
// changed C:\users\<USER>\.platformio\lib\IRremote_ID4\boarddefs.h
// according to https://github.com/z3t0/Arduino-IRremote/pull/657/files
#define PIN_DETECT 2
#define PIN_STATUS 13
IRsend irsend;
const bool WIRE_TEST = false; // true uses digitalWrite(..,HIGH) instead of irsend
void setup() {
delay(2000);
pinMode(PIN_DETECT, INPUT);
pinMode(PIN_STATUS, OUTPUT);
if(WIRE_TEST)
{ // test without irsend
pinMode(TIMER_PWM_PIN, OUTPUT);
digitalWrite(TIMER_PWM_PIN, PinStatus::HIGH);
}
else
{
irsend.enableIROut(38);
irsend.mark(0);
}
}
void loop() {
bool detected = !digitalRead(PIN_DETECT);
digitalWrite(PIN_STATUS, detected ? PinStatus::HIGH : PinStatus::LOW);
} |
thanks @Seelge for your analysis and the test code. First the bad news: my board is already built-in into one of my projects and I currently have no chance for doing further tests - so in that regard I fully depend on you/others. I tried to do my best on implementing the platform support based on the code I found in the file ~/.arduino15/packages/arduino/hardware/megaavr/1.8.5/variants/uno2018/variant.c upon looking into that file once again I saw another possibility for solving the sending issue... would you mind inserting the following code on line number 586 in boarddefs.h oh, and I guess there's one more detail. In "Tools -> Registers Emulation" I guess the value should be set to "None". Again, I'm not sure of the implications if it's not ;) |
Thank you for the suggestion, I tried it but the additional line / no register emulation does not seem to have an effect. |
it seems as if there is something wrong with my timer_enable_pwm and timer_disable_pwm macros. After crawling through atmel documentation sheets again, I think I might have found another possible solution. the lines 580 and 581 might have to look like this:
thanks too for your help! if it works, I'll commit and append it to the pull request. oh, and would you mind testing a 2nd version of those new definitions?
|
Progress! With the new TIMER..PWM, the IR-LED lights up and the receiver signals on the transition space->mark. There does not seem to be a functional difference between the two definitions but that may be a limitation of my code snippet. I compared the behavior to the mega2560 with the same code and there is a different behavior: As long as a mark is sent, the reciever is getting a signal, not only on the change space->mark. Edit: Just to clarify, with the nano every the receiver only signals on the change space->mark, but the IR LED lights up for as long as the mark is sent. It seems the pin is triggered on but perhaps not with the correct frequency. My receiver is a TSOP4838. |
good to hear about the progress! regarding the two versions of the macros... technically they are supposed to do the same job; I just wasn't sure if the shorter version suffices. I don't fully understand your observations. could you elaborate and maybe add a code snippet? is the receiver on the same board? |
@mklemenz Sending with a simple void loop() {
irsend.sendNEC(0xF700FF, 32);
delay(2000);
} and receiving with the library example IRrecvDumpV2 works. Tested with the nano every sending and the mega receiving and vice versa. |
@Seelge : you're AWESOME! to be honest, now I'm a bit surprised! a few lines further down (within the same macro) I intentionally set a clock divider to be 2 (TCB_CLKSEL_CLKDIV2_gc)... hence the '/2' in the calculation. The reason was that the atmega4809 can be clocked up to 20MHz. Considering that the comparator-registers CCMPL and CCMPH each are 8 bits wide and no divider is set, this would not work with 38kHz sending frequency. eg: 20000000/2000/38 equals 263.xxx, which exceeds the 8 Bits. The thing that puzzles me most is that the divider doesn't seem to be working anyway. |
Okay, I did some more extensive testing with the following sequence. void loop()
{
irsend.sendNEC(0x00000001, 32); delay(250);
irsend.sendNEC(0x00000010, 32); delay(250);
irsend.sendNEC(0x00000100, 32); delay(250);
irsend.sendNEC(0x00001000, 32); delay(250);
irsend.sendNEC(0x00010000, 32); delay(250);
irsend.sendNEC(0x00100000, 32); delay(250);
irsend.sendNEC(0x01000000, 32); delay(250);
irsend.sendNEC(0x10000000, 32); delay(250);
delay(5000);
} Test A Sending with the nano every the mega2560 understood but with a high error rate of around 25%, random readings didn't get correctly classified and ended up as other encodings or unknown with bad codes. Test B Vice versa with the mega2560 sending and the nano every receiving there were no bad readings. Test C With Then I changed everything back to Test A, nano every sending with |
Is this change working? I would love to try it out. |
Yes, it worked for me in January with the simple examples above but there might be some unresolved issues. I do not know if a ~5% error rate is typical. I modified the initial pull request according to the descriptions in this thread but I have not checked whether they are included by now. |
If it interests anyone, I have implemented Atmega4809 support (sending and receiving) in version 1.1.0 of Infrared4Arduino, based on this PR. Available in the Arduino library manager in a few hours ("Infrared"). |
This thread has been gold for me, thank you so much @mklemenz and @Seelge for your back and forth messaging. I took the second option from #657 (comment)
Then the prompt to use TCB_CLKSEL_CLKDIV2_gc instead of TCB_CLKSEL_CLKDIV1_gc from #657 (comment) worked and changed that in line 853: Now my Nano Every is able to communicate with my video projector (NEC protocol). Thank you! |
Just one question. |
No, I had to change it to the above to get my videoprojector to respond to the commands. Using a Nano Every. |
@bombarie Can you do me a favor and test the current version 2.6.0. I included your suggested changes, but I have no board to test it. |
@ArminJo All good save for one typo on line 830 of IRremoteBoardDefs.h |
Thanks a lot for QA 👍 Its corrected now in the repo. |
Yes I positively tested it on my Arduino Nano Every. With the bitwise OR |
This patch should work for the new boards "Nano Every" and "UNO WiFi Rev2" from Arduino.
I have tested receiving IR signals and it works. But since I currently don't have IR emitters/diodes at hand, consider the code necessary for sending signals as experimental.
It fixes the compiler errors mentioned in the issues #639 and #641 as well.