112 votes
Accepted

How do you use SPI on an Arduino?

Introduction to SPI The Serial Peripheral Interface Bus (SPI) interface is used for communication between multiple devices over short distances, and at high speed. Typically there is a single "...
Nick Gammon's user avatar
  • 37.6k
8 votes

A question about resistance measurement with arduino

If you know Ohm's Law (which you should) and you realise that the ADC measures voltage, you should be able to work it out from there. But I will go into minute detail for you to ensure you understand. ...
Majenko's user avatar
  • 105k
6 votes

Press the Windows key using "keyboard.press();"

They Keyboard.press() command accept modifiers per the documentation. You may need to do multiple press() commands before releasing. For example, if you want to launch File Explorer you could use: ...
Eric G's user avatar
  • 161
6 votes
Accepted

How do I prevent Arduino from running on startup?

The Leonardo should wait a couple of seconds after resetting to see if a new sketch arrives. Power off the board completely (remove the USB cable). Hold down the Reset button, and keep it held down (...
Nick Gammon's user avatar
  • 37.6k
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
  • 41.4k
6 votes
Accepted

How can I detect which baudrate a virtual COM port is set to?

From looking at the source it appears that on 32u4 based boards Serial includes extra methods to access the settings from the USB host: see: https://github.com/arduino/ArduinoCore-avr/blob/...
Craig's user avatar
  • 2,120
5 votes

Keyboard.print() skips keys

The Arduino assumes a US keyboard layout. The thing with keyboards is they don't actually send the letters or symbols that are printed on the keys. Instead the send a scan code that defines where on ...
Majenko's user avatar
  • 105k
5 votes
Accepted

Pinout for Leonardo USB

The USB does not go to pins 0 and 1. The UART goes to pins 0 and 1 - that is a totally different interface. The USB is connected to dedicated USB pins on the chip. If you look at the Leonardo ...
Majenko's user avatar
  • 105k
5 votes
Accepted

Upload code on Arduino Leonardo using command line

The problem with the Leonardo is it doesn't automatically reset when you open the serial port like boards such as the Uno do. The Arduino IDE contains code to manually reset the board (by opening the ...
Majenko's user avatar
  • 105k
5 votes

Upload code on Arduino Leonardo using command line

After try some trial and error I have built a simple binary to upload into the Leonardo bootloader. This binary opens serial at 1200 baud then closes it, and wraps the avrdude binary to write .hex ...
vanbwodonk's user avatar
5 votes

How to convert Arduino example sketch to a complete c++ project?

Basically *.ino is *.cpp without headers. So you can rename it to *.cpp, If you have any functions which are used before they have been defined, provide declarations for each function before its ...
gilhad's user avatar
  • 1,380
5 votes
Accepted

Which Arduinos have a true serial port?

There seems to be quite a few Arduinos without a 32U4, like: Uno (you mentioned it already) Mega (same) Lilypad Snap MKR1000 Pro Pro Mini Zero Due Ethernet Mini Nano MKR Zero See the list at ...
Michel Keijzers's user avatar
5 votes
Accepted

Arduino Leonardo(Atmega32u4) - Detecting if USB is connected to a computer?

ADDEN of UDADDR is set if the '32U4 has been assigned a USB address by the host and the firmware wants to enable USB connectivity. UDADDR & _BV(ADDEN)
Ignacio Vazquez-Abrams's user avatar
5 votes
Accepted

Help with AlphaNumeric array

All of those "A1" "A2" pins have other numbers that go with them. The A1 or A2 is #defined in the core to be some number. You can just use A1 or A2 and it will work. For example, try this line and ...
Delta_G's user avatar
  • 3,118
5 votes

Generated frequency is not as expected

digitalWrite() takes a few microseconds to execute as well. There is also some overhead around the delayMicroseconds() function. If you need exactly 500 kHz, you would want to consider using a timer. ...
towe's user avatar
  • 863
4 votes

Disabling i2c internal pull up resistors

Let's go back to basics. A low-value pull-up resistor actually improves the shape of the I2C clock and data. One internal pull-up: Both ends with the internal pull-up: 10 k external pull-up: 4.7 k ...
Nick Gammon's user avatar
  • 37.6k
4 votes

Disabling i2c internal pull up resistors

From the datasheet: Note that the internal pull-ups in the AVR pads can be enabled by setting the PORT bits corresponding to the SCL and SDA pins, as explained in the I/O Port section. To disable ...
Ignacio Vazquez-Abrams's user avatar
4 votes
Accepted

Arduino Pro Micro Analog Pinouts

Assuming you have the Pro Micro core, they are called A0, A1, A2, A3, A6, A7, A8, A9 and A10. There is no need to "special case" the others, since the pins are known as both.
Ignacio Vazquez-Abrams's user avatar
4 votes
Accepted

Powering ESP8266 from Leonardo's 3.3v pin

The Leonardo is specified to provide only 50mA on the 3V3 pin. A ESP8266 can use up to almost 300mA when transmitting. Consider using a LDO regulator connected to the 5V pin instead.
Ignacio Vazquez-Abrams's user avatar
4 votes
Accepted

Can Arduino Leonardo use USB port and RX TX serial pins at the same time?

32u4 is multi-serial uC. USB connection works on default serial communication which can be used via Serial.print("somevalue"). On the other hand if you want to use RX/TX on pins 0, 1 which are ...
Sener's user avatar
  • 394
4 votes

Arduino I2C Wire.onReceive hangs after a few loops

After a bit of tinkering, I noticed that removing the delay() call in the slave fixed it and there were no more hangs. Also, when using the Servo library to move a servo instead of blinking the led, ...
Valentin Brasso's user avatar
4 votes
Accepted

Arduino Leonardo/Pro Micro sleep and USB

The Arduino has several sleep modes. They differ mainly by the clocks that are kept running, the peripherals that are enabled, and the possible wake-up sources. All these modes are described in the ...
Edgar Bonet's user avatar
  • 41.4k
3 votes
Accepted

Can I use analogReadResolution() on an Uno or Leonardo?

There is no point to having analogReadResolution() on AVR devices since that function only exists to provide/ensure backwards compatibility with the fixed 10-bit ADC that is found in AVR devices. If ...
Ignacio Vazquez-Abrams's user avatar
3 votes

Do I need a bubble sort or something easier?

Since you only need to know the 4 largest values in the array you don't need to sort the array, you just need to iterate through it and find the four largest values. This can be done in O(n*k) which ...
Chris's user avatar
  • 369
3 votes

How to generate Chirp Signal using Arduino

If you're ok with starting with square wave signals, this can be done on an Arduino. You need to do the following: Configure a 16-bit Timer to CTC mode Select the right prescaling Add a RC low pass ...
bot3663369's user avatar
3 votes

Send Keyboard Media Keys with Keyboard Library

It is indeed possible and also without the requirement to modify the Arduino environment itself. Just register an HID descriptor for the "report ID" for "Consumer Control" (the ...
Peter Mortensen's user avatar
3 votes

Arduino Leonardo is not recognized by usb cable in Windows 8

Nick Gammon's solution worked for me. I am adding the arduino code I used below. While Arduino Leonardo is connected to your computer, press its reset button. A COM for Arduino Leonardo appears ...
Yus Sidani 's user avatar
3 votes

Arduino Leonardo is not recognized by usb cable in Windows 8

It is highly likely that the sketch you loaded is causing this. However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few ...
Nick Gammon's user avatar
  • 37.6k
3 votes
Accepted

RF24 tranceivers: trouble with two way communication

The main thing that I can see wrong with your sketch is that the logic of your methodology is backwards. You are spending most of your time either with the radio asleep, or not in listening mode, so ...
Majenko's user avatar
  • 105k
3 votes

Pinout for Leonardo USB

As shown in the ATmega32U4 datasheet, D- and D+ connect to pins 3 and 4 respectively of the MCU. But you don't want to wire directly to the chip unless you know what you are doing since the chip does ...
Ignacio Vazquez-Abrams's user avatar

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