Table of Contents

Connecting an Arduino microcontroller to Blocks

This application note provides an example of how an encoder connected to an 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 Blocks root for this application note, and here is the Arduino sketch (the Arduino sketch has been tested on an Arduino Nano Every). See the general setup article for details on how to download and install the root on your Blocks server.

Running the example

  1. Open the downloaded Arduino sketch in the Arduino IDE. The Arduino sketch depends on the Encoder library, which can be downloaded through the Library Manager in the Arduino IDE.
  2. Upload the sketch to the Arduino.
  3. Connect the encoder to digital pins 2 and 3 on the Arduino.
  4. Connect the Arduino to a computer running PIXILAB Player.
  5. Start Blocks.
  6. Open the editor using the Admin button.
  7. Log in using the name admin and the password pixi.
  8. Assign the PIXILAB Player to the DisplaySpot1 Display Spot.
  9. 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.