i need My UDP from VB .NET to pass a Larger Number like 11223 into my Function in the Arduino in which now its only talking 1 2 3 4 5 ... it would be nice to take the Argument MoveAtVelocity($RPM);
RPM would come from my Converted Math in VB .NET Can anyone help me out, Thanks so much
void loop() {
motor.EnableRequest(true);
// SerialPort.SendLine("Motor Enabled");
int packetSize = Udp.parsePacket();
if (packetSize > 0) {
Serial.print("Remote IP: ");
Serial.print(Udp.remoteIP());
Serial.print(" ");
Serial.print(Udp.remotePort());
Serial.print(" ");
int bytesRead = Udp.read(packetReceived, MAX_PACKET_LENGTH);
Serial.write(packetReceived, bytesRead);
Serial.println();
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
for (int i = 0; i < bytesRead; i++) {
Udp.write(toupper(packetReceived[i]));
// Udp.write(toupper(SETRPM));
}
Udp.endPacket();
if (packetReceived[0] == '0') digitalWrite(LED_BUILTIN, LOW);
if (packetReceived[0] == '0') MoveAtVelocity(0);
// if (packetReceived[0] == '3') MoveAtVelocity(22450); //674 RPM
// if (packetReceived[0] == '3') MoveAtVelocity(11225); //337 RPM
//if (packetReceived[0] == '3') MoveAtVelocity(9225); //227 RPM
if (packetReceived[0] == '3') MoveAtVelocity(8333); //250 RPM
if (packetReceived[0] == '4') MoveAtVelocity(11667); //350 RPM
if (packetReceived[0] == '5') MoveAtVelocity(12667); //380 RPM
if (packetReceived[0] == '6') MoveAtVelocity(13667); //410 RPM
if (packetReceived[0] == '7') MoveAtVelocity(15000); //450 RPM
// if (packetRecieved[0] == '3') Serial.print(SETRPM);
if (packetReceived[0] == '1') digitalWrite(LED_BUILTIN, HIGH);
}
delay(10);
}
/*------------------------------------------------------------------------------
* MoveAtVelocity
*
* Command the motor to move at the specified "velocity", in steps/second.
* Prints the move status to the USB serial port
*
* Parameters:
* int velocity - The velocity, in step steps/sec, to command
*
* Returns: None
*------------------------------------------------------------------------------*/
bool MoveAtVelocity(int32_t velocity) {
// Check if an alert is currently preventing motion
if (motor.StatusReg().bit.AlertsPresent) {
SerialPort.SendLine("Motor status: 'In Alert'. Move Canceled.");
return false;
}
SerialPort.Send("Commanding velocity: ");
SerialPort.SendLine(velocity);
// Command the velocity move
motor.MoveVelocity(velocity);
// Waits for the step command to ramp up/down to the commanded velocity.
// This time will depend on your Acceleration Limit.
SerialPort.SendLine("Ramping to speed...");
while (!motor.StatusReg().bit.AtTargetVelocity) {
continue;
}
SerialPort.SendLine("At Speed");
return true;
}
//------------------------------------------------------------------------------
So my VB .NET looks like this , i am only taking 2, 3, 4, 5 etc so what I'm trying to accomplish is a user puts in 350 or 120 as in RPM it Goes into my Formula rpmx = tbSend.Text / 60 * 2000
in which will get me my velocity to UDP into the Arduino now when the Arduino receives this value it needs to pass that value into the Arduino
if (packetReceived[0] == '4') MoveAtVelocity(12667); //350 RPM
' VB.NET
Private Sub sendBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendBut.Click
Dim toSend As String = tbSend.Text 'tbSend is a textbox,
' Formula 500RPM take 500/60*2000
Dim data() As Byte = Encoding.ASCII.GetBytes(toSend) 'Convert string to bytes
sendingClient.Send(data, data.Length) 'Send bytes
End Sub
the Arduino is only seeing the First Number of the Value
if (packetReceived[0] == '4') MoveAtVelocity(12667); //350 RPM
FULL Arduino UDP Code
void loop() {
motor.EnableRequest(true);
// SerialPort.SendLine("Motor Enabled");
int packetSize = Udp.parsePacket();
if (packetSize > 0) {
Serial.print("Remote IP: ");
Serial.print(Udp.remoteIP());
Serial.print(" ");
Serial.print(Udp.remotePort());
Serial.print(" ");
int bytesRead = Udp.read(packetReceived, MAX_PACKET_LENGTH);
Serial.write(packetReceived, bytesRead);
Serial.println();
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
for (int i = 0; i < bytesRead; i++) {
Udp.write(toupper(packetReceived[i]));
// Udp.write(toupper(SETRPM));
}
Udp.endPacket();
if (packetReceived[0] == '0') digitalWrite(LED_BUILTIN, LOW);
if (packetReceived[0] == '0') MoveAtVelocity(0);
// if (packetReceived[0] == '3') MoveAtVelocity(22450); //674 RPM
// if (packetReceived[0] == '3') MoveAtVelocity(11225); //337 RPM
//if (packetReceived[0] == '3') MoveAtVelocity(9225); //227 RPM
if (packetReceived[0] == '3') MoveAtVelocity(8333); //250 RPM
if (packetReceived[0] == '4') MoveAtVelocity(12667); //350 RPM
if (packetReceived[0] == '5') MoveAtVelocity(15667); //350 RPM
if (packetReceived[0] == '7') MoveAtVelocity(17667); //380 RPM
if (packetReceived[0] == '8') MoveAtVelocity(19667); //410 RPM
if (packetReceived[0] == '450') MoveAtVelocity(15000); //450 RPM
if (packetReceived[0] == '16000') MoveAtVelocity(16000);
Serial.print (packetReceived[0]);
if (packetReceived[0] == '19000') MoveAtVelocity(19000);
// if (packetRecieved[0] == '3') Serial.print(SETRPM);
if (packetReceived[0] == '1') digitalWrite(LED_BUILTIN, HIGH);
}
delay(10);
}
/*------------------------------------------------------------------------------
* MoveAtVelocity
*
* Command the motor to move at the specified "velocity", in steps/second.
* Prints the move status to the USB serial port
*
* Parameters:
* int velocity - The velocity, in step steps/sec, to command
*
* Returns: None
*------------------------------------------------------------------------------*/
bool MoveAtVelocity(int32_t velocity) {
// Check if an alert is currently preventing motion
if (motor.StatusReg().bit.AlertsPresent) {
SerialPort.SendLine("Motor status: 'In Alert'. Move Canceled.");
return false;
}
SerialPort.Send("Commanding velocity: ");
SerialPort.SendLine(velocity);
// Command the velocity move
motor.MoveVelocity(velocity);
// Waits for the step command to ramp up/down to the commanded velocity.
// This time will depend on your Acceleration Limit.
SerialPort.SendLine("Ramping to speed...");
while (!motor.StatusReg().bit.AtTargetVelocity) {
continue;
}
SerialPort.SendLine("At Speed");
return true;
}
#include "ClearCore.h"
#include "MotorManager.h"
#include <Ethernet.h>
#include <EthernetUdp.h>
/* LED Through UDP */
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 111, 177);
unsigned int localPort = 8888;
unsigned int SETRPM;
unsigned int vol;
bool MoveAtVelocity(int32_t velocity);
#define MAX_PACKET_LENGTH 100
#define SETRPM
#define vol
#define motor ConnectorM0
#define SerialPort ConnectorUsb
int32_t accelerationLimit = 8000; // 100000
char packetReceived[MAX_PACKET_LENGTH];
EthernetUDP Udp;
bool usingDhcp = false;
void setup() {
//-------------------------------------------------------------------
// step and direction applications.
MotorMgr.MotorInputClocking(MotorManager::CLOCK_RATE_NORMAL);
// Sets all motor connectors into step and direction mode.
MotorMgr.MotorModeSet(MotorManager::MOTOR_ALL,Connector::CPM_MODE_STEP_AND_DIR);
motor.HlfbCarrier(MotorDriver::HLFB_CARRIER_482_HZ);
// Set the maximum acceleration for each move
motor.AccelMax(accelerationLimit);
//-------------------------------------------------------------------
Serial.begin(115200);
delay(3000); // wait so serial port comm is open
if (usingDhcp) {
int dhcpSuccess = Ethernet.begin(mac);
if (dhcpSuccess) {
Serial.print("DHCP ");
Serial.println(Ethernet.localIP());
}
else {
Serial.println("DHCP failed");
Serial.println("Try again using a manual configuration...");
while (true) {
// UDP will not work without a configured IP address.
continue;
}
}
}
else {
Ethernet.begin(mac, ip);
Serial.print("IP ");
Serial.println(Ethernet.localIP());
}
while (Ethernet.linkStatus() == LinkOFF) {
Serial.println("The Ethernet cable is unplugged...");
delay(500);
}
Udp.begin(localPort);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
motor.EnableRequest(true);
// SerialPort.SendLine("Motor Enabled");
int packetSize = Udp.parsePacket();
if (packetSize > 0) {
Serial.print("Remote IP: ");
Serial.print(Udp.remoteIP());
Serial.print(" ");
Serial.print(Udp.remotePort());
Serial.print(" ");
int bytesRead = Udp.read(packetReceived, MAX_PACKET_LENGTH);
Serial.write(packetReceived, bytesRead);
Serial.println();
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
for (int i = 0; i < bytesRead; i++) {
Udp.write(toupper(packetReceived[i]));
// Udp.write(toupper(SETRPM));
}
Udp.endPacket();
// MoveAtVelocity(packetReceived);
if (packetReceived[0] == '0') digitalWrite(LED_BUILTIN, LOW);
if (packetReceived[0] == '0') MoveAtVelocity(0);
// if (packetReceived[0] == '3') MoveAtVelocity(22450); //674 RPM
// if (packetReceived[0] == '3') MoveAtVelocity(11225); //337 RPM
//if (packetReceived[0] == '3') MoveAtVelocity(9225); //227 RPM
if (packetReceived[0] == '3') MoveAtVelocity(8333); //250 RPM
if (packetReceived[0] == '4') MoveAtVelocity(12667); //350 RPM
if (packetReceived[0] == '5') MoveAtVelocity(15667); //350 RPM
if (packetReceived[0] == '7') MoveAtVelocity(17667); //380 RPM
if (packetReceived[0] == '8') MoveAtVelocity(19667); //410 RPM
Serial.print (packetReceived[0]);
// if (packetRecieved[0] == '3') Serial.print(SETRPM);
if (packetReceived[0] == '1') digitalWrite(LED_BUILTIN, HIGH);
}
delay(10);
}
/*------------------------------------------------------------------------------
* MoveAtVelocity
*
* Command the motor to move at the specified "velocity", in steps/second.
* Prints the move status to the USB serial port
*
* Parameters:
* int velocity - The velocity, in step steps/sec, to command
*
* Returns: None
*------------------------------------------------------------------------------*/
bool MoveAtVelocity(int32_t velocity) {
// Check if an alert is currently preventing motion
if (motor.StatusReg().bit.AlertsPresent) {
SerialPort.SendLine("Motor status: 'In Alert'. Move Canceled.");
return false;
}
SerialPort.Send("Commanding velocity: ");
SerialPort.SendLine(velocity);
// Command the velocity move
motor.MoveVelocity(velocity);
// Waits for the step command to ramp up/down to the commanded velocity.
// This time will depend on your Acceleration Limit.
SerialPort.SendLine("Ramping to speed...");
while (!motor.StatusReg().bit.AtTargetVelocity) {
continue;
}
SerialPort.SendLine("At Speed");
return true;
}
well my RPM value is Converted from VB.NET my Motor Class in Arduino can only take a Velocity Movement, so if the User Enters in 360 as an RPM it Gets Converted to Velocity
What is being passed to the Arduino?
a). Velocity?
b). RPM?
c). A single byte. You are currently just looking at the first byte. '0' , '1', '2', '3' etc.
Yeah it's Fixed, i know that is wrong i was just testing it but Doesn't work for the fact im only looking at if (packetReceived[0] == '19000') MoveAtVelocity(19000); // Value (1)