Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Linking Arduino project with C project (Read 7858 times)
arslanxazmi
Newbies
*
Offline


Posts: 6
Joined: Jul 25th, 2015
Linking Arduino project with C project
Jul 25th, 2015 at 1:35pm
Print Post  
Hey, i want to ask, how can i link my arduino project with C++ project file, as i want to perform serial communication. I am using visual studio 2013, arduino ide 1.6.5.
« Last Edit: Jul 25th, 2015 at 1:43pm by arslanxazmi »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12164
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Linking Arduino project with C project
Reply #1 - Jul 25th, 2015 at 1:57pm
Print Post  
Hi,

I am sorry I an not clear about your question.

You have a c# or c++ windows program that must speak with an Arduino program using usb?

or

You have an arduino .cpp file in an Arduino project. The .cpp needs to have access to Serial?
« Last Edit: Jul 25th, 2015 at 1:57pm by Tim@Visual Micro »  
Back to top
IP Logged
 
arslanxazmi
Newbies
*
Offline


Posts: 6
Joined: Jul 25th, 2015
Re: Linking Arduino project with C project
Reply #2 - Jul 25th, 2015 at 2:01pm
Print Post  
Thank You for your reply. I have a c++ file, and i want to communicate with my stepper motor using arduino through serial communication(USB port)
« Last Edit: Jul 25th, 2015 at 2:01pm by arslanxazmi »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12164
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Linking Arduino project with C project
Reply #3 - Jul 25th, 2015 at 2:08pm
Print Post  
Okay this forum is reallu just to help people get the ide running. The best place for answers is http://www.stackoverflow.com

I can give this info but it might not help you ...

Does your C++ have access to windows .net objects such as System.IO? If yes then you can use the SerialPort object, is No then you need to search google for C++ Serial Port code for windows.

On the Arduino you do something like this:-
Code
Select All
void setup()
{
  Serial.begin(115200);
}

void loop()
{
 if (Serial.available()>0)
{
  char cmd = Serial.read();
 
     switch (cmd)
    {
        //command = motor
        case 'm':
        {
        //stepper angle
        char angle = Serial.read();
        //
        break;
       }
    }
} 

« Last Edit: Jul 25th, 2015 at 2:10pm by Tim@Visual Micro »  
Back to top
IP Logged
 
arslanxazmi
Newbies
*
Offline


Posts: 6
Joined: Jul 25th, 2015
Re: Linking Arduino project with C project
Reply #4 - Jul 25th, 2015 at 2:14pm
Print Post  
Thank You. Let me show you my code. I am using a variable 'incomingbyte', and i want to control it with my c++ code. Any Help will be really appreciated. 
Code:
#include <Stepper.h>
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor
int incomingByte=0;
// initialize the stepper library on pins 9 through 12:
Stepper myStepper(stepsPerRevolution, 9, 10, 11,12);
void setup() {
  // put your setup code here, to run once:
  // set the speed at 60 rpm:
  myStepper.setSpeed(15);
  // initialize the serial port:
  Serial.begin(9600);


}

void loop() {
  if (Serial.available() > 0) {
    // read the incoming byte:
   incomingByte = Serial.read();

    switch(incomingByte)
    {
      case'a':
      { 
       myStepper.step(-40);
  delay(1000);
      }
      break;
      case 'b':
      {
     myStepper.step(-20);
  delay(1000);
      }
      break;
      case 'c':
      {
         myStepper.step(0);
         
  delay(1000);
      }
      break;
      case 'd':
      {
        myStepper.step(20);
  delay(1000);
      }
      break;
      case 'e':
      {
myStepper.step(40);
    delay(1000);
      }
      break;
    }
  }
}
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12164
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Linking Arduino project with C project
Reply #5 - Jul 25th, 2015 at 2:21pm
Print Post  
Hi,

You need to add a reference to System.IO into your C++ project

https://msdn.microsoft.com/en-us/library/system.io.ports.serialport(v=vs.110).as...
« Last Edit: Jul 25th, 2015 at 2:21pm by Tim@Visual Micro »  
Back to top
IP Logged
 
arslanxazmi
Newbies
*
Offline


Posts: 6
Joined: Jul 25th, 2015
Re: Linking Arduino project with C project
Reply #6 - Jul 25th, 2015 at 3:01pm
Print Post  
Okay, Thank You. But explanation in that link is not clear. Can you please help me with it?
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12164
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Linking Arduino project with C project
Reply #7 - Jul 25th, 2015 at 3:05pm
Print Post  
Something like this C# but as C++

Stackoverflow is your friend

Code
Select All
using System;
using System.IO.Ports;

namespace SerialPortTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new SerialPort(args[0], 9600, Parity.None, 8, StopBits.One);
            p.Open();

            Console.WriteLine("Sending ({1}) {0}", args[1], args[1].Length);

            p.WriteLine(args[1]);

            Console.WriteLine("Reading back");

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(p.ReadLine());

            Console.ResetColor();
        }
    }
} 

  
Back to top
IP Logged
 
arslanxazmi
Newbies
*
Offline


Posts: 6
Joined: Jul 25th, 2015
Re: Linking Arduino project with C project
Reply #8 - Jul 25th, 2015 at 5:13pm
Print Post  
Thanks for your kind help. This Link can also be very helpful.
http://arduinovisualc.blogspot.com.tr/
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12164
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Linking Arduino project with C project
Reply #9 - Jul 25th, 2015 at 5:28pm
Print Post  
Yes that is useful link thanks
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint