Hi everybody..
I just do not understand what could be the error ... my program only sent once a value of position and then communication with Arduino fells
I have a Serial Version which works preatty good..I know that the motor functions are not the problem..
I will be very grateful for the help
my code:
#include <SPI.h>
#include <Ethernet.h>
#include <Z_OSC.h>
#include <L6470.h>
L6470 stepper(7);
//==============================================================================================================================================================
byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // A Media Access Control address (MAC address)
byte myIp[] = { MY ARDUINO IP}; // Ethenet Shield IP Adresse// Marked as Remote Host in vvvv
int serverPort = 4441; // Marked as Remote Port in vvvv Patch
byte destIp[] = { IP }; // My Computer IP Adress
int destPort = 4442; // Destination Port
const int L6470SC = 7;
const int ETHERNETSC = 10;
//=============================================================================================================================================================
//Arduino digital Pins Variable//
boolean test; //Sleep Mode Arduino Pin 7
//===============================================================================================================================================================
//Motor control variables//
long int pos = 0; // Variable to set the Position
long int mode =0; // Variable to set the Motion Mode
//================================================================================================================================================================
//OSC Comunication variables//
Z_OSCServer server;
Z_OSCMessage *rcvMes;
//================================================================================================================================================================
void setup(){
pinMode(5,OUTPUT); // Test Pin as Output
Serial.begin(9600);
Ethernet.begin(myMac ,myIp);
server.sockOpen(serverPort);
//digitalWrite(10,HIGH); //
//========================================================================================
//MOTOR Set up
stepper.setMaxSpeed(600);
stepper.setMinSpeed(0);
stepper.setAcc(100); //set acceleration
stepper.setDec(100); //set decc
stepper.setMicroSteps(8); //1,2,4,8,16,32,64 or 128
stepper.setOverCurrent(3000); //set overcurrent protection
stepper.setStallCurrent(3000);
}
//============================================================================================================================================================
void loop()
{
ComunicationProcedure ();
}
void ComunicationProcedure ()
{
if(server.available()){ //Gets a client that is connected to the server and has data available for reading.
rcvMes=server.getMessage();
//pos
if( !strcmp( rcvMes->getZ_OSCAddress() , "/arduino/out" ) ) //compares the adress
{
pos = rcvMes->getInteger32(0); //Get value from vvvv
if(pos > 0) //
MotorProcedure();
}
// mode
if( !strcmp( rcvMes->getZ_OSCAddress() , "/arduino/out" ) )
{
mode = rcvMes->getInteger32(1); //Get value from vvvv
}
//test_Pin: if you can blink a Pin with "vvvv Bang button" you have comunication
if ( !strcmp( rcvMes->getZ_OSCAddress() , "/arduino/out" ))
{
test = rcvMes->getInteger32(2); //Get the value from vvvv
test = constrain(test, 0, 1); // limit the value to 0-1
if ( test == 1 )
{
digitalWrite(5,HIGH);
}
else {
digitalWrite(5,LOW);
}
}
}
}
void MotorProcedure()
//,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
{
int Type = mode;//////// //Changes the operation Mode////////////////////////////////////////
switch (Type) {
case 1: //Testing getPos() function
stepper.init();
stepper.isBusy();
stepper.goTo(long (pos));
if(stepper.getPos()==pos){
digitalWrite(L6470SC, LOW);
digitalWrite(10,LOW);
}
break;
case 2: // Testing move() function
stepper.init();
stepper.isBusy();
stepper.move(long (pos));
if(stepper.getPos()==pos){
digitalWrite(L6470SC, LOW);
digitalWrite(10,LOW);
}
break;
}
}