Standalone ATMega Upload Failed

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");

}


}

What size are the pull-up resistor and capacitor on the reset pin on the breadboard?

and what is this ?
image

It looks like pull-down on RESET pin. If so, ATmega won't start.

Another one, 100nF on XTAL pins. It is way too much. Should be 27pF max, 22pF is "universal" value.
Message: "\.\COM9: Access is denied.", looks more like the port is held by another APP.

Yep. The crystal oscillator won't work at all with those caps.

Check the crystal data sheet for the required value of the load capacitance.

Ah, apologies... There are some differences between the original diagram and what I actually ended up soldering to the PCB. I failed to specify those differences. So much information, I always end up leaving something out of my posts...

  • I did indeed use 22 pF caps for the crystal oscilator, not 100 nF, despite what the diagram says.

  • Red_car, the resistor you posted was something I thought I needed thanks to the internet. I saw some diagrams for standalone ATmega that showed a 10k resistor between RST and GND, but I must have misunderstood. It only caused problems. After some troubleshooting I found out it was the source of many problems. That resistor has been removed from the final PCB (if you look at the front/right of the remote control, you can see the empty space.)

  • On the reset breadboard, the resistor is 10k, the cap is 0.1 uF.

Sorry for the confusion, hope this clears it up.

Update:

I just realized that although my VR headset was disconnected, the hub was still plugged into the USB and may have been interfering with the port in some way. I unplugged it. The sketch upload still fails, but the error message is different:


avrdude: Version 6.3-20190619
       "C:\Users\timat\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\usernm\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM9" -b115200 -D "-Uflash:w:C:\Users\username\AppData\Local\Temp\arduino-sketch-4B7BD71C451DCE88A07F4D5BEF1B50CB/Remote Mk II.ino.hex:i"
Failed uploading: uploading error: exit status 1

Can you post the full error message.

This is...extremely odd.

The error I posted above was the complete full error message. I even had verbose output on for uploading, and the error was only those three lines.

Then, a separate issue, I noticed that small changes I made to the sketch weren't actually saving. File > save, and ctrl+S have actually been doing nothing this entire time.

So, I did a "save as" to make a new file. Not only did that work, but... The upload issue is now resolved. Programming successful.

Is it possible my sketch file was corrupt in a way that prevented uploading? The only change I made was adding a
//TEST
to see if changes were saved.