How to control the pins in Arduino Nano?

Helo,

I've got a question.

I own this board: https://www.amazon.de/dp/B01NBS2UBL/ref=pe_3044161_189395811_TE_SCE_dp_4

Now I installed Arduino IDE.

This is my program and it works fine:

const int A = 1;
int i = 1000;
bool plusorminus = true;

void setup() {
  pinMode(A, OUTPUT);
}

void loop() {
  if(plusorminus == true) i = i - 100;
  else i = i + 100;
  digitalWrite(A, HIGH);
  delay(i);
  digitalWrite(A, LOW);
  delay(i);

  if(plusorminus == true && i == 0) plusorminus = false;
  else if(plusorminus == false && i == 1000) plusorminus = true;
}

Now, I want to blink my LED on a different PIN. How is the configuration of the PINs on this board? I can't figure it out. When I use for example A = 4 (PIN 4), then I can't find the PIN on the board to blink my LED.

This is my first problem.

My second is, that I own the book "Make: AVR Programming". There is a code sample like this:

#include <avr/io.h>
#include <util/delay.h>

int main(void) {
  DDRB = 0b00000001;

  while(1) {
    PORTB = 0b00000001;
    _delay_ms(1000);

    PORTB = 0b00000000;
   _delay_ms(1000);
  }

  return (0);
}

This does compile. But when I load it to the board, it does nothing... Why?

Thank you for every answer! :slight_smile:

This does compile. But when I load it to the board, it does nothing... Why?

Because you have not called init() to make the hardware ready.

When I use for example A = 4 (PIN 4), then I can't find the PIN on the board to blink my LED.

Could it be the digital pin cunningly labelled D4, do you think ?

The pin numbers printed on the board do not relate directly to the pin numbers of the AVR chip. They are automatically translated as part of the compilation process

UKHeliBob:
Could it be the digital pin cunningly labelled D4, do you think ?

No, it isn't. :frowning: When I try to plug the LED to PIN D4, then it doesn't blink.

PaulS:
Because you have not called init() to make the hardware ready.

#include <avr/io.h>
#include <util/delay.h>

int main(void) {
  init();

  DDRB = 0b00000001;

  while (1) {

    PORTB = 0b00000001;
    _delay_ms(1000);

    PORTB = 0b00000000;
    _delay_ms(1000);
  }

  return (0);
}

This doesn't work also. The LED doesn't blink, I tried to connect every pin with the LED...

What only works is, if I set A = 1, then the PIN "TX1" is blinking. And when I set A = 3, then "D3" is blinking.

No matter, how I can control the other PINs... It starts then with A = 18 or somehow...

No, it isn't. :frowning: When I try to plug the LED to PIN D4, then it doesn't blink.

Are you saying that if you set A = 4 in the first sketch of your original post and connect an LED (and resistor, of course) to D4 that the LED does not blink ?

What happens if you set A = LED_BUILTIN ?
Does the built in LED on pin 13 blink ?

This thread is a good example of why it's a crap idea to ask two questions at once.

UKHeliBob:
Are you saying that if you set A = 4 in the first sketch of your original post and connect an LED (and resistor, of course) to D4 that the LED does not blink ?

What happens if you set A = LED_BUILTIN ?
Does the built in LED on pin 13 blink ?

Yes, when I set A = 4 then D4 doesn't blink.

This works:

const int A = LED_BUILTIN;

What voltage do you get from D4 if you set it's state permanently HIGH ?

UKHeliBob:
What voltage do you get from D4 if you set it's state permanently HIGH ?

About 0.4 V with HIGH and 0.4 V with LOW...

ubik123:
About 0.4 V with HIGH and 0.4 V with LOW...

It sounds like the board is busted

Hm. I've got two boards and yes, it looks like it is defect.

Are there any advices to NOT destroy the board? :slight_smile: (I'm a newbie)

Well, the only thing what I did is to try every pin. So i connected my LED step by step to every pin. But I think it wasn't a good idea. How can I prevent this?

So i connected my LED step by step to every pin

What value of current limiting resistor did you use ?

UKHeliBob:
What value of current limiting resistor did you use ?

I'm going to guess that the answer to that is "what resistor? What are you talking about?".

PaulS:
I'm going to guess that the answer to that is "what resistor? What are you talking about?".

I agree. That's why I framed the question in your the way I did

Or, the answer could be "What resistors? I use these."

UKHeliBob:
What value of current limiting resistor did you use ?

240 Ohm. The LED is a green one.