I played around with some scripting last year to get a Wemos D1 to output I think 6 servo outputs. I used it to control my 3D talking skull worked perfect. I am not a programmer and I never cleaned up the code from when I was collaborating and learning with Darren, but here it is.
Code:
// Wemos D1 Mini E1.31 - 6 channel Servo Controller - Tomms first test
#include <ESP8266WiFi.h>
#include <E131.h> // Copyright (c) 2015 Shelby Merrick http://www.forkineye.com
#include <Servo.h>
Servo ch_1_red_Nodd;
Servo ch_1_green_Tilt;
Servo ch_1_blue_Turn;
Servo ch_2_red_Jaw;
Servo ch_2_green_eyehor;
Servo ch_2_blue_eyever;
// ***** USER SETUP STUFF *****
const char ssid[] = "ENTER SSID HERE"; // replace with your SSID.
const char passphrase[] = "PASSWORD HERE"; // replace with your PASSWORD.
const int universe = 8; // this sets the universe number you are using.
// this sets the Universe channel number used by the output.
const int ch_1_red = 0; // the channel number to link to output 1 red.
const int ch_1_green = 1; // the channel number to link to output 1 green.
const int ch_1_blue = 2; // the channel number to link to output 1 blue.
const int ch_2_red = 3; // the channel number to link to output 2 red.
const int ch_2_green = 4; // the channel number to link to output 2 green.
const int ch_2_blue = 5; // the channel number to link to output 2 blue.
// this sets the pin numbers to use as outputs. **FROM OLD RGB CODE** DO WE USE OR DELETE??
//const int output_1_red = 4; // the pin to use as output 1 red (D2).
//const int output_1_green = 5; // the pin to use as output 1 green (D1).
//const int output_1_blue = 12; // the pin to use as output 1 blue (D6).
//const int output_2_red = 13; // the pin to use as output 1 red (D7).
//const int output_2_green = 14; // the pin to use as output 1 green (D5).
//const int output_2_blue = 15; // the pin to use as output 1 blue (D8).
E131 e131;
void setup() {
Serial.begin(115200);
ch_1_red_Nodd.attach(4); // D2
ch_1_green_Tilt.attach(5); // D1
ch_1_blue_Turn.attach(12); // D6
ch_2_red_Jaw.attach(13); // D7
ch_2_green_eyehor.attach(14); // D5
ch_2_blue_eyever.attach(15); // D8
// set the pins chosen above as outputs. **OLD CODE**
//pinMode(output_1_red, OUTPUT);
// pinMode(output_1_green, OUTPUT);
// pinMode(output_1_blue, OUTPUT);
// pinMode(output_2_red, OUTPUT);
//pinMode(output_2_green, OUTPUT);
// pinMode(output_2_blue, OUTPUT);
// set the servos to Mid point
ch_1_red_Nodd.write(90);
ch_1_green_Tilt.write(90);
ch_1_blue_Turn.write(90);
ch_2_red_Jaw.write(90);
ch_2_green_eyehor.write(90);
ch_2_blue_eyever.write(90);
/* Choose one to begin listening for E1.31 data */
//e131.begin(ssid, passphrase); /* via Unicast on the default port */
e131.beginMulticast(ssid, passphrase, universe); /* via Multicast for Universe 1 */
}
void loop() {
/* Parse a packet */
uint16_t num_channels = e131.parsePacket();
/* Process channel data if we have it */
if (num_channels) {
Serial.println("we have data");
Serial.println(e131.data[ch_1_red -1]);
Serial.println(e131.data[ch_1_green -1]);
Serial.println(e131.data[ch_1_blue -1]);
Serial.println(e131.data[ch_2_red -1]);
Serial.println(e131.data[ch_2_green -1]);
Serial.println(e131.data[ch_2_blue -1]);
// set the outputs to the data value. **OLD CODE FOR DUMB RGB**
//analogWrite(output_1_red, (e131.data[channel_1_red -1] *4));
//analogWrite(output_1_green, (e131.data[channel_1_green -1] *4));
//analogWrite(output_1_blue, (e131.data[channel_1_blue -1] *4));
// analogWrite(output_2_red, (e131.data[channel_2_red -1] *4));
//analogWrite(output_2_green, (e131.data[channel_2_green -1] *4));
// analogWrite(output_2_blue, (e131.data[channel_2_blue -1] *4));
// Set output to servo **NEW CODE** will this work???
if ((e131.data[ch_1_red] >= 0) or (e131.data[ch_1_red] <= 180)) {
if (e131.data[ch_1_red] == 0 ) {
ch_1_red_Nodd.write(90);
}
else {
ch_1_red_Nodd.write(e131.data[ch_1_red]);
// Serial.println("Nodd");
}
};
if ((e131.data[ch_1_green] >= 0) or (e131.data[ch_1_green] <= 180)) {
if (e131.data[ch_1_green] == 0 ) {
ch_1_green_Tilt.write(90);
}
else {
ch_1_green_Tilt.write(e131.data[ch_1_green]);
// Serial.println("Tilt");
}
};
if ((e131.data[ch_1_blue] >= 0) or (e131.data[ch_1_blue] <= 180)) {
if (e131.data[ch_1_blue] == 0 ) {
ch_1_blue_Turn.write(90);
}
else {
ch_1_blue_Turn.write(e131.data[ch_1_blue]);
// Serial.println("Turn");
}
};
if ((e131.data[ch_2_red] >= 0) or (e131.data[ch_2_red] <= 180)) {
if (e131.data[ch_2_red] == 0 ) {
ch_2_red_Jaw.write(90);
}
else {
ch_2_red_Jaw.write(e131.data[ch_2_red]);
// Serial.println("Jaw");
}
};
if ((e131.data[ch_2_green] >= 0) or (e131.data[ch_2_green] <= 180)) {
if (e131.data[ch_2_green] == 0 ) {
ch_2_green_eyehor.write(90);
}
else {
ch_2_green_eyehor.write(e131.data[ch_2_green]);
// Serial.println("Eyehor");
}
};
if ((e131.data[ch_2_blue] >= 0) or (e131.data[ch_2_blue] <= 180)) {
if (e131.data[ch_2_blue] == 0 ) {
ch_2_blue_eyever.write(90);
}
else {
ch_2_blue_eyever.write(e131.data[ch_2_blue]);
// Serial.println("Eyever");
}
};
// ***** Repeat for each channel if this is correct******
}
}
Bookmarks