Same code working differently on Nano 33 IoT and Mega

If you do not have an oscilloscope and look for a cheaper solution. Google "25MHz Logic analyzer".
You can get one for around $10 or €. They are surprisingly good for the money and fast enough for many protocols supported by Arduinos like SPI, UART, I2C, CAN ...

Have a look at Sigrok PulseView. It is a open source software for these logic analyzers. It supports decoders for many popular protocols. You can try the software without hardware with some build-in trace files.

https://sigrok.org/wiki/Downloads

1 Like