Using the input sensors and output actuators built onto the Esplora board is a little different than using the general inputs and outputs on other Arduino boards. As a result, the example sketches included with the Arduino IDE need a little modification before you can use them with the Esplora. This guide explains how to do it.
On this page... (hide)
You need to add the Esplora library to any sketch you want to use on the Esplora. To do so, choose Import Library... -> Esplora from the Sketch menu and the IDE will automatically add the following at the top of your sketch:
The other Arduino boards have two types of inputs: digital inputs, which have only two states, HIGH or LOW, and analog inputs, which have a varying range of states, typically from 0 to 1023. The pushbuttons on the Esplora are digital inputs, and the other sensors are analog inputs. To adapt the regular examples to the Esplora, you can substitute the pushbutton inputs for the digital inputs, and any of the other sensors for the analog inputs.
The digital inputs on the other Arduino boards can also be used as outputs, so they need to be declared as either input or output using a command called pinMode()
. Because all of the Esplora's inputs or outputs are dedicated to one function, you don't need pinMode commands.
Whenever you see the command digitalRead()
in an Arduino example, substitute the command Esplora.readButton()
. Choose whichever button you want to read. Below, you can see the original DigitalReadSerial example (found in File -> Examples -> 01.Basics -> DigitalReadSerial) and the modified version that works on the Esplora using Switch 1:
Original example:
Modified example for use with Esplora:
Most of the Arduino digitalRead() examples are written with the assumption that the pushbutton or switch attached to them will go HIGH when pressed, and LOW when not pressed. The Esplora's pushbuttons go LOW when pressed and HIGH when not pressed. So if you want to read when the Esplora's buttons are pressed, read for LOW instead of HIGH. If you want to read when they're not pressed, read for HIGH instead of LOW.
For most Arduino examples, LEDs are used as digital outputs, meaning that you can only turn them on or off (HIGH or LOW). The RGB LED on the Esplora, however, is used as an analog output, meaning that you can set its brightness from 0 to 255. To make it act like a digital output, set its level to 255 for HIGH and 0 for LOW.
Below, you'll see the Button example (found in File -> 02.Digital -> Button) in its original and modified forms:
Original example: Highlit lines will change. Pin constants and pinMode() commands will go away because they're not needed.
Modified example for use with Esplora:
You don't have to use only the red LED channel; you can use any of the RGB channels as digital outputs in this way. Likewise, you can use any of the pushbuttons to replace digital inputs.
Changes to analog examples are similar to the digital ones. There's no pinMode() commands to remove, however, because the analog inputs on the other Arduino boards are inputs by default.
Here's another example, this time replacing an analog input with one the Esplora's analog inputs. The ReadAnalogVoltage example (found in File -> 01.Basics -> ReadAnalogVoltage) reads an analog input and tells you the voltage on the pin. Below, you'll replace the analogRead()
command with the reading from the light sensor:
Original example:
Modified example for use with Esplora:
Most of the analog sensors on the Esplora can be substituted for analogRead()
statements as-is, because they are simply that: analog sensors. The joystick is made of two potentiometers, so you can think of each of its axes as a single analogRead()
. Similarly, the accelerometer can be thought of three analogRead()
channels, one for each axis.
The temperature sensor on the Esplora is different from the other analog sensors, however. The Esplora.readTemperature()
command doesn't simply give you the analog reading like the other sensor commands do. Instead, it converts the sensor's reading to Celsius or Fahrenheit. So you can't simply substitute the temperature sensor for an analogRead()
command.
The analogWrite()
command on other Arduinos works only on certain pins. Its range is from 0 to 255, just like the Esplora.writeRed()
, Esplora.writeGreen()
, and Esplora.writeBlue()
commands, so you could replace analogWrite()
statements with any of these three commands and see a working result. Note that analogWrite()
takes two parameters, a pin number and a brightness level, while the Esplora.writeRed()
and related commands only take one parameter, the brightness. Below you can see the Fade example (found in File -> Examples -> 01.Basics -> Fade) in its original and modified forms:
Original example: pinMode()
command will be cut, as it's not needed.
Modified example for use with Esplora:
Serial communication over USB using the Serial.read()
, Serial.write()
, Serial.print
and Serial.println()
commands should work on the Esplora just the same as they do on other boards. However, the serial output of the Esplora works slightly faster than the Uno, so you might want to add a short delay to sketches that do nothing but read a sensor and serially print the result, so as not to fill your computer's serial input buffer. When your computer's serial buffer fills up, the Serial Monitor will run much slower, and you'll experience a delay when you change windows from it to the main IDE. A delay of even 1 millisecond will work fine.
You can also use the USB Mouse and Keyboard libraries on the Esplora. The examples found in File -> Examples -> 09.USB will work with only modifications for digital and analog I/O, as described above. There's an example for the Esplora called EsploraJoystickMouse that lets you use the joystick as a mouse controller as well.
The other Arduinos offer two other forms of serial communication, SPI (using the SPI library) and I2C (using the Wire library). The Esplora can communicate via SPI using the ICSP header that's also used for optional in-circuit serial programming of the board. The ICSP connector's pins are laid out as follows. Pin 1 is the pin nearest the white dot on the Esplora board. It's the bottom right pin if you're holding the Esplora with the USB connector facing up:
To connect an SPI device to the Esplora, you'll have to make your own connector cable for this connector.
The Esplora doesn't expose pins to provide for I2C communication, so you won't be able to use examples that use the Wire library with the Esplora.
Generally, if you need SPI or I2C connectivity, you're better off using another model of Arduino.
Once you've mastered the Esplora, if you're looking for other Arduino boards to try, the next best step is the Arduino Uno, which is the heart of the Arduino line. It allows you to connect your own sensor and actuator circuits, or add-on shields for expanded capability. You might also want to consider the Arduino Leonardo. It's based on the same processor as the Esplora, and can likewise act as a USB keyboard or mouse. It offers all of the functionality of the regular Arduino boards as well. The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain.