Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino doing weird things....

Status
Not open for further replies.

Fintek

Member
I am trying to get an Elegoo Nano to control a sound board through 4 pins by making them low one at a time, then a combination.
When it gets to sound four, it is supposed to blink the built in led four times, then make pin 22 low. Instead it gives a long blink, three short blinks, then turns on the TX and RX lights. Any idea what is going on? I've tried 3 new boards and they all do the same.
Here is the code:

void setup() {

pinMode(19,OUTPUT);
pinMode(20,OUTPUT);
pinMode(21,OUTPUT);
pinMode(22,OUTPUT);
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(19,HIGH);
digitalWrite(20,HIGH);
digitalWrite(21,HIGH);
digitalWrite(22,HIGH);
digitalWrite(LED_BUILTIN,LOW);


}
void loop() {

delay(2000);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(19,LOW);
delay(3000);
digitalWrite(19,HIGH);

delay(2000);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(20,LOW);
delay(2000);
digitalWrite(20,HIGH);


delay(2000);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(21,LOW);
delay(2000);
digitalWrite(21,HIGH);


// problem seems to start here


delay(2000);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(22,LOW);
delay(2000);
digitalWrite(22,HIGH);

// starts working normally again


delay(2000);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
delay(500);
digitalWrite(LED_BUILTIN,HIGH);
delay(500);
digitalWrite(LED_BUILTIN,LOW);
digitalWrite(19,LOW);
digitalWrite(21,LOW);
delay(2000);
digitalWrite(19,HIGH);
digitalWrite(21,HIGH);

delay(2000);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(19,LOW);
delay(1000);
digitalWrite(19,LOW);
digitalWrite(20,LOW);
digitalWrite(21,LOW);
digitalWrite(19,HIGH);
digitalWrite(20,HIGH);
digitalWrite(21,HIGH);
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
delay(1000);
}
 
Hi,

Its because on the Nano, pins A6 and A7 are Analogue Inputs only, not Digital 20 & 21 -see pin out diagram

001751.jpg
 
The pinout the poster lists seems to be the Nano Every (or similar), not the "regular" Nano
I didn't know there was such a beast.

Are you able to clear up some confusion,
On the Arduino nano every page (under Tech Specs) it states Two different processors. I'm assuming it has a ATMega4809 but the diagram doesn't show a 48 pin device. It also state that it runs at 16MHz but the 4809 has an internal 20MHz oscillator. Are you able to confirm which speed it runs at?
A link to an accurate page would be much appreciated.

Thanks,

Mike.
Edit Link to 4809 page.
 
The ones I have use the 4809 chip. It runs at the default 16Mhz speed under the Arduino IDE, to keep the Arduino timing stuff the same. There are ways to change it to 20Mhz in code, but most people don't bother. Other difference is that some of the PWM pins (2 of them?) are different.
Main advantage is it has 6kB ram, and 48k of program space. Otherwise, it runs much like a regular Nano, and 5V device...
I believe it also has four USARTs, but not sure if the IDE can pick them all up (limited Nano pinouts?).
 
Last edited:
Thanks for that.
Any idea what they mean by PA2/PF2 etc? - red eclipse.
And what does the tilde mean on some of the digital pins? I.E. ~D10 - blue eclipse
nano.png

They seem to have used UART1 for the default as that can be remapped to PC4 & 5.
UART0 defaults to PA0 & 1 so it might be possible to use it.

Guess I'll have to get one and have a play.

Mike.
 
There's also a MicroChip ATMEGA4809 CNANO board, which presumably has a similar spec but can be programmed from MPLABX or AVR Studio.

I bought a few to play with, but never really did anything with them, there seems a general lack of information and examples for them.
 
Pommie, the tilde denotes a PWM port, I think. Seems there are only 5 of them.
BTW, one uart handles the USB traffic, and the TX/RX pins (D0/D1) are the "other" USART. That implies one can use both at the same time?
 
Pommie, the tilde denotes a PWM port, I think. Seems there are only 5 of them.
BTW, one uart handles the USB traffic, and the TX/RX pins (D0/D1) are the "other" USART. That implies one can use both at the same time?
If the chip has 2 usarts then you can use them both, if it has 3 (like the ESP32 boards) then you can use all three. If the chip only has one, then you can use a software UART to create a second one.
 
Thanks for that.
Any idea what they mean by PA2/PF2 etc? - red eclipse.
And what does the tilde mean on some of the digital pins? I.E. ~D10 - blue eclipse
View attachment 140428
They seem to have used UART1 for the default as that can be remapped to PC4 & 5.
UART0 defaults to PA0 & 1 so it might be possible to use it.

Guess I'll have to get one and have a play.

Mike.

Those pins show up over here on chip pinout, basically analog pins :



Regards, Dana.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top