Go Down

Topic: Arduino Nano communication problem (Read 682 times) previous topic - next topic

seldon

Hello everyone, as I'm new here. I'm not very experienced so please be patient if answer to my question is trivial, however I cannot find it myself, even though I have tried hard.
I have a problem with my Arduino Nano 328P (a clone actually, marked as "Deek-Robot NANO V4.0"). I have created a sketch and succesfully uploaded it, but the problem appeared when I tried to update it - during upload Arduino IDE either says that COM port is already in use (if I connect Arduino after starting IDE) or Java process crashes (if it is connected before starting IDE). I'm sure that this is because I messed with RX, TX pins. In my project I need all possible digital pins and I had to use also D0 and D1. THe relevant part of my code is:
Code: [Select]

void setup(){
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  delay(300);

  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, INPUT);
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(A5, OUTPUT);
  pinMode(A4, INPUT);

// here some reading from pins A3 and A4, and writing to A0, A1, A2, A5, 0 and 1
}

Did I disabled possibility to program Arduino through USB? What are my options now? Please post some answers or direct me to a tutorial if there is any.

groundfungus

you can use analog input pins as digital by the statement pinMode(Ax, OUTPUT); (Ax is A0,A1,...).  Then free up the RX and TX pins for upload and communication.

CrossRoads

You can use as written - to  download: press & hold the reset button, when the IDE shows "compiled xxx of 32xxx bytes" release the reset. Might take a few tries to get the timing right. Also easier if you do File:Preferences and turn on Verbose outputs.
The reset makes sure the bootloader is ready for the downloa and that the sketch hasn't started already to interfere on the serial lines.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

seldon

@groundfungus
As you can see in my sketch, I'm already using analog pins as digital outputs, and even though it's not enough. Using a shift register is not an option too, beacause I need ability to switch outputs with frequency up to 1 MHz, so I won't have time to transmit data serially. Besides, my problem is not the code, but the fact that I don't have access to my Arduino.

@CrossRoads
I tried that already, but it seems that the key is timing. I'll try your advice and turn verbose output on. Thanks!
Also, for the future - what should I do to avoid such situation? As you can see, I've put 300ms delay, but it is clearly not enough.

CrossRoads

Well, you can 'not' use the serial pins as outputs.
The bootloader takes a few seconds, so 300mS is not long enough.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

seldon

OK, problem solved. I aquired USBasp programmer and reburned bootloader. After few experiments (and few sequential reburns) I found out, that 1800 ms delay on startup allows to use D0 and D1 as outputs without blocking ability to reprogram normally through USB.

seldon

One more question. If I want to restore USB programming ability - is it enough to just add:
Code: [Select]

  pinMode(0, INPUT);

I want to remove 2s pause at the start, but want to enable programming by external button.

Go Up