Please post the sketch.
I thought it was working, but you didn't seem to need what fixed it just now.
a7
Please post the sketch.
I thought it was working, but you didn't seem to need what fixed it just now.
a7
Quite. But your posted code syntax wasn't from 4.x.x version.
Hmmm will investigate after dinner. Maybe something is amiss with my IDE setup.
Here you go, could do with a tidy up at the end to put it to sleep:
#include <IRremote.h> // Standard IR library for Arduino
// Define RC5 codes (address and command)
#define RC5_ADDRESS 0x10
#define RC5_POWER_ON 0x7B
#define RC5_SELECT_AV 0x5E
#define RC5_STANDBY 0x7C
// Define pin mapping
const int IR_SEND_PIN = 3; // Digital pin 3 for IR LED
// For older versions of IRremote library
IRsend irsend(IR_SEND_PIN); // Explicitly specify the pin in older versions
void setup() {
Serial.begin(9600);
Serial.println("IR Remote Control - Testing Output");
pinMode(IR_SEND_PIN, OUTPUT); // Explicitly set the pin mode
Serial.println("IR sender initialized on pin " + String(IR_SEND_PIN));
}
void sendRC5(uint8_t address, uint8_t command) {
Serial.println("Sending RC5 - Address: " + String(address, HEX) + ", Command: " + String(command, HEX));
for (int i = 0; i < 3; i++) { // Send multiple times to increase chance of reception
irsend.sendRC5(address, command, 0);
delay(100);
}
Serial.println("Command sent");
}
void loop() {
// Start first RC5 transmission (Power On)
Serial.println("Sending Power On command");
sendRC5(RC5_ADDRESS, RC5_POWER_ON);
delay(6000); // Wait 6 seconds
// Start second RC5 transmission (Select AV input)
Serial.println("Sending Select AV command");
sendRC5(RC5_ADDRESS, RC5_SELECT_AV);
while (1); // processor spins here until power off or reset
// Wait before repeating the sequence
delay(10000);
}
Quite likely, Your code is from ancient version of the library.
Yes you were right, my folder path was set wrong.... sorted out the libraries to 4.4.2 from github and manually put it into the right place.
Below sketch now works with 4.4.2.
#include <IRremote.hpp> // Updated include for latest IRremote library
// Define RC5 codes (address and command)
#define RC5_ADDRESS 0x10
#define RC5_POWER_ON 0x7B
#define RC5_SELECT_AV 0x5E
#define RC5_STANDBY 0x7C
// Define pin mapping
#define IR_SEND_PIN 3 // Digital pin 3 for IR LED
void setup() {
Serial.begin(9600);
Serial.println("IR Remote Control");
// Start the IR sender with the latest library syntax
IrSender.begin(IR_SEND_PIN); // Initialize the IR sender
Serial.println("IR sender initialized on pin " + String(IR_SEND_PIN));
}
void sendRC5(uint8_t address, uint8_t command) {
Serial.println("Sending RC5 - Address: " + String(address, HEX) + ", Command: " + String(command, HEX));
// Updated syntax for the latest library
IrSender.sendRC5(address, command, 2); // Address, command, number of repeats (2 means send 3 times)
delay(100); // Small delay after sending
}
void loop() {
// Start first RC5 transmission (Power On)
Serial.println("Sending Power On command");
sendRC5(RC5_ADDRESS, RC5_POWER_ON);
delay(7000); // Wait 7 seconds
// Start second RC5 transmission (Select AV input)
Serial.println("Sending Select AV command");
sendRC5(RC5_ADDRESS, RC5_SELECT_AV);
// Wait before repeating the sequence
while (1); // processor spins here until power off or reset
delay(10000);
}
NOTE:
For anyone wanting to attempt this, this was my final sketch for use on the Nano and it works fine. Just substitute your RC5 codes.
Now it's matching..
Yaaaaay!
Onto the next problem. Nice that I got this work on the Nano, however my original plan was to get this work on the Digispark ATTiny board.
I've managed to follow the guide to get the drivers and IDE configured correctly and I can see it device manager. However, when I try to compile it for the digispark I'm getting a lot of errors (using the same sketch that compiles fine for the Nano)
Never tried with that.
Read the docs about attiny85:
Not having much luck, got past the compiling errors and managed to upload some sketches. I can get the IR LED output to work but the receiver ignores whatever is being sent by the ATtiny.
Not sure where to go from here.
Post the code, or say what code you have posted you are using unmodified.
a7
The first step is to get the ATTiny85 "Blink" example to flash and run. Then you know you have the boards file and the USB driver installed.
When you select the Sparkfun as the board, do you have an option to set the clock speed? If so, you might try 8MHz instead of 1MHz.
Also, when you say it's working with the Nano, does that mean you can control the other device from the Nano's IR? So in other words, it's outputting the RC5 commands correctly?
Hi, I can upload sketches to the ATTIny like the blink one fine. Everything is setup correctly.
Yes the project works fine on the Nano with the IR sequence accepted correctly by the second device, powers on and changes input as required.
I just can't get the sketch to work once I've ported it to the ATTiny.
// RC5 IR transmitter for Digispark using hardware PWM
// Focused on exact protocol compliance with precise timing
#include <avr/io.h>
#define IR_LED_PIN 4 // Using PB4 for IR transmission (PWM pin)
#define FEEDBACK_LED_PIN 1 // Using PB1 for visual feedback (built-in LED)
// RC5 protocol constants
#define RC5_ADDRESS 0x10 // Your confirmed address (0x10)
#define RC5_POWER 0x7B // Your confirmed power code (0x7B)
#define RC5_AV 0x5E // Your confirmed AV code (0x5E)
// RC5 timing (microseconds)
#define RC5_TIME_BASE 889 // Each RC5 bit is 1.778ms (2 × 889μs)
// Global toggle bit (changes each time a button is pressed)
boolean toggleBit = true;
void setup() {
// Configure pins
pinMode(IR_LED_PIN, OUTPUT);
pinMode(FEEDBACK_LED_PIN, OUTPUT);
// Configure Timer1 for 38kHz PWM on PB4
TCCR1 = 0; // Clear timer configuration
GTCCR = 0; // Clear GTCCR configuration
TCCR1 = (1 << CTC1) | (1 << PWM1A) | (1 << COM1A0) | (1 << CS10); // Fast PWM, no prescaler
OCR1C = 210; // Set TOP value (F_CPU / 38000 / 2)
OCR1A = 70; // ~33% duty cycle
// Brief delay for system stabilization
delay(1000);
}
void loop() {
// Send power command with 3 repetitions
for (int i = 0; i < 3; i++) {
sendRC5(RC5_ADDRESS, RC5_POWER);
delay(65); // Standard RC5 gap between repetitions
}
// Visual feedback
flashFeedbackLED();
delay(7000); // Wait 7 seconds
// Send AV select command with 3 repetitions
for (int i = 0; i < 3; i++) {
sendRC5(RC5_ADDRESS, RC5_AV);
delay(65); // Standard RC5 gap between repetitions
}
// Visual feedback
flashFeedbackLED();
delay(10000); // Wait before repeating the sequence
// Toggle the toggle bit for next transmission
toggleBit = !toggleBit;
}
void flashFeedbackLED() {
digitalWrite(FEEDBACK_LED_PIN, HIGH);
delay(200);
digitalWrite(FEEDBACK_LED_PIN, LOW);
}
void sendRC5(uint8_t address, uint8_t command) {
uint16_t frame = 0;
// Build the 14-bit RC5 frame
frame = (1 << 13); // First start bit (always 1)
frame |= (1 << 12); // Second start bit (always 1)
frame |= (toggleBit ? 0 : 1) << 11; // Toggle bit (inverted for extended RC5)
// Apply the 5-bit address
frame |= (address & 0x1F) << 6;
// Apply the 6-bit command
frame |= (command & 0x3F);
// Transmit the frame bit by bit, MSB first
for (uint8_t i = 14; i > 0; i--) {
// Extract bit value (0 or 1)
uint8_t bit = (frame & (1 << (i-1))) ? 1 : 0;
// Manchester encode and send this bit
if (bit) {
// Bit 1: space then mark
ir_off(RC5_TIME_BASE);
ir_on(RC5_TIME_BASE);
} else {
// Bit 0: mark then space
ir_on(RC5_TIME_BASE);
ir_off(RC5_TIME_BASE);
}
}
// Final space to end transmission
ir_off(RC5_TIME_BASE);
}
// Turn IR LED on (generate carrier)
void ir_on(unsigned int time) {
// Enable PWM output
GTCCR |= (1 << PWM1B) | (1 << COM1B1);
delayMicroseconds(time);
}
// Turn IR LED off (stop carrier)
void ir_off(unsigned int time) {
// Disable PWM output
GTCCR &= ~((1 << PWM1B) | (1 << COM1B1));
digitalWrite(IR_LED_PIN, LOW);
delayMicroseconds(time);
}
What is the clock speed of the digispark?
The ATtiny85 defaults to its 1-MHz internal clock
But if the comment is right,
210 * 38000 *2 is 16 MHz.
Where did the code for setting the carrier frequency constants come from?
a7
Everything is from the Arduino AI. Not sure what the clock speed is, will check.
I'm suspecting the issue is something like the carrier is not correct or the way the Attiny does the PWM. I can see output to the IR led but the receiver ignores it.
I'll book up a scope and compare it with the IR out on the Nano.
Tried that, didn't make a difference.... must be something else and ATTiny not working too good with these ATTiny chips. Will try a project a bit later based on Raw IR codes, I will set up the Uno I bought as a receiver to capture the codes and try a different approach. For now I will use the Nano as that works.
Good choice.
I kind of lost the problem at the moment. You still get errors while compiling? You use digispark or bare attiny85? At what frequency?