Hi Guys,
I am building a new DAC using the diyinhk ES9018k2m chip and am trying to control it with an Arduino using the hifiduino code from glt.
In general it works really well but I cannot get the IR remote to function properly.
I have everything wired up as in the attached pictures and have checked many times to make sure I have it correct.

I am able to get the remote to work once in about 200 key presses which is obviously no use to me, but it does work sometimes!
I have uncommented the IR debug lines and have been able to get one line of information from the serial monitor which shows that the codes are correct.

I have also uploaded a sketch IRrecvDump from the IRlib-master library. With exactly the same wiring and the sketch changed to listen for the remote on pin3 I get an instant code every time I press the apple remote. Although the codes look different it is just because they have the MSB and LSB reversed from the hifiduino convention. When you change the order the codes are exactly the same.

I have attached the ircode section of the hifiduino code as a text file.
View attachment ircode.txt
Does anyone have any idea on what could be causing the remote to behave so unreliably in the hifiduino code or what I could try to get it working properly?
Thanks
Duncan
****UPDATE:
After getting help from cookiemonster77 I have been able to make amendments to the code to get it working with my apple remote.
I have used the IRremote library to do the decoding and have integrated this into the existing structure so it works as intended.
I have used the full code that my remote outputs rather than just the third byte with LSB removed.
I would imagine that this will not work immediately with another apple remote due to the pairing numbers being different.
The IR codes can easily be read to the serial monitor by enabling the lines in the code and then changing the case statements to reflect the codes being used.
This would also allow RC5 or RC6 remotes to function with the hifiduino code as the IRremote can decode them too.
If anyone wants to use this version of the code you will need to download the IRremote library and install it.
I got it from here Arduino IRremote
Be aware that this conflicts with the Arduino Robot IR library so that will need to be removed otherwise you will get conflicts when compiling.
I have attached the new code in a zip file further down so anyone can have a look to see what was done.
I am building a new DAC using the diyinhk ES9018k2m chip and am trying to control it with an Arduino using the hifiduino code from glt.
In general it works really well but I cannot get the IR remote to function properly.
I have everything wired up as in the attached pictures and have checked many times to make sure I have it correct.


I am able to get the remote to work once in about 200 key presses which is obviously no use to me, but it does work sometimes!
I have uncommented the IR debug lines and have been able to get one line of information from the serial monitor which shows that the codes are correct.

I have also uploaded a sketch IRrecvDump from the IRlib-master library. With exactly the same wiring and the sketch changed to listen for the remote on pin3 I get an instant code every time I press the apple remote. Although the codes look different it is just because they have the MSB and LSB reversed from the hifiduino convention. When you change the order the codes are exactly the same.

I have attached the ircode section of the hifiduino code as a text file.
View attachment ircode.txt
Does anyone have any idea on what could be causing the remote to behave so unreliably in the hifiduino code or what I could try to get it working properly?
Thanks
Duncan
****UPDATE:
After getting help from cookiemonster77 I have been able to make amendments to the code to get it working with my apple remote.
I have used the IRremote library to do the decoding and have integrated this into the existing structure so it works as intended.
I have used the full code that my remote outputs rather than just the third byte with LSB removed.
I would imagine that this will not work immediately with another apple remote due to the pairing numbers being different.
The IR codes can easily be read to the serial monitor by enabling the lines in the code and then changing the case statements to reflect the codes being used.
This would also allow RC5 or RC6 remotes to function with the hifiduino code as the IRremote can decode them too.
If anyone wants to use this version of the code you will need to download the IRremote library and install it.
I got it from here Arduino IRremote
Be aware that this conflicts with the Arduino Robot IR library so that will need to be removed otherwise you will get conflicts when compiling.
I have attached the new code in a zip file further down so anyone can have a look to see what was done.
Last edited:
Duncan,
Looking at the code, it seems to be geared for one protocol. I think you should check which protocol that is at the hifiduino site and see if your remote is using the same one. Alternatively, you can try various remotes you might have and see if you get more consistent keypresses.
The apple remote is popular for these projects, so if you have one of those, it might be worth trying.
My guess is that either 1) you have to change your remote, or 2) you have to replace the hifiduino code with code specific to your remote, or 3) replace the entire IR section of the code with a standard arduino IR library that supports many protocols.
Looking at the code, it seems to be geared for one protocol. I think you should check which protocol that is at the hifiduino site and see if your remote is using the same one. Alternatively, you can try various remotes you might have and see if you get more consistent keypresses.
The apple remote is popular for these projects, so if you have one of those, it might be worth trying.
My guess is that either 1) you have to change your remote, or 2) you have to replace the hifiduino code with code specific to your remote, or 3) replace the entire IR section of the code with a standard arduino IR library that supports many protocols.
The hifiduino code is only for the apple remote which is what I am using, it does register a code from the apple remote and works but only once out of 200 key presses.
Maybe there is something in the code that is causing it to not work so well in my setup but I really don't know what that could be.
As the IRlib master library is working well with the apple remote and setup I have it may be better to incorporate that to do the receiving and decoding of the remote signals. Unfortunately I don't have the knowledge to do that yet but unless there are any other simpler suggestions that maybe my only option.
Thanks
Duncan
Maybe there is something in the code that is causing it to not work so well in my setup but I really don't know what that could be.
3) replace the entire IR section of the code with a standard arduino IR library that supports many protocols.
As the IRlib master library is working well with the apple remote and setup I have it may be better to incorporate that to do the receiving and decoding of the remote signals. Unfortunately I don't have the knowledge to do that yet but unless there are any other simpler suggestions that maybe my only option.
Thanks
Duncan
Hi Duncan,
You need to get a different generic IR library if you want to use it with your hifiduino code. Your rotary uses the interrupt-enabled pins, so you need to use a regular "polling" library for your IR. I have just included IRemote.h in my sketches, and it has worked nicely.
Here´s the code I have used with the IRemote library:
Looking at it now, I see I´m a bit inconsistent with the "else" statement (and proper programmers will probably not approve of the naming conventions etc). If you include the above, you should be able to map the infrared codes to the commands glt has built into his code. Remove or add lines as necessary.
You can "learn" the values from your remote by printing results.value to the serial monitor and pasting them into the code.
Test first the IRemote library to see if it works well with your remote before plugging into the hifiduino code.
You need to get a different generic IR library if you want to use it with your hifiduino code. Your rotary uses the interrupt-enabled pins, so you need to use a regular "polling" library for your IR. I have just included IRemote.h in my sketches, and it has worked nicely.
Here´s the code I have used with the IRemote library:
Code:
// in "global section"
#include <IRremote.h>
#define IR_PIN 7
IRrecv irrecv(IR_PIN);
int iNumberOfRepeatCodesReceived = 0;
long lLastCommand=0;
// in setup()
irrecv.enableIRIn();
// somewhere in loop()
if (irrecv.decode(&results))
{
long lThisCommand = results.value;
// Ensure repeated codes are treated correctly
if(lThisCommand == 4294967295) iNumberOfRepeatCodesReceived++;
else
{
iNumberOfRepeatCodesReceived = 0;
lLastCommand = lThisCommand;
}
if(iNumberOfRepeatCodesReceived != 1) // Skip the first repeat code
{
if(lThisCommand == 4294967295) lThisCommand = lLastCommand;
if(lThisCommand == 16687964 && bStandby==false) { changeVolume(3); }
else if(lThisCommand == 16698164 && bStandby==false) { changeVolume(-3); }
else if(lThisCommand == 16661444 && bStandby==false) { muteOnOff(); }
else if(lThisCommand == 16679804 && bStandby==false) { nextSource(); }
else if(lThisCommand == 16647164 && bStandby==false) { setSource(0); }
else if(lThisCommand == 16708364 && bStandby==false) { setSource(3); }
else if(lThisCommand == 16659404 && bStandby==false) { setSource(1); }
else if(lThisCommand == 16679804 && bStandby==false) { setSource(2); }
else if(lThisCommand == 16694084 && bStandby==false) { nextFilter(); }
else if(lThisCommand == 16710404) { standby(); }
}
irrecv.resume(); // Receive the next value
}
Looking at it now, I see I´m a bit inconsistent with the "else" statement (and proper programmers will probably not approve of the naming conventions etc). If you include the above, you should be able to map the infrared codes to the commands glt has built into his code. Remove or add lines as necessary.
You can "learn" the values from your remote by printing results.value to the serial monitor and pasting them into the code.
Test first the IRemote library to see if it works well with your remote before plugging into the hifiduino code.
Thanks for your help, I will give this a try, it may take me a while as I will have to do some more reading on arduino code to know how to add this into the existing hifiduino sketch.
Make a backup of your hifiduino sketch. Then comment out everything related to IR in that sketch. Compile and run. If you get errors during compilation, you have commented out too much or too little. The messages should help you identify the issue. Once your hifiduino sketch runs without IR, make a backup again, and add my code above in the three sections. It won't compile because the methods NextSource etc don't exist in your hifiduino code. So you need to change the names to the hifiduino methods or comment out those rows for now. Once that compiles, you can read the codes by printing them to the serial monitor. Add a println just after long lThisCommand... and print lThisCommand.
I can to modify the code for you, but can't promise an ETA, so if you are in a rush, just try out the above.
I have the same problem using ES9018. Also, when it is working (like you said once in 200 key presses) all the buttons do the same thing (turn volume down).
Martin that is very generous offer but I don't need you to do all the work for me 😉 or maybe I do judging by the rest of this post .....
I'll start with volume up and down which apart from a dim function is all that is there already.
With your change volume there is (3) and (-3) do these numbers refer to dB or something else?
I am thinking to take out && bStandby==false as I don't have any kind of standby function.
This is the part of the code that sets the volume from the remote
case 5 is volume up and case 6 volume down. 5 and 6 represent the decimal values of the the third byte in the remote code with the LSB removed. Your code looks to include the whole four bytes so these numbers will be quite different.
I am not sure how to replace the IRkey parts with your code, if you have any pointers for that it would be helpful.
If/when I get this working I will put the details here so others can amend the code if they have the same issues.
Thanks
Duncan
I'll start with volume up and down which apart from a dim function is all that is there already.
With your change volume there is (3) and (-3) do these numbers refer to dB or something else?
I am thinking to take out && bStandby==false as I don't have any kind of standby function.
This is the part of the code that sets the volume from the remote
Code:
while(digitalRead(REMOTEPIN)==LOW){
// Serial.println("hi");
if((IRkey=getIRkey())==255){
// Do nothing
}
else {
if(IRkey==0) { // Repeat code
if(previousIRkey==5||previousIRkey==6) { // Specify key=5 and key=6 as repeatable keys
// specify other keys here to make them repeatable
IRkey=previousIRkey; // Repeat code
}
else {
// Do nothing. No repeat for the rest of the keys
}
}
else { // Not a repeat code, it is a new command
previousIRkey=IRkey; // Remember the key in case we want to use the repeat code
}
}
switch(IRkey){
// case 0 and 255 are "valid" cases from the code, but we do nothing in this switch statement
case 5: // 5 is the up key, we will use for volume up
if (currAttnu>MINATTNU) // Check if not already at minimum attenuation
{
if(dimmed) {
rampUp(); // Disengage dim
dimmed=false;
}
currAttnu-=2; // Decrease attenuation 1 dB (increase volume 1 db)
setSabreVolume(currAttnu); // Write value into registers
printTwoNumber(13,currAttnu/2); // Divide by 2 to print in whole dBs
}
break;
case 6: // 6 is the down key, we will use for volume down
if (currAttnu<MAXATTNU) // Check if not already at maximum attenuation
{
if(dimmed) {
rampUp(); // Disengage dim
dimmed=false;
}
currAttnu+=2; // Increase 1 dB attenuation (decrease volume 1 db)
setSabreVolume(currAttnu); // Write value into registers
printTwoNumber(13,currAttnu/2); // Divide by 2 to print in whole dBs
}
break;
case 5 is volume up and case 6 volume down. 5 and 6 represent the decimal values of the the third byte in the remote code with the LSB removed. Your code looks to include the whole four bytes so these numbers will be quite different.
I am not sure how to replace the IRkey parts with your code, if you have any pointers for that it would be helpful.
If/when I get this working I will put the details here so others can amend the code if they have the same issues.
Thanks
Duncan
Fredrik Aandal at hifiduino also found a fix for the ES9018 b11f code.
He says the following:
''Found the bug in B11f!
Timing must be increased from 15k to 20k.
Insert this line:
while((duration=pulseIn(REMOTEPIN, HIGH, 20000)) < 2000 && duration!=0)''
He says the following:
''Found the bug in B11f!
Timing must be increased from 15k to 20k.
Insert this line:
while((duration=pulseIn(REMOTEPIN, HIGH, 20000)) < 2000 && duration!=0)''
Interesting information, my DAC is all boxed up and working now, but if I open it up or build another one I'll give it a try. Did it work for you?
- Status
- Not open for further replies.
- Home
- Source & Line
- Digital Line Level
- ES9018k2m Arduino IR remote issue