SyRen Motor Driver & Wifi Control - Problem with Multiple Serial Connections

UPDATED

Hi,

I am driving a large DC motor with the SyRen 50A motor driver from Dimension Engineering. I have the hardware working fine using the serial control, but when I try to combine with my WiFi controls, I’m having issues. I believe the problem is that my WiFi shield is using the Tx1 and Rx1 serial pins and I need to establish the SyRen connection on Tx2 (no Rx on this board). So the help I need is how to establish a second Tx communication on pin 16 of the Arduino Mega.

For context, the two numbers that follow ST.motor refer to the controller board and the motor direction/speed. 1 is always the first number because the SyRen can control multiple motors but I just have the 1. The second number is for direction/speed: -127 is full reverse, 0 is stop, and 127 is full forward.

/*
 WiFi AutoValve control with SyRen and serial communication.  

 SyRen DIP switches: ON/OFF/ON/OFF/ON/ON

 Arduino Tx -> SyRen S1
 SyRen 0v -> GND
 SyRen 5v ->5v
 
 */
#include <SPI.h>
#include <WiFi.h>
#include <SyRenSimplified.h>

const int proxyPin = 40;
const int proxyPin2 = 41;
const int tx2 = 16;          //???????????


SyRenSimplified ST; //Simplified serial mode. Baud 9600, Arduino Tx 1 -> SyRen S1, 0v -> GND


char ssid[] = "Galaxy S6 active 4126";      //  your network SSID (name)
char pass[] = "trsd1733";                  // your network password



int keyIndex = 0;                 // your network key Index number (needed only for WEP)
int proxyState = 0;
int proxyState2 = 0;


int status = WL_IDLE_STATUS;
WiFiServer server(80);



void setup() {
  
  Serial.begin(9600);      

  SyRenTXPinSerial.begin(9600); // make sure DIP switches are correct : https://www.dimensionengineering.com/datasheets/SyrenDIPWizard/nonlithium/serial/simple/single.htm


  ////////////////////////////// Hardware I/O /////////////////////////////////
  
  pinMode(????, OUTPUT);    //???????????????
  pinMode(proxyPin, INPUT);
  pinMode(proxyPin2, INPUT);
  
////////////////////////////////// WiFi Startup /////////////////////////////////

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status
}




void loop() {

/////////////////////////////////// WiFi loop ////////////////////////////////////

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character


    //////////////////////////////// Interface Design /////////////////////////////////////

          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

           
            client.print("<title>");
               client.print("AutoValve Control Page");
            client.print("</title>");
            
            client.print("

");
            
            client.print("<head>");
               client.print("<div style='font-size:60px'>");
                  client.print("<center> AutoValve Control Page </center>");
               client.print("</div>");
            client.print("</head>");
            
            client.print("

");
            
            // the content of the HTTP response follows the header:
            client.print("<body>");
                 client.print("<div style='font-size:60px'>");
                    client.print("<center> <a href=\"/Open\">OPEN</a> </center>");
                    client.print("
");
                    client.print("<center> <a href=\"/Close\">CLOSE</a> </center>");
                 client.print("</div>");
                 client.print("

");

             
                if (proxyState == LOW){
                  client.print("<div style='font-size:45px'>");
                     client.print("<center> Current Position: CLOSED </center>");
                  client.print("</div>");
               }
               
               if (proxyState2 == LOW){
                  client.print("<div style='font-size:45px'>");
                      client.print("<center>  Current Position: OPEN </center>");
                  client.print("</div>");
               }

           client.print("</body>");

             
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }



 ///////////////Hardware control loop//////////////////////////

 ST.motor(1,0); 
 delay(2000);    //delay 2s for debugging
 ST.motor(1,0);

 proxyState = digitalRead(proxyPin);
 proxyState2 = digitalRead(proxyPin2);
 
   if (currentLine.endsWith("GET /Open") && (proxyState == LOW)) {
     ST.motor(1,60);
    
         while(digitalRead(proxyPin2) == HIGH){     //as long as proxy2 is not triggered
            ST.motor(1,60);
               }
               }
       if(proxyState2 == LOW){
         ST.motor(1,0);
         }



             
  if (currentLine.endsWith("GET /Close") && (proxyState2 == LOW)) {
     ST.motor(1,-60);
    
      while(digitalRead(proxyPin) == HIGH){     //as long as proxy1 is not triggered
         ST.motor(1,-60);
    }
    }
   if(proxyState == LOW){
    ST.motor(1,0);
        }
      }
      
    }
 ///////////////////////////////////// WiFi close loop //////////////////////////////////
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("ssid: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("Control page available at http://");
  Serial.println(ip);
}

Here is the link to the SyRen library: Dimension Engineering - Libraries for Arduino

This section of my code should be enough to troubleshoot

This section of my answer should be enough to get you straightened out: You need to

If you need more of the answer, post ALL of your code AND links to non-standard libraries.

ST.motor(1,0);

Are the 1 and 0 pin numbers?

Delta_G: ST.motor(1,0);

Are the 1 and 0 pin numbers?

No it's a weird thing with this SyRen library. The 1 refers to the motor driver (it can communicate with multiple motors but I'm just using the one) and the second number refers to the motor direction and speed. -127 is full reverse, 0 is stop, and 127 is full forward.

PaulS:
This section of my answer should be enough to get you straightened out:
You need to

If you need more of the answer, post ALL of your code AND links to non-standard libraries.

Edited my post just for you :*

And the "issues" you're having would be.... what? You say you're having a problem with multiple serial ports, but you don;t give a single clue as to what that problem is.

Regards, Ray L.

RayLivingston: And the "issues" you're having would be.... what? You say you're having a problem with multiple serial ports, but you don;t give a single clue as to what that problem is.

Regards, Ray L.

Yeah my bad. I'm honing in closer on the issue now and I've updated my question. Thank you.

Please quit updating the first post and just add to the thread. It starts to get confusing trying to figure out what’s going on when the posts keep changing.

The documentation for the library shows that there are multiple constructors. You are currently using the no argument constructor, which uses Serial as the input/out stream.

You can use the constructor that takes an argument, Serial2, after connecting the S1 pin to TX2 (instead of TX).

Thank you, that is new to me. How would one introduce the Serial2 constructor into the code? Would it substitute in for the "ST.motor" lines I am currently trying to use?

How would one introduce the Serial2 constructor into the code?

SyRenSimplified ST(Serial2); // Be sure to add a long useless comment after the instance creation

Thanks a lot. I believe I'll get it figured out from here.

You’re going down this road now, so might as well continue. But, looking at the source code for that library, using it hardly seems worth the trouble. It’s very simple (at least the version I found). You probably would have got up and running faster just coding it yourself as ‘C’ functions.

gfvalvo: You probably would have got up and running faster just coding it yourself as ‘C’ functions.

The struggles of being a noob. I did try using the analog mode which sounded simple enough but it was doing all sorts of weird stuff. It was especially frustrating considering that I had everything working just right with a different motor and motor controller. They just weren't quite strong enough.