Using the IoT Button with NeoPixel BFF with Arduino involves plugging the breakout into your Arduino-compatible QT Py or Xiao form factor board, installing the Adafruit_NeoPixel and Adafruit_IO_Arduino libraries, and running the provided example code.
Wiring
Plug an IoT Button with NeoPixel BFF into your QT Py or Xiao form factor board exactly as shown below. Here's an example of connecting a QT Py ESP32-S2 to the BFF.
Connect the QT Py ESP32-S2 with pin headers into the IoT Button with NeoPixel BFF with socket headers. They should be plugged in with the backs of the boards facing each other.
For more information on soldering socket headers, check out this Learn Guide.
Library Installation
You can install the Adafruit NeoPixel and Adafruit IO Arduino libraries for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit NeoPixel and select the Adafruit NeoPixel library:
Then, search for the Adafruit IO Arduino library:
If asked about dependencies for any of the libraries, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
// SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT // Basic IoT Button with NeoPixel BFF Demo #include <Adafruit_NeoPixel.h> #define LED_PIN A3 #define BUTTON_PIN A2 #define LED_COUNT 1 int buttonState = 0; Adafruit_NeoPixel pixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { pinMode(BUTTON_PIN, INPUT); pixel.begin(); pixel.show(); pixel.setBrightness(50); } void loop() { //pixel.clear(); buttonState = digitalRead(BUTTON_PIN); if(buttonState == HIGH) { pixel.setPixelColor(0, pixel.Color(150, 0, 0)); pixel.show(); } if(buttonState == LOW) { pixel.setPixelColor(0, pixel.Color(0, 0, 0)); pixel.show(); } }
Upload the sketch to your board. Press the button and you will see the NeoPixel light up red.
Before running this code, be sure to review the Welcome to Adafruit IO Learn Guide.
// SPDX-FileCopyrightText: 2016 Todd Treece, Adapted 2023 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT // Adafruit IO IoT Button with NeoPixel BFF Demo // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing // products from Adafruit! // // Written by Todd Treece for Adafruit Industries // Copyright (c) 2016 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. /************************** Configuration ***********************************/ // edit the config.h tab and enter your Adafruit IO credentials // and any additional configuration needed for WiFi, cellular, // or ethernet clients. #include "config.h" #include <Adafruit_NeoPixel.h> /************************ Example Starts Here *******************************/ #define BUTTON_PIN A2 #define LED_PIN A3 #define LED_COUNT 1 Adafruit_NeoPixel pixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // button state bool current = false; bool last = false; // set up the 'digital' feed AdafruitIO_Feed *digital = io.feed("digital"); void setup() { pixel.begin(); pixel.show(); pixel.setBrightness(50); pixel.setPixelColor(0, pixel.Color(150, 0, 0)); pixel.show(); // set button pin as an input pinMode(BUTTON_PIN, INPUT); // start the serial connection Serial.begin(115200); // wait for serial monitor to open while(! Serial); // connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); // wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500); } // we are connected Serial.println(); Serial.println(io.statusText()); pixel.setPixelColor(0, pixel.Color(0, 150, 0)); pixel.show(); } void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); // grab the current state of the button. // we have to flip the logic because we are // using a pullup resistor. if(digitalRead(BUTTON_PIN) == LOW){ current = true; pixel.setPixelColor(0, pixel.Color(0, 0, 150)); pixel.show(); } else { current = false; pixel.setPixelColor(0, pixel.Color(0, 150, 0)); pixel.show(); } // return if the value hasn't changed if(current == last) return; // save the current state to the 'digital' feed on adafruit io Serial.print("sending button -> "); Serial.println(current); digital->save(current); // store last button state last = current; }
Edit the included config.h file with your Adafruit IO username, Adafruit IO key, SSID name and SSID password. Save the file and then upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. While your board is connecting to Adafruit IO, you'll see "Connecting to Adafruit IO...
" print in the Serial Monitor. After establishing a connection, "Adafruit IO connected.
" will print.
When you press the button, a value of 0
or 1
will be sent to Adafruit IO and will print to the Serial Monitor. You'll be able to see this data in your feed on Adafruit IO.
The NeoPixel acts as an Adafruit IO status light. Before connecting to Adafruit IO, the NeoPixel is red. If your board is connected, the NeoPixel is green. If your board is actively uploading data to Adafruit IO, the NeoPixel is blue.
Text editor powered by tinymce.