37 votes
Accepted

How do interrupts work on the Arduino Uno and similar boards?

TL;DR : When writing an Interrupt Service Routine (ISR): Keep it short Don't use delay () Don't do serial prints Make variables shared with the main code volatile Variables shared with main code may ...
Nick Gammon's user avatar
  • 38.1k
17 votes
Accepted

What to do with Arduino floating pins?

The simplest thing to do is set them to INPUT_PULLUP. If you want a purely hardware solution then you could connect them to GND through some resistors (10kΩ or whatever you have in that kind of order ...
Majenko's user avatar
  • 105k
16 votes
Accepted

What is the purpose of the I/O pin capacitor on the AVR microcontroller?

To make explicit the implicit parasitic capacitance on the pin.
dannyf's user avatar
  • 2,770
15 votes
Accepted

very lightweight low power microcontroller with memory?

I made up a small torch locator which used an ATtiny85 powered from a button-cell (CR2032). It looks like this: Other side: That currently weighs 5.9g. The battery-holder weighs 1.6g so you could ...
Nick Gammon's user avatar
  • 38.1k
15 votes

Why connect a diode between the reset pin of Arduino and 555 timer?

It's called a "Wired Or" arrangement. The Arduino's RESET pin has a pullup resistor in it (10KΩ). That keeps the RESET pin normally HIGH. To invoke a reset that pin needs pulling low, and that is ...
Majenko's user avatar
  • 105k
14 votes
Accepted

ATMEGA328P-U vs ATMEGA328-PU

The main difference is the bit before the -. That is, the 328 vs the 328P. The "P" there denotes "Picopower" which allows the chip to run at very low power consumptions. Basically the P version is ...
Majenko's user avatar
  • 105k
11 votes
Accepted

Can we burn Arduino bootloader into any microcontroller chip?

The answer needs to have multiple parts: Yes, in principle you can create a bootloader for any microcontroller, which acts like the Arduino's. Please be aware that there are different bootloaders, ...
the busybee's user avatar
  • 1,991
10 votes
Accepted

Programming Chinese Arduinos

It's because these are unprogrammed chips, meaning they haven't had a bootloader programmed into them yet. Here is a tutorial for using your Arduino board to program a bootloader into them (there are ...
JRobert's user avatar
  • 15.2k
9 votes
Accepted

Arduino 16 MHz with only 3.3V?

Officially, no. Practically, often but not always. If I follow the datasheet to the the letter, this configuration should not work. BUT... After some test, it did work. The data sheet does not ...
Chris Stratton's user avatar
9 votes

Does the reset button work when not powered?

The reset on an Arduino does not erase anything. It merely restarts execution of an already uploaded program. Also the AVR needs to be powered on for it to realize whether it has been reset. Every ...
electrophile's user avatar
9 votes
Accepted

Is there a way to disable modules like ADC without a sleep mode?

Certainly there is. // disable ADC ADCSRA = 0; You can disable lots of internal modules like this: power_all_disable(); // turn off all modules See my page about power saving. Majenko ...
Nick Gammon's user avatar
  • 38.1k
9 votes
Accepted

Powering Atmega328p from 4.5V

From the ATmega328P datasheet: Within the range 2.7 V – 4.5 V, the maximum frequency is a linear function of Vcc. From this graph, you can compute the minimum value of Vcc required to run the ...
Edgar Bonet's user avatar
  • 42.7k
8 votes

very lightweight low power microcontroller with memory?

I would personnaly suggest an ATtiny 45/85. It is pretty much a small AVR with 5 GPIOs. You can program it with the Arduino IDE and use the Arduino as ISP. If you can design you own custom PCB, a SMD ...
Dat Ha's user avatar
  • 2,913
8 votes
Accepted

Sending serial data in an interrupt

You cannot use Serial inside an interrupt. Transmitting Serial relies on interrupts being available, and from inside an interrupt they aren't. All Serial communication must be done from loop(). So ...
Majenko's user avatar
  • 105k
8 votes

Run code once after programming

This is a X->Y problem. Here is a solution for X: Bit 3 of high fuse of the ATmega328p controls if EEPROM memory is preserved through the chip erase. You can change the high fuse setting in boards....
Juraj's user avatar
  • 17.9k
7 votes
Accepted

Two function Reset button - long/short press

It can be done with one button, one resistor, one capacitor and one GPIO pin (in addition to the RESET pin): simulate this circuit – Schematic created using CircuitLab Pressing the button ...
Majenko's user avatar
  • 105k
7 votes
Accepted

Why doesn't millis() use 1 µsec or 1 msec interrupt?

One microsecond is only 16 CPU cycles. The CPU needs 4 cycles to prepare itself for servicing the interrupt (save the program counter, load the interrupt vector and clear the I bit in SREG). The ...
Edgar Bonet's user avatar
  • 42.7k
7 votes
Accepted

How to deep sleep ATtiny/ATmega (to run for years with batteries) but still detect a button press?

ATTINY's are designed to easily do this since they can wake from power down sleep mode by a pin change... Basically you want to... Connect a normally-open push button between an IO pin and ground....
bigjosh's user avatar
  • 1,553
7 votes

Serial printing from flash memory (F() macro, PROGMEM, sprintf_P, SPTR)

First, the freeMemory() function that you used from Adafruit was originated from a GitHub repository. I don't know about the __arm__ implementation, but for the AVR one, it is incomplete for handling ...
hcheung's user avatar
  • 1,362
6 votes
Accepted

Correct Capacitors to use with L7805 Voltage Regulator

The answers are in the notes: Although no output capacitor is need for stability, it does improve transient response. Required if regulator is locate an appreciable distance from power supply ...
Majenko's user avatar
  • 105k
6 votes
Accepted

Increasing number of iterations not increasing time

The compiler has realized that your loop doesn't do anything useful and therefore optimized the whole thing away. Thus you are just timing how long it takes to do nothing. (You didn't get a result of ...
Nick Gammon's user avatar
  • 38.1k
6 votes
Accepted

Where in datasheet is the warning about unreliability of reading PINxn?

did somebody come across such case, or I'm the first in the world? You are not the first. I recently got bitten by the very same issue. However, unless you are close to an unusually strong radio ...
Edgar Bonet's user avatar
  • 42.7k
6 votes

ATMEGA328P-U vs ATMEGA328-PU

There are three die types: 328 328P 328PB all have different signature bytes which may or may not impact loading code into them. Generally tho the programming software needs to know which part ...
CrossRoads's user avatar
  • 2,405
6 votes

ATMEGA328P-U vs ATMEGA328-PU

User line_code from forum.arduino.cc recently received an ATMEGA328P-U (or actually ATMEGA328P U) from Mouser (a company which you would not suspect to send out fakes or source from the gray market). ...
Julian Habekost's user avatar
5 votes

Is RX1 and TX0 the same thing as TX and RX? Will there be a difference in the way I program it?

It's not RX1 and TX0 but RXI and TXO That is receive input and transmit output, Exactly the same as RX and TX just with the data direction explicitly shown in the lettering.
Majenko's user avatar
  • 105k
5 votes
Accepted

Atmega328 PWM frequency setting not working

Your code assumes that TCCR0n are zero. But what if they are not. What if there is some hidden initialization? Timer0 is used by the Arduino micro/millis counter and the prescale (TCCR0B) is ...
Mikael Patel's user avatar
  • 7,959
5 votes

Basic makefile for avr-gcc

The accepted answer is great as it has given me a valuable lesson in all kinds of debugging tools (avr-objdump -D has become a close friend). Namely, the line: ${OBJCOPY} -O ihex -R .eeprom $< $@ ...
Robert Špendl's user avatar
5 votes
Accepted

How to use the analog comparator to determine when an analog pin has reached a certain voltage?

I have a page about the analog comparator that has code: volatile boolean triggered; ISR (ANALOG_COMP_vect) { triggered = true; } void setup () { Serial.begin (115200); Serial.println ("...
Nick Gammon's user avatar
  • 38.1k
5 votes
Accepted

What happens if I draw too much current from ATMEGA IO pin?

There's a few crude calculations you can do using some numbers from the datasheet. This graph is in the datasheet: It shows the voltage dropped by the high-side MOSFET driver in the IO pin for ...
Majenko's user avatar
  • 105k
5 votes

SIM808 module GSM working fine, GPS not working (No GPS ready message on power on)

You have a version2 module. Use AT+CGNSxxx instead of AT+CGPSxxx
user24177's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible