0

I have created this Arduino sketch that communicates with my pc through the Console library and using the serial monitor over my network. Essentially, when I enter the digit 1, my Arduino stepper motor moves 30 steps etc. However, it is inconvenient to have to type in the serial monitor. I was hoping anyone would know how I can create an executable windows form or something that can connect over my network, to the Arduino Yun console.

#include <Stepper.h>
#include <Console.h>

char incomingByte;      
Stepper stepper(64,8,9,10,11);
int stepCount = 1;

void setup() {

  Bridge.begin();  
  Console.begin(); 
  while (!Console);
  stepper.setSpeed(60);

}

void loop() {
  if (Console.available() > 0) 
  {    

incomingByte = Console.read();

    if (incomingByte == '1') 
    {
    stepCount += 30;
     if (stepCount > 0 && stepCount < 4096)
     {
     stepper.step(30);
     Console.println(stepCount);
     }
    else{stepCount = stepCount - 30;}
    }

    if (incomingByte == '2') 
    {
    stepCount = stepCount - 30;
     if (stepCount > 0 && stepCount < 4096)
     {
     stepper.step(-30);
     Console.println(stepCount);
     }
    else{stepCount += 30;}
    }

    if (incomingByte == '3') 
    {
    stepCount += 200;
     if (stepCount > 0 && stepCount < 4096)
     {
     stepper.step(200);
     Console.println(stepCount);
     }
    else{stepCount = stepCount - 200;}
    }

    if (incomingByte == '4') 
    {
    stepCount = stepCount - 200;
     if (stepCount > 0 && stepCount < 4096)
     {
     stepper.step(-200);
     Console.println(stepCount);
     }
    else{stepCount += 200;}
    }
  }
}

Here is the windows form app I was hoping would work:

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;
using System.IO.Ports;


namespace Remote_Focuser
{
    public partial class Form1 : Form
    {
        private SerialPort myPort;
        public Form1()
        {
            Console.Read();
            InitializeComponent();
            Init();
        }

        private void Fwd_30_Button_Click(object sender, EventArgs e)
        {
            myPort.WriteLine("1");
        } 

        private void Backward_30_Button_Click(object sender, EventArgs e)
        {
            myPort.WriteLine("2");
        }

        private void Forward_200_Button_Click(object sender, EventArgs e)
        {
            myPort.WriteLine("3");
        }

        private void Backward_200_Button_Click(object sender, EventArgs e)
        {
            myPort.WriteLine("4");
        }
        private void Init()
        {
            myPort = new SerialPort();
            myPort.BaudRate = 9600;
            myPort.PortName = "10.1.1.211";

            myPort.Open();
        }
    }
}

Thanks heaps in advance, and yes I have probably made a big mistake, I am not too proficient yet... :)

Harry Stuart
  • 1,781
  • 2
  • 24
  • 39
  • "serial monitor over my network"... Serial port or Ethernet network? You are mixing things, a serial port is a COM port, a physical RS-232 one, but you have named the port as "10.1.1.211" and that's an IP... do you have some device connected to the serial port of the arduino that connects to wi-fi or ethernet? – Gusman Jul 25 '17 at 00:09
  • You want send data wireless through "Serial Port" or "Tcp Port"? If sending data through Serial Port then you need "System.IO.Ports.SerialPort" class, BUT if using Tcp Port then you need "System.Net.Sockets" class. – Ihdina Jul 25 '17 at 00:52
  • I assume you are sending data via serial port. For get "myPort.PortName", look at device manager - Ports (COM & LPT) - COMx, with x is value between 1 to N. You so need "serial to wireless module" to convert serial port to wireless. – Ihdina Jul 25 '17 at 01:02
  • Sorry, I was vague. I want send information from a windows form on my computer, to my Arduino yun over wifi. The arduino's ip is 10.1.1.211. Essentially, I want the IDE serial monitor to Console.read() what information is being sent by the windows form – Harry Stuart Jul 25 '17 at 06:14

0 Answers0