Go Down

Topic: error access to com4 denied (Read 273 times) previous topic - next topic

TCSC47

Hi
I'm trying to write a word to PORTD to drive a stepper motor. I only have LEDs connected up though. The program compiled but won't upload. I haven't used DDRD or PORTD before.

error message reads --
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.

Under tools, ARDUINO UNO and COM4 are shown selected.

This is my program

void setup() {
  // put your setup code here, to run once:
DDRD = B11111110;  // sets Arduino pins 1 to 7 as outputs, pin 0 as input:
}

void loop() {
  // put your main code here, to run repeatedly:
PORTD = B00111000; // step 1 sets digital pins 3,4,5 HIGH:
delay(1000);
PORTD = B00101000; // step 2 sets digital pins 4,5 HIGH:
delay(1000);
PORTD = B00110000; // step 3 sets digital pins 2,4,5 HIGH:
delay(1000);
PORTD = B00100100; // step 4 sets digital pins 2,5 HIGH:
delay(1000);
PORTD = B0101100; // step 5 sets digital pins 2,3,5 HIGH:
delay(1000);
PORTD = B00001100; // step 6 sets digital pins 2,3 HIGH:
delay(1000);
PORTD = B00011100; // step 7 sets digital pins 2,3,4 HIGH:
delay(1000);
}


Grateful for any help. Thanks

TCSC47

I've just rebooted my laptop  as recommended by other com4 queries here, but the program still refused to upload. However when I went back to the tutorial program to flash pin 13, this program uploaded and worked fine.

TCSC47

#2
Mar 29, 2019, 10:26 pm Last Edit: Mar 29, 2019, 10:34 pm by TCSC47
Me again! I got it to upload by changing

DDRD = B11111110;  // sets Arduino pins 1 to 7 as outputs, pin 0 as input:

to
DDRD = DDRD | B11111100;

I got the info from the Arduino manual here -- https://www.arduino.cc/en/Reference/PortManipulation which said the second statement is safer because o/p 1 and 2 are used for the serial port which would be COM4 ?? Not really sure the difference but as they say, RTFM.

Anyway, it is working ok now. Good fun this Arduino stuff!


blh64

Changing code has nothing to do with being able to successfully upload or not.

TCSC47

#4
Mar 31, 2019, 01:25 pm Last Edit: Mar 31, 2019, 01:27 pm by TCSC47
Thanks for that blh64. I have changed the code back to the original
DDRD = B11111110; 

and it now uploads quite happily. I have no idea what is going on, apart from other strings on the forum saying that it is due to something else in my PC competing for the port COM4. However, nothing else on my pc seemed to change from it not uploading to it then being able to upload.

Others here have said it just happens and then goes away. Reminds me that PC operating systems and other software running in them have got so cumbersome and cobbled together nowadays that we can not claim to really know what the PC is always getting up to.

CopperDog

I used to have a lot of problems uploading from the IDE until I switched to using FTDI and a 5V programming cable from Sparkfun which works very well. It's so much more reliable in fact that I often pull the chip off an Arduino board and upload to it in a standalone circuit I have set up on a breadboard.

It's faster than trying multiple times to upload to the Arduino board directly.
Personal bytes are finite, save room for play.

TCSC47


DrAzzy

That makes no sense whatsoever.

"access denied" generally means something else is using the serial port, and at the time that you get that error, the sketch hasn't been uploaded, so the content of the sketch can't have any effect - it can't change the behavior of the board until it's been uploaded successfully. And besides, the Arduino Uno resets the chip when the serial port is opened to upload, so the sketch isn't running at that time anyway, and hence nothing the sketch does can break uploads (on a classic AVR with a separate serial adapter chip - the Leo/Micro use native USB for the serial, and those you can put into a difficult-to-upload-to state by uploading a bad sketch; I don't know which ARM-based boards have analogous issues). In your case, it wasn't even getting to that point - it's not even able to open the serial port to try to start uploading.

I think it working was due to some other non-obvious factor - I'm going to predict... that if you unplug the board and plug it back in, it won't work, but if you then wait a while with it plugged in it will spontaneously work again. There exist programs that run in the background and open any serial port they see, assuming it's the kind of device they're meant to talk to (often these are "modem managers" or meant to talk to some specific device that communicates over serial), tries to talk to it, and after a while (may) eventually conclude that the serial device in question isn't whatever they're supposed to talk to, give up. If you see the behavior I predicted, find the program, get rid of it, and tell us what it was so we can warn people :-P
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up