Skip to content

Instantly share code, notes, and snippets.

@ajfisher
Last active January 3, 2017 23:51
Show Gist options
  • Save ajfisher/ee6fadcd837a0f46be8d to your computer and use it in GitHub Desktop.
Save ajfisher/ee6fadcd837a0f46be8d to your computer and use it in GitHub Desktop.
Using a pebble watch to control NeoPixel (WS2812 ) LEDs via an ESP8266 controller

This is the general instructions for how to get a pebble watch to talk to an ESP8266 and turn NeoPixels different colours.

Pebble Controlled NeoPixels

Video: https://www.youtube.com/watch?v=BeIQ47WBVXs

Prereqs

  • Pebble watch
  • ESP8266 ESP-01
  • NeoPixel strip (or ring or matrix or single pixel)

Software needed

  • ESPTool
  • ESPlora
  • Pebble SDK and command line tools

Directions

  • Using ESPTool, flash the ESP8266 with NodeMCU development branch (bins are in this gist) so it has WS8212 support.
  • Using ESPlora, change config.lua to have SSID / PASSWORD of your network in them - upload all lua files to the ESP8266
  • Wire up the WS2812 strip so data line is connected to GPIO 2 (change this in server.lua if you use a different pin).
  • Reset the ESP8266 and note it's IP address in ESPlora when it comes up. You should now be able to hit the web server using
curl --data "red=255&green=0&blue=255" http://<IP address>
  • Using CloudPebble, copy app.js contents into the app.js file (make a watch app project and use Pebble JS)
  • Change the HOST IP address to that of your ESP8266
  • Compile and then download the PBW file
  • Use the developer configuration (as documented by Pebble SDK setup) to run:
pebble install watch_led.pbw

That's it - you should be able to hit it as expected.

/**
Pebble - ESP8266 - NeoPixel controller
Author: Andrew Fisher
Licence: MIT
**/
var UI = require('ui');
var ajax = require('ajax');
var HOST = '<<IP>>';
// Connect to the ESP8266 and post the data
function colour_request(r, g, b) {
//console.log("Making request");
//console.log("r:" + r + " g: " + g);
var req = {
url: HOST,
method: 'post',
data: {red:r, green:g, blue:b}
};
//console.log(JSON.stringify(req));
ajax(req,
function(data, status, request) {
console.log(data);
},
function(data, status, request) {
console.log('The ajax request failed: ' + data + status + JSON.stringify(request));
}
);
}
// Make a list of the colours to select
var colours = [
{ title: "OFF", r: 0, g: 0, b: 0, },
{ title: "RED", r: 255, g: 0, b: 0, },
{ title: "GREEN", r: 0, g: 255, b: 0, },
{ title: "BLUE", r: 0, g: 0, b: 255, },
{ title: "YELLOW", r: 255, g: 255, b: 0, },
{ title: "MAGENTA", r: 255, g: 0, b: 255, },
{ title: "CYAN", r: 0, g: 255, b: 255, },
{ title: "WHITE", r: 255, g: 255, b: 255, },
];
// Create the Menu
var menu = new UI.Menu({
sections: [{
title: 'Choose LED colour',
items: colours
}]
});
// Send command when menu item is selected
menu.on('select', function(e) {
colour_request(e.item.r, e.item.g, e.item.b);
});
menu.show();
local module = {}
function module.start()
print("application start")
print("IP address: " .. wifi.sta.getip())
dofile("server.lua")
end
return module
local module = {}
module.SSID = {}
module.SSID["SSID"] = "PASSWORD"
return module
app = require("application")
config = require("config")
require("setup").start()
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

@goliatone
Copy link

@ajfisher: This is really cool, thank you! Could you also provide a simple schematic with the wiring?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment