Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samm-git
Last active March 16, 2024 19:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samm-git/a76058a03fe28aa2f5407f6826c93b6a to your computer and use it in GitHub Desktop.
Save samm-git/a76058a03fe28aa2f5407f6826c93b6a to your computer and use it in GitHub Desktop.
// marantz wired remote control demo
// inspired by https://github.com/Arduino-IRremote/Arduino-IRremote
// see https://smallhacks.wordpress.com/2021/07/07/controlling-marantz-amplifier-using-arduino-via-remote-socket/
/* some definitions from the IRremote Arduino Library */
#define RC5_ADDRESS_BITS 5
#define RC5_COMMAND_BITS 6
#define RC5_EXT_BITS 6
#define RC5_COMMAND_FIELD_BIT 1
#define RC5_TOGGLE_BIT 1
#define RC5_BITS (RC5_COMMAND_FIELD_BIT + RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS) // 13
#define RC5X_BITS (RC5_BITS + RC5_EXT_BITS) // 19
#define RC5_UNIT 889 // (32 cycles of 36 kHz)
#define RC5_DURATION (15L * RC5_UNIT) // 13335
#define RC5_REPEAT_PERIOD (128L *RC5_UNIT) // 113792
#define RC5_REPEAT_SPACE (RC5_REPEAT_PERIOD - RC5_DURATION) // 100 ms
#define IR_TX_PIN 5 // pin to use for tx
//#define TRACE // print binary commands to serial
uint8_t sLastSendToggleValue = 0;
/*
* normal Philips RC-5 as in the https://en.wikipedia.org/wiki/RC-5
* code taken from IRremote with some changes
*/
int sendRC5(uint8_t aAddress, uint8_t aCommand, uint_fast8_t aNumberOfRepeats)
{
digitalWrite(IR_TX_PIN, LOW);
uint16_t tIRData = ((aAddress & 0x1F) << RC5_COMMAND_BITS);
if (aCommand < 0x40)
{
// set field bit to lower field / set inverted upper command bit
tIRData |= 1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS);
}
else
{
// let field bit zero
aCommand &= 0x3F;
}
tIRData |= aCommand;
tIRData |= 1 << RC5_BITS;
if (sLastSendToggleValue == 0)
{
sLastSendToggleValue = 1;
// set toggled bit
tIRData |= 1 << (RC5_ADDRESS_BITS + RC5_COMMAND_BITS);
}
else
{
sLastSendToggleValue = 0;
}
uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
while (tNumberOfCommands > 0)
{
for (int i = 13; 0 <= i; i--)
{
#ifdef TRACE
Serial.print((tIRData &(1 << i)) ? '1' : '0');
#endif
(tIRData &(1 << i)) ? send_1() : send_0();
}
tNumberOfCommands--;
if (tNumberOfCommands > 0)
{
// send repeated command in a fixed raster
delay(RC5_REPEAT_SPACE / 1000);
}
#ifdef TRACE
Serial.print("\n");
#endif
}
digitalWrite(IR_TX_PIN, LOW);
return 0;
}
/*
* Marantz 20 bit RC5 extension, see
* http://lirc.10951.n7.nabble.com/Marantz-RC5-22-bits-Extend-Data-Word-possible-with-lircd-conf-semantic-td9784.html
* could be combined with sendRC5, but ATM split to simplify debugging
*/
int sendRC5_X(uint8_t aAddress, uint8_t aCommand, uint8_t aExt, uint_fast8_t aNumberOfRepeats)
{
uint32_t tIRData = (uint32_t)(aAddress & 0x1F) << (RC5_COMMAND_BITS + RC5_EXT_BITS);
digitalWrite(IR_TX_PIN, LOW);
if (aCommand < 0x40)
{
// set field bit to lower field / set inverted upper command bit
tIRData |= (uint32_t) 1 << (RC5_TOGGLE_BIT + RC5_ADDRESS_BITS + RC5_COMMAND_BITS + RC5_EXT_BITS);
}
else
{
// let field bit zero
aCommand &= 0x3F;
}
tIRData |= (uint32_t)(aExt & 0x3F);
tIRData |= (uint32_t) aCommand << RC5_EXT_BITS;
tIRData |= (uint32_t) 1 << RC5X_BITS;
if (sLastSendToggleValue == 0)
{
sLastSendToggleValue = 1;
// set toggled bit
tIRData |= (uint32_t) 1 << (RC5_ADDRESS_BITS + RC5_COMMAND_BITS + RC5_EXT_BITS);
}
else
{
sLastSendToggleValue = 0;
}
uint_fast8_t tNumberOfCommands = aNumberOfRepeats + 1;
while (tNumberOfCommands > 0)
{
for (int i = 19; 0 <= i; i--)
{
#ifdef TRACE
Serial.print((tIRData &((uint32_t) 1 << i)) ? '1' : '0');
#endif
(tIRData &((uint32_t) 1 << i)) ? send_1() : send_0();
if (i == 12)
{
#ifdef TRACE
Serial.print("<p>");
#endif
// space marker for marantz rc5 extension
delayMicroseconds(RC5_UNIT *2 *2);
}
}
#ifdef TRACE
Serial.print("\n");
#endif
tNumberOfCommands--;
if (tNumberOfCommands > 0)
{
// send repeated command in a fixed raster
delay(RC5_REPEAT_SPACE / 1000);
}
}
digitalWrite(IR_TX_PIN, LOW);
return 0;
}
void setup()
{
//start serial connection
Serial.begin(115200);
// configure output pin
pinMode(IR_TX_PIN, OUTPUT);
}
void send_0()
{
digitalWrite(IR_TX_PIN, HIGH);
delayMicroseconds(RC5_UNIT);
digitalWrite(IR_TX_PIN, LOW);
delayMicroseconds(RC5_UNIT);
}
void send_1()
{
digitalWrite(IR_TX_PIN, LOW);
delayMicroseconds(RC5_UNIT);
digitalWrite(IR_TX_PIN, HIGH);
delayMicroseconds(RC5_UNIT);
}
void loop()
{
// demo to switch outputs and turn device on/off
sendRC5(21, 63, 1); // phono
delay(500);
sendRC5(20, 63, 1); // cd
delay(500);
sendRC5(17, 63, 1); // tuner
delay(500);
sendRC5_X(16, 0, 6, 1); // aux1
delay(500);
sendRC5_X(16, 0, 7, 1); // aux2
delay(500);
sendRC5(16, 12, 1); // standby
delay(2000);
}
@anker2000
Copy link

I don't suppose you'd know how to find the RC5 values for the "Optical 1" input on the PM6007 amp? I've been searching like crazy and had zero luck.

@samm-git
Copy link
Author

samm-git commented Feb 5, 2023

@anker2000 I was using a logic analyzer with my own rc5 decoder. I never completed it to the stage where it's fine to upstream it.

Also you can just try to write program to check all the codes, i don't think it could harm.

@Johanvanderveen
Copy link

Hi,
I am having issues with sending the codes for commands without an extension.
Thanks, at least this program did turn off my ampl. and was able to mute and unmute. Other commands failed.
I am having issues with sending the codes for commands without an extension. The power-on does not work in for my SR5004 amplifiers.
Also tried codes for Direct Volume, without succes. I hope you have a fix for this maybe.

@dubosc2
Copy link

dubosc2 commented Mar 16, 2024

Hi, I am having issues with sending the codes for commands without an extension. Thanks, at least this program did turn off my ampl. and was able to mute and unmute. Other commands failed. I am having issues with sending the codes for commands without an extension. The power-on does not work in for my SR5004 amplifiers. Also tried codes for Direct Volume, without succes. I hope you have a fix for this maybe.

Hi, for tuning on, did you try using all three different power signals? And did you disable the remote control signal receiving function on your amp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment