Differences

This shows you the differences between two versions of the page.

Link to this comparison view

blocks:app-note:arduino-encoder [2023-08-16 13:04] (current)
mattias created
Line 1: Line 1:
 +====== Connecting an Arduino microcontroller to Blocks ======
 +
 +This application note provides an example of how an [[https://en.wikipedia.org/wiki/Rotary_encoder|encoder]] connected to an [[https://www.arduino.cc/|Arduino]] microcontroller can be used to interact with Blocks. It is assumed that the reader is familiar with Arduino concepts, the Arduino IDE and microcontrollers in general.
 +
 +===== Installation =====
 +
 +You need a computer with a running Blocks server and a web browser to use this application note. You also need a separate computer running PIXILAB Player. Here is the [[LINK_TO_BlocksrootZIP|Blocks root]] for this application note, and here is the [[LINK_TO_encoderex.zip|Arduino sketch]] (the Arduino sketch has been tested on an Arduino Nano Every). See the [[blocks:app-note:start|general setup]] article for details on how to download and install the root on your Blocks server.
 +
 +===== Running the example =====
 +
 +  - Open the downloaded Arduino sketch in the Arduino IDE. The Arduino sketch depends on the [[https://github.com/PaulStoffregen/Encoder|Encoder library]], which can be downloaded through the Library Manager in the Arduino IDE.
 +  - Upload the sketch to the Arduino.
 +  - Connect the encoder to digital pins 2 and 3 on the Arduino.
 +  - Connect the Arduino to a computer running PIXILAB Player.
 +  - Start Blocks.
 +  - Open the editor using the Admin button.
 +  - Log in using the name //admin// and the password //pixi//.
 +  - Assign the PIXILAB Player to the //DisplaySpot1// Display Spot.
 +  - Rotate the encoder and observe how the bar shown on the PIXILAB Player Spot moves. The speed depends on the resolution of the encoder. Click the "Set to 0" button to reset the encoder position to 0.
 +
 +===== Behind the scenes =====
 +
 +The PIXILAB Player Spot passes data received from the Arduino to the Blocks server over the network. The //EncoderExample// driver handles the received data and exposes a numeric //position// property, which the bar and the button binds to.
 +
 +The source code for the EncoderExample driver is located in PIXILAB-Blocks-root/script/driver/EncoderExample.ts.