Hello all. Pleased to announce that your help from my previous post about the standalone ATMega has born fruit! I have an 8-button remote for my TV and soundbar that is functioning perfectly... almost...
In my sketch, I accidentally flipped the IR codes for "Volume Up" and "Volume Down." Fortunately I can upload a new sketch because I included 5 pins for TTL interface on the PCB the design. Unfortunately, it's not QUITE working. Here's what's working:
- Serial communication being sent from the remote (TX) to the PC (RX) is working fine.
- The DTR actually IS successfully triggering a reset. Soon after I click upload in Arduino IDE, my PC receives serial communication stating that the ATmega has indeed rebooted.
- Unfortunately, I lacked the foresight to include a way to test PC to Remote serial communication. After checking my diagram and eye-balling the physical PCB tracks, I was at least able to confirm it is going to the correct pin.
Despite a seemingly successful auto-reboot at the time of upload, I'm receiving this error:
Failed uploading: uploading error: exit status 1avrdude: ser_open(): can't open device "\\.\COM9": Access is denied.
I also tried rigging up a manual reset button, in case it was a timing issue. No dice.
Picture time! First, here are my circuit diagrams. Sorry if they're a little too hairy for interpretation.
Next, photos of the real deal. The wide shot includes:
- My USB to TTL module
- Breadboard containing circuitry to make DTR work
- The remote
The push button from my manual reset experiment is still on the breadboard, but it's intentionally disconnected. Please disregard.
The pin labels for the USB to TTL are difficult to read. From top to bottom, and by wire color, they are:
- DTR > Yellow Wire
- RX > Green
- TX > Blue
- VCC > Purple
- CTS > Grey (Not connected to remote)
- GROUND > White
I've rebooted my PC, confirmed I have the right port selected, unplugged/replugged the module, restarted IDE, and even unplugged my USB mouse/keyboard during the upload.
Is there something I've overlooked or misunderstood? Any idea what it will take for me to upload a new sketch?
Thank you!
PS, Here's my sketch:
//IR LED must use Pin #3
#include <IRremote.h>
IRsend irsend; // Create IR Send Object
//NAME BUTTON PINS
const int irPin = 3;
const int tvPowPin = 7;
const int tvUpPin = 10;
const int tvDownPin = 11;
const int tvSourcePin = 5;
const int tvEnterPin = 8;
const int sPowPin = 6;
const int sUpPin = 9;
const int sDownPin = 4;
unsigned long timer = millis(); //Used for sleep countdown
void digitalInterrupt() {} //----------Wake Interrupt: Blank. Just restarts code.
void setup(){
// initialize TV Buttons as input
pinMode(irPin, OUTPUT);
pinMode(tvPowPin, INPUT_PULLUP);
pinMode(tvUpPin, INPUT_PULLUP);
pinMode(tvDownPin, INPUT_PULLUP);
pinMode(tvSourcePin, INPUT_PULLUP);
pinMode(tvEnterPin, INPUT_PULLUP);
// initialize Soundbar Buttons as input
pinMode(sPowPin, INPUT_PULLUP);
pinMode(sUpPin, INPUT_PULLUP);
pinMode(sDownPin, INPUT_PULLUP);
Serial.begin(9600);
Serial.print("Setup Function. Current timer at: ");
Serial.println(timer);
//INTERRUPT PIN
pinMode (2, INPUT);
attachInterrupt (0, digitalInterrupt, FALLING);
}
void loop() {
//SET STATES
int tvPowState = LOW;
int tvUpState = LOW;
int tvDownState = LOW;
int tvSourceState = LOW;
int tvEnterState = LOW;
int sPowState = LOW;
int sUpState = LOW;
int sDownState = LOW;
//---------------Buttons----------------
// TV Power
tvPowState = digitalRead(tvPowPin);
if (tvPowState == LOW) {
Serial.print("TV POW");
Serial.print('\n');
irsend.sendSony(0xA90, 12);
delay(100);
irsend.sendSony(0xA90, 12);
delay(150);
timer = millis();
}
// TV Up
tvUpState = digitalRead(tvUpPin);
if (tvUpState == LOW) {
Serial.print("TV UP");
Serial.print('\n');
irsend.sendSony(0x2F0, 12);
delay(100);
irsend.sendSony(0x2F0, 12);
delay(150);
timer = millis();
}
// TV Down
tvDownState = digitalRead(tvDownPin);
if (tvDownState == LOW) {
Serial.print("TV DOWN");
Serial.print('\n');
irsend.sendSony(0xAF0, 12);
delay(100);
irsend.sendSony(0xAF0, 12);;
delay(150);
timer = millis();
}
// TV Source
tvSourceState = digitalRead(tvSourcePin);
if (tvSourceState == LOW) {
Serial.print("TV Source Pressed");
Serial.print('\n');
irsend.sendSony(0xA50, 12);
delay(100);
irsend.sendSony(0xA50, 12);
delay(150);
timer = millis();
}
// TV Enter
tvEnterState = digitalRead(tvEnterPin);
if (tvEnterState == LOW) {
Serial.print("TV ENTER");
Serial.print('\n');
irsend.sendSony(0xD10, 12);
delay(100);
irsend.sendSony(0xD10, 12);
delay(150);
timer = millis();
}
// Sound Power
sPowState = digitalRead(sPowPin);
if (sPowState == LOW) {
Serial.print("Sound Power");
Serial.print('\n');
irsend.sendNEC(0xFF02FD, 32);
delay(150);
timer = millis();
}
// Sound Up
sUpState = digitalRead(sUpPin);
if (sUpState == LOW) {
Serial.print("Sound Up");
Serial.print('\n');
irsend.sendNEC(0xFFA25D, 32);
delay(150);
timer = millis();
}
// Sound Down
sDownState = digitalRead(sDownPin);
if (sDownState == LOW) {
Serial.print("Sound Down");
Serial.print('\n');
irsend.sendNEC(0xFF827D, 32);
delay(150);
timer = millis();
}
//-------------SLEEP STUFF-----------------
if (millis() >= (timer + 1000)){
Serial.println("Sleeping Now");
digitalWrite (4, LOW);
//Disable ADC
ADCSRA&= -(1<<7);
//ENABLE SLEEP
SMCR |= (1<<2); //power down mode
SMCR |= 1; //enable sleep
//BOD DISABLE
MCUCR != (3<<5); //set both BODS and BODSE at same time
MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6); // then set the BODS bit and clear the BODSE bit at the same time.
delay (100);
__asm__ __volatile__("sleep");
}
}







