104

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 "master" device, which initiates communications and supplies the clock which controls the data transfer rate. There can be one or more slaves. For more than ...


24

Those aren't the only frequencies available for the PWM signals. However, they are the frequencies as determined by the applied prescaler (which you can readily change as detailed below). Each of the 3 pairs of PWM pins is tied to one timer, each of which has its own base frequency, as follows: Pins 5 and 6 are paired on timer0, with base frequency of ...


8

I am not aware of the design considerations, but if you check the datasheet for the microcontroller on your Arduino, you will notice that PWM pins are grouped together and per group connected to a timer. The speed at which this timer is increased varies by the configured prescaler. If you change the prescaler for a certain timer, you change the PWM frequency ...


8

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. Ohm's Law defines the relationship between Voltage (V), Current (I) and Resistance (R). R = V/I To find one unknown value (in your case R) you need to know ...


7

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 source, I do not think it has anything to do with electromagnetic interference. In my experience, the internal pullup is perfectly reliable for reading switches ...


6

Reading the answer from Gerben I realised the core of the issue: The TX/RX LED's on the Leonardo are wired PIN-LED-5V(common anode), whereas on the Olimexino-32U4 they are wired PIN-LED-GND(common cathode). So the two boards will need inverse signals for the same visual output. Compare: http://arduino.cc/en/uploads/Main/arduino-leonardo-schematic_3b.pdf ...


6

int A0, A1,A2,A3,A4; delay(200); A0= analogRead(A0); A1= analogRead(A1); A2= analogRead(A2); A3= analogRead(A3); A4= analogRead(A4); Your local variables (A0 through A4) are shadowing the global variables for the pins (A0 through A4). Give your local variables different names.


6

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 (or, run a jumper wire from the RESET pin to the GND pin). This stops the problem sketch from starting. Still holding down Reset, reconnect the USB cable. Start ...


6

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/b7c607663fecc232e598f2c0acf419ceb0b7078c/cores/arduino/USBAPI.h#L129 From USBAPI.h: // These return the settings specified by the USB host for the // serial port. ...


6

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 see what it prints: Serial.println(A0); And for your pins, just put A0, A1, etc. in your int array and leave the quotes off. Those symbols are being ...


5

The Atmel ATmega328 datasheet, section 24.6.1, recommends that you drive the analog input pin with an output impedance of 10 KOhm or less. Also, it recommends that you remove high-frequency components with a low-pass filter. (That low-pass is sometimes called an antialiasing filter). The simplest possible low-pass filter is a resistor and a capacitor. +...


5

The teensy series from pjrc.com allows USB MIDI natively (full USB speed!). It works well and does not require any firmware tomfoolery. It can also do HID keyboard/mouse/joystick natively as well. There's the 2.0, which is 32u4, and the 2.0++ which has more pins and memory. If you want to step off the Atmel reservation the teensy 3.0 and 3.1 have more ...


5

You could do a qsort. You haven't posted any data types so it is hard to answer with your specific code, however here is a sample of sorting numbers: const int COUNT = 10; int someNumbers [COUNT] = { 7342, 54, 21, 42, 18, -5, 30, 998, 999, 3 }; // callback function for doing comparisons int myCompareFunction (const void * arg1, const void * arg2) { ...


5

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 the keyboard the key is. It is then up to the computer to convert those scan codes into actual letters and symbols, and that is performed by the keyboard ...


5

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 schematic you can see it is pins 3 and 4 on the chip. Note that that is not pins D3 and D4 on the board, but the third and fourth pins anti-clockwise from the "pin 1"...


5

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: Keyboard.press(KEY_LEFT_GUI); Keyboard.press('e'); Keyboard.releaseAll(); This is equivalent to shortcut keys Win + E. The modifier GUI is what stands in for ...


5

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 first use #include <Arduino.h> on the top #include <Wire.h> if you are using Wire and so on and you have "normal" CPP file. If you are making ...


5

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 Comparison table.


5

Welcome to SE. digitalWrite() takes a few microseconds to execute as well. There is also some overhead around the delayMicroseconds() function. I you need exactly 500 kHz, you would want to consider using a timer. You can read up on how to set one up in the microcontrollers datasheet. Unfortunately, I don't have access to an Arduino Leonardo, but here is ...


4

This is because on ATmega 32u4, which is used in Arduino Leonardo, pins 5 and 7 are not mapped to port D but to port C and E respectively, as you can see in the ATmega 32u4 - Arduino Pin Mapping. So you will have to: either find another port where all 8 bits are available as digital outputs (note that I'm not sure one such port exists) or split each sine[...


4

The documentation for that library is recommending that you place a 100 pF capacitor between the sense pin and ground. However, I personally suspect you will get the best results when the user's presence affects at small mutual capacitance between a sense surface and a ground surface. One idea could be to have a large ground plane, and on it a smaller ...


4

Please note the SPI clock will only be active while it is shifting data. So simply put the spi.transfer in a hard loop #include <SPI.h> void setup() { SPI.begin(); while (1) { SPI.transfer(0x00); } }


4

Motors draw large amounts of current, and will either cause your power supply voltage to sag if you draw more current than your power supply can support, or cause blips in the power supply that will cause you all sorts of problems. You need to take steps to isolate the power from the motor shield from the power for the Arduino. How are you powering the ...


4

As somebody else suggested, 9V batteries are pretty weak. They only provide a very small number of mAh (milliamp/hours) before their voltage starts to drop. Once the voltage drops to around 7 volts, the regulator in the Arduino can't keep providing 5 volts, so your Arduino resets. Wire up 6 AA batteries in series. That will provide a much "stiffer" 9 volt ...


4

Power steering is performed by the assembly labelled "+5V AUTO SELECTOR" at the bottom of the page. The voltage at VIN is halved and then compared with the board's 3.3V output in order to determine whether or not to enable USB power via T1.


4

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 the internal pull-ups: digitalWrite(A4, LOW); digitalWrite(A5, LOW); or digitalWrite(2, LOW); digitalWrite(3, LOW);


4

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 external pull-up: 2.2 k external pull-up: As Majenko pointed out, leaving the internal pull-ups enabled would give you a pull-up between 4.7 k and 2.2 k. And ...


4

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 serial port at 1200 baud and closing it again) which avrdude doesn't have. Basically you need a different way to reset the board so it enters the bootloader. ...


4

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 into flash. In Arduino core CDC.cpp we can see that CDC not only waiting baudrate 1200, but CDC checking DTR value. If DTR goes high, CDC cancels to jump into ...


4

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.


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