WeMos AP with WS2811 RGB

Parts

  • WeMos D1 WiFi ESP8266 UNO IOT Development Board
  • WS2811 RGB pixels

Step One:

To set up this board with the Arduino IDE, you must first place this link in File > Preferences > Additional Boards Manager URLs: (Ctrl+Comma)

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Step Two:

Then go to Tool > Boards > Boards Manager:

Scroll down until you see esp8266 by ESP8266 Community and install it. Make sure it lists WeMos D1 R1 as shown below in the screenshot.

Step Three:

Make sure you have the CH341 Driver installed before plugging your board into your computer. After that is complete, Plug in your board and let it install the drivers needed.

Step Four:

In the menu of the Arduino IDE open Tools > Port and select your correct COM Port for the board.

In the menu of the Arduino IDE open Tools > Boards > and select WeMos D1 R1

Step Five:

Wire up your WS2811 RGB’s

These only have a 5V Positive, Negative, and one Digital Line connected to D12

Step Six:

Upload this code to your board and Change the SSID/Password, NeoPixel Pin number if using another, and the number of RGB’s you’re going to use. In this Sketch, I’m using 10 RGB’s

// call esp8266 LIB
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

// call Adafruit_NeoPixel LIB and settings
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 12 // D12 neopixel data line

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800); // how many RGBs

String rgbcolor = "none";

// access point settings

const char *ssid = "esphack";
const char *password = "12345678";
int stateLED = LOW;

// start port
ESP8266WebServer server(8181);

// handel request for http://192.168.4.1:8181/
void handleRoot() {
response();
}

// settings for tuning on the onbard LED
void handleLedOn() {
stateLED = LOW;
digitalWrite(LED_BUILTIN, stateLED);
response();
}

// settings for tuning off the onbard LED
void handleLedOff() {
stateLED = HIGH;
digitalWrite(LED_BUILTIN, stateLED);
response();
}

// settings for tuning the RGBs blue
void handlergbblue() {
rgbcolor = "blue";
colorWipe(strip.Color(0, 0, 255), 50); // blue

response();
}

// settings for tuning the RGBs red
void handlergbred() {
rgbcolor = "red";
colorWipe(strip.Color(0, 255, 0), 50); // red

response();
}

// settings for tuning the RGBs white
void handlergbwhite() {
rgbcolor = "white";
colorWipe(strip.Color(255, 255, 255), 50); // white

response();
}

// settings for tuning the RGBs off
void handlergboff() {
rgbcolor = "off";
colorWipe(strip.Color(0, 0, 0), 1); // off

response();
}

// setting up the https responce/buttons for LED & RGBs
const String HtmlHtml = "<html><head>"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head>";
const String HtmlHtmlClose = "</html>";
const String HtmlTitle = "
<h1>Hack's ESP8266 AP for Neopixles</h1>

\n";
const String HtmlLedStateLow = "<big>LED is now <b>LED On</b></big>
\n";
const String HtmlLedStateHigh = "<big>LED is now <b>LED Off</b></big>
\n";

const String rgbstatered = "<big>RGBs are now <b>Red</b></big>
\n";
const String rgbstatewhite = "<big>RGBs are now <b>White</b></big>
\n";
const String rgbstateblue = "<big>RGBs are now <b>Blue</b></big>
\n";
const String rgbstateoff = "<big>RGBs are now <b>Off</b></big>
\n";

const String HtmlButtons =
"<a href=\"LEDOn\"><button style=\"display: block; width: 100%;\">On</button></a>
"
"<a href=\"LEDOff\"><button style=\"display: block; width: 100%;\">Off</button></a>
"

"<a href=\"off\"><button style=\"display: block; width: 100%;\">RGBs Off</button></a>
"
"<a href=\"red\"><button style=\"display: block; width: 100%;\">Red</button></a>
"
"<a href=\"white\"><button style=\"display: block; width: 100%;\">White</button></a>
"
"<a href=\"blue\"><button style=\"display: block; width: 100%;\">Blue</button></a>
";

// setup and send the responce when called
void response(){
String htmlRes = HtmlHtml + HtmlTitle;

if(stateLED == LOW){
htmlRes += HtmlLedStateLow;
}

if(stateLED == HIGH){
htmlRes += HtmlLedStateHigh;
}

if(rgbcolor == "blue"){
htmlRes += rgbstateblue;
}

if(rgbcolor == "red"){
htmlRes += rgbstatered;
}

if(rgbcolor == "white"){
htmlRes += rgbstatewhite;
}

if(rgbcolor == "off"){
htmlRes += rgbstateoff;
}

htmlRes += HtmlButtons;
htmlRes += HtmlHtmlClose;

server.send(200, "text/html", htmlRes);
}

void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();

// starting neopixels
strip.begin();
strip.show();

// stating the access point
WiFi.softAP(ssid, password);

IPAddress apip = WiFi.softAPIP();
Serial.print("visit: \n");
Serial.println(apip);
server.on("/", handleRoot);

// what to watch for and what to call for said keywords
server.on("/red", handlergbred);
server.on("/white", handlergbwhite);
server.on("/blue", handlergbblue);
server.on("/off", handlergboff);

server.on("/LEDOn", handleLedOn);
server.on("/LEDOff", handleLedOff);
server.begin();
Serial.println("HTTP server beginned");
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, stateLED);
}

void loop() {
server.handleClient();
}

// neopixel funtion
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

Step Seven:

Connect to the WIFI using a SmartPhone, Tablet/iPad, or Laptop and point a web browser to http://192.168.4.1:8181/ to load the page.

Facebook Comments