Arduino forum,
I'm just learning the Nano and have my I2C LCD and HC-SR04 sensor working.
Reading about the pin functions it looks like only ports 2/3 have interrupts and is seems that is uses interrupts to capture the echo wavelength of the HC-SR04.
I am used to using a counter to measure this and I will eventually need more interrupts.
I read about port expanders but they doesn't supply much in the way of interrupts.
Is there a way to get around this without going to larger device.
When they designed the ATmega328 chip, they decided that it should have more interrupts than the ATmega8, while keeping most things the same. So they added a Pin Change Interrupt (PCINT) to each pin.
In the Arduino world, an interrupt is almost never necessary, as LarryD wrote. The more you use interrupts and timers, the less compatible the code is.
Reading buttons in a interrupt is normal in a embedded system, but not in the Arduino world. The Arduino Nano has only 2kbyte of SRAM, but it is still possible to do many thing "at the same time" with a sketch that has no delay and uses millis() for timing.
If you are used to embedded systems with a multitasking system and interrupts and queues and semaphores, then you can use the ESP32 (or a newer variant) or the Raspberry Pi Pico.
The ESP32 runs FreeRTOS and the Raspberry Pi Pico runs Mbed. The Arduino layer is build upon that.
I think that any pin can be used.
The NewPing library uses Timer2 with an interrupt. Since the Arduino Nano has only three timers, and Timer0 is in use by Arduino, you might run out of timers if you add another library that uses a timer (tone, Servo, and many other libraries).
The label "ATMEL M32P" indicates the ATmega328P. I can not find when the microcontroller was introduced, but it is still amazing what a simple microcontroller can do. It is/was the perfect companion for Arduino, because at power up everything is guaranteed to be turned off. The boot section is therefor very simple. The code only needs to initialize what is used inside the microcontroller.
One doesn't need any interrupts at all. Here's a simulation that shows that an Arduino/Nano can be fast enough to read an HC-SR04 with plain old state machine and state change detection coding: