Box IO

Self-hosted IoT for Arduino and ESP32.

D-pad

Four arrows in a controller pad. Hold an arrow to write its pin. Let go to write the released value.

Sample pin: V1 up, V2 right, V3 down, V4 left

Set it up on the server

  1. Sign in to the Box IO dashboard and open the project that uses this device key.
  2. Turn on Edit.
  3. In Edit, add D-pad.
  4. Set Up pin, Right pin, Down pin, and Left pin. Each arrow uses its own virtual pin. Adding a D-pad picks four free pins.
  5. Set Value when pressed and Value when released. The usual pair is 1 while held and 0 when released.
  6. Set Pressed color and Pad color if you want different colors than the defaults.
  7. Save the layout, then open Live. Holding an arrow writes that pin. Releasing it writes the released value. Edit shows the pin number on each arm.
  8. Flash the sketch below with the same device key, host, and port 5923. Keep BoxIO.run() in loop().

Properties

Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").

PropertyWhere to set itFormatExampleEffect
pinUpDashboardVirtual pin 0 to 1271Pin written by the up arrow. The widget pin matches this one.
pinRightDashboardVirtual pin 0 to 1272Pin written by the right arrow.
pinDownDashboardVirtual pin 0 to 1273Pin written by the down arrow.
pinLeftDashboardVirtual pin 0 to 1274Pin written by the left arrow.
onValueDashboardText sent while held1Written to that arrow’s pin on press.
offValueDashboardText sent when released0Written to that arrow’s pin when the pointer leaves the arrow.
colorOnDashboard#RRGGBB#2ee0c5Color of an arrow while it is held, or while its pin matches the pressed value.
colorOffDashboard#RRGGBB#314057Color of the pad and of arrows that are not held.
labelDashboard or sketchPlain textPumpCaption above the widget, taken from the label saved on that widget. A sketch setProperty for label does not rename it. On a round or oval button this is the caption, not the word on the button face.
hideLabelDashboardOn or offcheckedHides the caption. Button face text, meter numbers, and label text stay visible.
fontSizeDashboardWhole number 8 to 160, or blank for automatic size28Text size in pixels inside the widget.
opacityDashboard10% to 100%70%Lets an overlapping widget show through. 100% is solid.

Formatting

Sketch

Paste the device key over bx_paste_your_device_key_here. Wi-Fi boards include BoxIOEsp32.h. Ethernet boards use the same calls with an EthernetClient.

#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID  "your-ssid"
#define WIFI_PASS  "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923

#include <BoxIOEsp32.h>

void setup() {
  BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);

}

void loop() {
  BoxIO.run();

}

BOX_WRITE(V1) {
  // Up. param.asStr() is 1 while held, 0 when released.
  Serial.print("up ");
  Serial.println(param.asStr());
}

BOX_WRITE(V2) {
  Serial.print("right ");
  Serial.println(param.asStr());
}

BOX_WRITE(V3) {
  Serial.print("down ");
  Serial.println(param.asStr());
}

BOX_WRITE(V4) {
  Serial.print("left ");
  Serial.println(param.asStr());
}

What you should see

Holding up writes 1 to V1. Releasing writes 0. The other three arrows do the same on their own pins. The held arrow lights with the pressed color.