Hey guys,
This is pretty much the first time I've ever attempted something like this, I don't have much knowledge on this type of stuff. But I feel like I'm overlooking something simple or small, so I came here for help.
I'm trying to make it to where a servo is rotated when a command is typed into my Twitch chat to trigger a feeder for my ducks.
The bot enters chat fine with "Ready to go Boss!"
but that's all I get, it compiles fine in IDE though.
Using the ESP8266 and the servo on a breadboard with yellow signal wire on D1, red power on VIN, and brown on GND. I've also used a 5V power supply for bread boards and tried attaching the red power wire to it, after verifying it was giving me 5V DC.
With red power connected to VIN, the servo moves to a fixed location and refuses to move either way, this only happens when yellow signal is connected to D1, unplugged or in another port the servo moves freely by hand.
This is the servo
https://www.amazon.com/gp/product/B07MFK266B/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1
This is the ESP8266
It would only let me post 2 links, if you need the breadboard and power supply links let me know and ill see if i can post more in the comments.
Any help or input helping me understand this and get this working would be amazing!
Thank you all for any help you have to offer!
This is the code
/*******************************************************************
Connect to Twtich Chat with a Bot
Created with code from TheOtherLoneStar (https://www.twitch.tv/theotherlonestar)
Hackaday IO: https://hackaday.io/otherlonestar
By Brian Lough (https://www.twitch.tv/brianlough)
YouTube: https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
Created with code from noycebru www.twitch.tv/noycebru
*******************************************************************/
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <IRCClient.h>
#include <Servo.h>
Servo servo;
//define your default values here, if there are different values in config.json, they are overwritten.
#define secret_ssid "my ssid"
#define IRC_SERVER "irc.chat.twitch.tv"
#define IRC_PORT 6667
//------- Replace the following! ------
char ssid[] = "Duckberg"; // your network SSID (name)
char password[] = "********"; // your network key
//The name of the channel that you want the bot to join
const String twitchChannelName = "duckbergducks"; //this is case sensitive!
//The name that you want the bot to have
#define TWITCH_BOT_NAME "duckbergbot"
//OAuth Key for your twitch bot
// https://twitchapps.com/tmi/
#define TWITCH_OAUTH_TOKEN "oauth:******************************"
//------------------------------
int feeder = 5;
String ircChannel = "";
WiFiClient wiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient);
// put your setup code here, to run once:
void setup() {
pinMode(feeder, OUTPUT);
servo.attach(5);
servo.write(0);
delay(2000);
Serial.begin(115200);
Serial.println();
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
ircChannel = "#" + twitchChannelName;
client.setCallback(callback);
}
void loop() {
// Try to connect to chat. If it loses connection try again
if (!client.connected()) {
Serial.println("Attempting to connect to " + ircChannel );
// Attempt to connect
// Second param is not needed by Twtich
if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN)) {
client.sendRaw("JOIN " + ircChannel);
Serial.println("connected and ready to rock");
sendTwitchMessage("Ready to go Boss!");
} else {
Serial.println("failed... try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
return;
}
client.loop();
}
void sendTwitchMessage(String message) {
client.sendMessage(ircChannel, message);
}
void callback(IRCMessage ircMessage) {
//Serial.println("In CallBack");
if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') {
//Serial.println("Passed private message.");
ircMessage.nick.toUpperCase();
String message("<" + ircMessage.nick + "> " + ircMessage.text);
//prints chat to serial
Serial.println(message);
//this is where you would replace these elements to match your streaming configureation.
if (ircMessage.text.indexOf("!feed") > -1 && ircMessage.nick == "duckbergbot")
{
servo.attach(5);
servo.write(180);
delay(750);
servo.write(0);
delay(1000);
servo.detach();
}
}
return;
}