Controlling Stepper Motor with visual basic

I need a way to control a stepper motor with visual basic.

I'm using an Arduino UNO, TB6600 Driver, and Nema 17 stepper motor.

I can make the stepper motor home at the desired position, and change the position with a textbox in Visual Studio (2019).
I need the motor to wait until the start button is pressed, and stop with the stop button is pressed.

I've put over 2 weeks of time into figuring it out, but I can't get it. I found a few projects where I can achieve desirable results using the Arduino serial monitor but, I can't make it work with Visual Studio.

PS: this is my first time using VS and Arduino.

VS Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort1.Open();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
Double a;
Double v = Double.Parse(textBox1.Text);
a = v;
serialPort1.Write(a.ToString());

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("B");

}

private void button3_Click(object sender, EventArgs e)
{
serialPort1.WriteLine("A");

}

private void label1_Click(object sender, EventArgs e)
{

}
}
}

Stepper_Position.ino (2.89 KB)

This is not a Visual Studio or a Visual Basic forum.

To receive serial data into the Arduino see the serial input basics tutorial.

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

arsenenko2:
I've put over 2 weeks of time into figuring it out, but I can't get it. I found a few projects where I can achieve desirable results using the Arduino serial monitor but, I can't make it work with Visual Studio.

If you have Arduino code that works with the Serial Monitor then you will have to seek advice on a Forum that deals with Visual Basic for advice about how to use VB to do what you have been doing with the Serial Monitor.

I don't use Windows but I suspect it should not be too difficult to get VB to do what you can do with the Serial Monitor.

One thing to be aware of is that when VB opens the serial port it will cause the Arduino to reset. Your VB program needs to allow time for that and then keep the serial port open until it is completely finished with the Arduino.

...R

Be explicit about which com port you're opening in vb. Ensure it's the one the Arduino is on. Be aware that this may vary as usb devices are connected or removed.

My Text I/O for the Real World tutorial provides a detailed example of reading and parsing general command words from the Serial port. The same tutorial has a GPS parser example that covers converting text to numbers reliably.

Maybe this can help:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.