All the rotary encoder examples in this repository are based on the circuit below:
Figure 1. Rotary encoder attached to a MKR board. The pushbutton is connected to digital pin 5, and has a 10-kilohm pulldown resistor attached to it. The two pins of the rotary encoder are attached to digital pins 0 and 1.
Further examples from this workshop can be found in the Light Projects repository.
Here is the pin diagram for the MKR boards:
Note: Most pins have multiple functions. (PWM) indicates that a pin can be used with the analogWrite
function. (INT) indicates that a pin can be used as an external interrupt.
This physical layout is sometimes referred to as a DIP, or Dual Inline Package. In a DIP package, physical pins are typically numbered from top left to bottom left, then from bottom right to top right. So physical pin 1 has the function Analog in 0, or A0; physical pin 14 has the function D5, or digital I/O 5; physical pin 15 has the function D6, or digital I/O 6; and pin 28 has the function 5V, or 5 volts supplied from the USB input.
The pins you'll use all the time are the third from the top on the right (physical pin 26), Vcc, which outputs 3.3 volts when the board is connected to a USB power source or a battery, and the fourth from top on the right (physical pin 25), GND, which is the ground pin. Remember, voltage is always a relative measurement between two points. The Vcc pin's voltage is measured relative to ground.
Plug your MKR into your breadboard with the top pins in the top row of the board. Connect the GND pin on the right side to the right side ground bus and the VCC pin to the voltage bus. Then connect the bus rows on the right side to their corresponding buses on the left. Figure 4 shows the board connected this way. The figure is rotated counter-clockwise so that the right hand side bus is on the top. Most of the circuit diagrams in these examples will be shown this way.
Figure 3. MKR Zero on a breadoard with Vcc and GND connected to the voltage and ground bus rows. The bus rows are also wired to their counterparts on the opposite side.
A very brief introduction to Bluetooth LE.
Bluetooth LE devices can be either central devices, or peripherals. Peripheral devices offer Bluetooth services that central devices can receive. For example, your fitness device is a peripheral device and the mobile phone or laptop that connects to it is a central device.
Peripherals offer services, which consist of characteristics. For example, a light controller might offer a light service, with four characteristics: red, green, blue, and white channels. Characteristics have values, and central devices can connect to a peripheral and read, write, or subscribe to those changing values.
The MKR 1010 WiFi boards we have been using can also communicate using Bluetooth LE. Here are some links to more information on it:
- An introduction to BLE by me, Alasdair Allan, Don Coleman, and Sandeep Mistry
- Bluetooth LE code samples
- Alasdair, Don, and Sandeep's Bluetooth LE book is excellent
- The ArduinoBLE library, which was written with this board in mind
- Instructions on upgrading the MKR 1010 firmware
- p5.js, a JavaScript environment designed in the spirit of Processing
- the p5.js web editor
- The p5.ble library by Yining Shi and Jingwen Zhu. Works only on Chrome browser
- A couple of useful BLE apps:
- LightBlue for Android, macOS or iOS
- BlueSee for macOS or iOS
- Bluetility for macOS
- BLE Scanner for Android
- nRF Connect for Android, iOS, and Desktop OSes
- Bluetooth LE Explorer for Windows
- noble, ad BLE framework for node.js