Senior Design project help, sending message over tcp to motor drive for robot

Hello,
I have been toiling for the last couple weeks to try to send ASCII message over tcp from an arduino uno ethernet to a motor controller. I have been using wireshark to listen to in and can’t seem to get the arduino to connect and send anything over tcp.

The goal is to send a potentiometer value as a 0-100 value to a baldor microflex e100 motor controller. I send [STX]MVR=1[ETX] to enable the motor and then send [STX]SPD=(poteniometer 0-100% Value)[ETX] to the motor controller to set the speed. The motor controller acts as a server that I have to connect to with the Arduino.

Any guidance would really be appreciated. I am out of ideas and have to get this working for my final presentation next Tuesday. Thank you very much for your help.

//  Variables
int button;                 // button value, high or low
int ledState = LOW;             // ledState used to set the LED
long previousMillis;        // will store last time LED was updated

//Ethernet Setup
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  Arduino MAC address
byte ip[] = { 192,168, 0, 3 }; // Arduino IP
byte server[] = { 192,168, 0, 1 };  // Server IP
EthernetClient client (5002);  // Mint Raw Ethernet Terminal uses Port 5002


void setup() {
  Serial.begin(9600);  // initialize serial communication at 9600 bits per second:
  Ethernet.begin(mac, ip);
    delay(1000);   // give the Ethernet shield a second to initialize:
    Serial.println("connecting...");
    if (client.connect(server, 5002)) {  // if you get a connection, report back via serial:
      Serial.println("connected");
  } 
    else {
      Serial.println("connection failed");  // if you didn't get a connection to the server:
    }
  
  pinMode(2, INPUT);  // sets the digital pin 2 as input
}

void loop() {
 button = digitalRead(2);   // check if the pushbutton is pressed
    
  if (button == HIGH) {     // if it is, the buttonState is HIGH:   
    int PotVal = analogRead(A1); // read the input on analog pin 0:
     
     Serial.println(PotVal/10.23);  // print potentiometer value 0-100%:
      
     client.println("[STX]MVR=1[ETX]"); //send signal to initialize motor
     client.println("[STX]SPD=");  //send signal to set speed
     client.println(PotVal/10.23);  //Can't figure out how to set the pot value in the middle of the ascii values i.e. [STX]SPD=PotVal/10.23[ETX]" 
     client.println("[ETX]");
     delay(1);  // delay in between reads for stability  
       
    long interval = 1050-PotVal;           // interval at which to blink (milliseconds)
      unsigned long currentMillis = millis();
 
    if(currentMillis - previousMillis > interval) {
      // save the last time you blinked the LED 
      previousMillis = currentMillis;   
      if (ledState == LOW)  // if the LED is off turn it on and vice-versa:
        ledState = HIGH;
    
      else
        ledState = LOW;
        digitalWrite(9, ledState); // set the LED with the ledState of the variable:
      }
  } 
  
  else {
    int PotVal;  // Set PotVal to 0:
    client.println("[STX]MVR=0[ETX]");  //Sends signal to de-initialize motor. 
  }
}

Have you gotten your baldor microflex e100 motor controller to work with any other application or device?

     client.println("[STX]MVR=1[ETX]"); //send signal to initialize motor
     client.println("[STX]SPD=");  //send signal to set speed
     client.println(PotVal/10.23);  //Can't figure out how to set the pot value in the middle of the ascii values i.e. [STX]SPD=PotVal/10.23[ETX]" 
     client.println("[ETX]");

Are you sure that you are supposed to be sending the string "[STX]", not the VALUE STX?

Zoomkat : I can connect over usb to the computer and program the microflex with Baldor mint software.

PaulS: In the data sheet for the software on the microflex they said that [STX] has a hex value of 02. Is there a way I could send that in line with the rest of the data? would it be client.print(02, HEX) client.print(MVR…)? How would you send the VALUE STX?

Thank you for all your help.

Is there anything special about the TCP stack that the arduino uses? Also is there a way to send the message to two servers, or mirror the message? I have to connect to two microflexs, one for each motor.

In the data sheet for the software on the microflex they said that [STX] has a hex value of 02. Is there a way I could send that in line with the rest of the data? would it be client.print(02, HEX) client.print(MVR...)? How would you send the VALUE STX?

client.write((byte)2);

Which, of course, is a world apart from writing

client.print("[STX]");

ear36:
Hello,
I have been toiling for the last couple weeks to try to send ASCII message over tcp from an arduino uno ethernet to a motor controller. I have been using wireshark to listen to in and can’t seem to get the arduino to connect and send anything over tcp.

It looks as if you have misunderstood the protocol for the controller and are trying to send your messages as an ASCII string instead of as binary messages. But that’s a side issue, if you haven’t even managed to get a TCP socket connected yet.

Are you seeing any activity over ethernet at all fro the Arduino, when your sketch tries to establish the connection?

Are you certain that your wireshark is running on an adapter which has visibility of the Arduino/motor controller traffic?

PeterH: I looked over the Baldor documentation today and confirmed that it is looking to receive ASCII messages not hex. As far as the TCP socket, I haven’t been able to have the arduino connect to the microflex or even my computer if I manually set the ip. I’m not sure how to configure my mac to act as a server. In addition I have not been able to see any TCP data from my arduino using Wireshark. I assumed that was due to the fact that my mac was not acting as a server. Are there any problems with my code that wouldn’t allow me to connect to a server at the ip 192.168.0.1 and port 5002?
Thanks again.

ear36:
Are there any problems with my code that wouldn’t allow me to connect to a server at the ip 192.168.0.1 and port 5002?

Port blocked, firewall, different subnet, ip address conflict…

I assumed that was due to the fact that my mac was not acting as a server. Are there any problems with my code that wouldn't allow me to connect to a server at the ip 192.168.0.1 and port 5002?

How did a mac get into the mix as a server?

Are there any problems with my code that wouldn't allow me to connect to a server at the ip 192.168.0.1 and port 5002?

In a home setup with a router, the 192.168.0.1 is most often the ip address assigned to the router.

I suggest you check out the behaviour of the motor controller using plain old Telnet and make sure you have got the communication protocol, addresses and ports correct. This will also enable you to confirm that your use of Wireshark actually does show the network traffic you're sending. Be sure to run Wireshark on a separate machine from your Telnet client, by the way, to prove that it is successfully capturing traffic on the interface in promiscuous mode.

Once you have that working, connect your Arduino to the same LAN port as the machine that you were running your Telnet client on, make sure your sketch is using the same TCP/Ip address and port, and sending the same string as you used in testing. If all our assumptions are correct, you should see the same network traffic, and the motor controller should respond the same.