Hi all, new to this and not sure if it is posted in the right section.
My end goal is to take an S-Video signal (converted from RGBS) from 16 arcade cabinets and choose any two cabinets via a phone or tablet to feed into a Twitch stream for the Australian Kong Off (Donkey Kong ) competition.
I started with an Arduino Uno (Wifi) and connected it to an Arduino compatible 8 Channel Relay Board and followed the instructions on the related project in GitHub and all worked fine.
My issue is that I need to expand the project out to 32 relays to control the PCB I have built.
The are 16 rows of two relays, the first relay turns the input on and the second relay selects either channel A (normally closed contacts) or B (normally open contacts). At any one time there will only be three relays turned on.
So I purchased an Arduino Mega2560 (Wifi) and uploaded the project the same as with the Uno and this is where I ran into problems. I could see and connect to the Wifi hotspot with my phone but the webpage wouldn't load like it did with the Uno.
I then tried the example code that is linked with the Mega and it worked fine on the Mega as well as the Uno.
Example Code:
Arduino:
#define SERIAL_BAUD 115200
/*******************************************
In this code we have used "[]" to surround our command codes
As a bit of a proof of concept for how to use the XC4411 board
*********************************************/
const int led_pin = 13;
String receivedCommand = "";
bool dataIn = false;
void setup()
{
// put your setup code here, to run once:
Serial.begin(SERIAL_BAUD); //same as ESP baud
pinMode(led_pin, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
while (Serial.available())
{
char c = Serial.read(); //read it
if (c == '[')
{
//this is the start of the command string
receivedCommand = "";
dataIn = true;
}
//otherwise, we are still reading the command string:
else if (dataIn && c != ']')
{
receivedCommand += c;
}
else if (dataIn && c == ']')
{
//finished receiving the command, process it
Serial.print("XC4411 has been running for ");
Serial.print(millis(), DEC);
Serial.println(" milliseconds..");
Serial.print("Received command was '");
Serial.print(receivedCommand);
Serial.print("' - action: ");
if (receivedCommand == "LEDON")
{
Serial.println("TURN LED ON");
digitalWrite(led_pin, HIGH);
}
else if (receivedCommand == "LEDOFF")
{
Serial.println("TURN LED OFF");
digitalWrite(led_pin, LOW);
}
else if (receivedCommand == "LEDTOGGLE")
{
Serial.println("CHANGE LED");
digitalWrite(led_pin, !digitalRead(led_pin));
}
Serial.println("---------------------------------------");
}
}
delay(10);
}
ESP Code:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#define SERIAL_BAUD 115200 //make sure this is the same in arduino.ino
ESP8266WebServer server(80);
String serialData = "";
//this is our HTML website that we send to the user, much easier to use SPIFFS in future.
const String html_page = "<!DOCTYPE html>"
"<html>"
" <head>"
" <meta name='viewport' content='width=device-width, initial-scale=1.0' />"
" </head>"
" <body>"
" <a href='/ledon'>turn LED on</a>"
" <a href='/ledoff'>turn LED off</a>"
" <h1>Latest data from arduino:</h1>"
" <pre id='reading'></pre>"
" <script>"
" (function() {"
" /* get new data every second*/"
" setInterval(function() {"
" fetch('/reading')"
" .then(response => { return response.text();})"
" .then(text => {"
" document.getElementById('reading').textContent = text;"
" });"
" }, 100);"
" })();"
" </script>"
" </body>"
"</html>";
const IPAddress serverIPAddress(10, 0, 0, 7);
void setup(void)
{
Serial.begin(SERIAL_BAUD);
//here we set up as a hot spot, called XC4411 dual board
WiFi.softAPConfig(serverIPAddress, serverIPAddress, IPAddress(255, 255, 255, 0));
WiFi.softAP("XC4411 Dual Board example code");
//here we set server paramters, the main page is the html_page from above
server.on("/", []() { //send html code, from above
server.send(200, "text/html", html_page);
});
//reading is just a copy of the serial Data
server.on("/reading", []() { //send raw serial data
Serial.println();
Serial.println(serialData);
server.send(200, "text/plain", serialData);
});
server.on("/ledon", []() {
Serial.println("[LEDON]"); //send serial data to arduino
server.send(200, "text/plain", "ok");
});
server.on("/ledoff", []() {
Serial.println("[LEDOFF]"); //send serial data to arduino
server.send(200, "text/plain", "ok");
});
server.on("/ledtoggle", []() {
Serial.println("[LEDTOGGLE]"); //send serial data to arduino
server.send(200, "text/plain", "ok");
});
server.onNotFound(handleNotFound);
server.begin();
}
void loop(void)
{
while (Serial.available())
{
char x = Serial.read();
if (x == '\r')
continue;
serialData += x;
}
server.handleClient();
}
void handleNotFound()
{
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++)
{
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
I have spent a couple of days trying to get the 8 Channel Relay project to work on the Mega without success, any thoughts?
I have a feeling it has something to do with the serial ports i.e. the Mega has 4 and the Uno only has one??