Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Senior Design project help, sending message over tcp to motor drive for robot on: May 24, 2012, 10:22:00 pm
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.
2  Using Arduino / Programming Questions / Re: Senior Design project help, sending message over tcp to motor drive for robot on: May 24, 2012, 09:55:11 am
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.
3  Using Arduino / Programming Questions / Senior Design project help, sending message over tcp to motor drive for robot on: May 23, 2012, 10:20:19 pm
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.

Code:
//  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.
  }
}
Pages: [1]