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
Normal Topic Beginner: How do I send bytes from my computer through the serial port to the uno? (Read 5959 times)
DSalles
Newbies
*
Offline


Posts: 5
Joined: Mar 21st, 2016
Beginner: How do I send bytes from my computer through the serial port to the uno?
Mar 21st, 2016 at 4:14am
Print Post  
I want to send bytes which represent angles in degrees, from my computer, through the "serial port" (the USB to which my Arduino Uno is connected.)  Later my plan is to control a puppet using a relSense camera, but for now I just want to send data out through Serial Port, in my case, COM4. 


I am using Visual Studio Professional 2013 and C++ with Visual Micro
I just registered and will be going through the documentation, but if there is a quick way to be able to write to COM4 interactively, like with a console, I will appreciate it.

This is the sketch I uploaded to the Uno: 

/*
Name:            Sketch1.ino
Created:      2/11/2016 12:37:46 PM
Author:      diana_000
*/

#include <Servo.h>

#include <Servo\src\Servo.h>


int PinServoHead;
int PinServoJaw;
int ServoSpeed;
int ServoStop;
bool run = true; /* true checks for serial input and if there is none resets the motors to 90 degrees. run = false loops through test rotations*/


Servo HeadServo;
Servo JawServo;
int i = 0;
char buffer;
int nextServo = 0;
int servoAngles[] = { 10, 10 };

// the setup function runs once when you press reset or power the board
void setup() {
     
     PinServoHead = 9;
     HeadServo.attach(PinServoHead);
     PinServoJaw = 8;
     JawServo.attach(PinServoJaw);
     Serial.begin(9600);
     RunServo(90, HeadServo);
     RunServo(110, JawServo);
}

// the loop function runs over and over again until power down or reset
void loop() {
     if (run){
           if (Serial.available() > 0)
           {
                 delay(10);
                 byte servoAngle = Serial.read();
                 
                 servoAngles[nextServo] = servoAngle;

                 nextServo++;
                 if (nextServo > 1)
                 {
                       nextServo = 0;
                 }

                 byte headAngle = servoAngles[0];
                 byte jawAngle = servoAngles[1];
                 RunServo(headAngle, HeadServo);
                 RunServo(jawAngle, JawServo);
           }
           else {//no serial input
                 RunServo(90, HeadServo);
                 RunServo(90, JawServo);
           }
     }
     else{ // run is false
           RunServo(40, HeadServo);
           RunServo(110, JawServo);
           delay(500);
           RunServo(140, HeadServo);
           RunServo(30, JawServo);
           delay(500);
     }
}

void RunServo(int spd, Servo servo)
{
     servo.write(spd);

}
« Last Edit: Mar 21st, 2016 at 4:16am by DSalles »  
Back to top
 
IP Logged
 
Jo Sto
Ex Member
*


Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #1 - Mar 21st, 2016 at 11:38am
Print Post  
You need a terminal program on the PC side, for example Hyperterm, and a "sketch" on Arduino, which evaluates the characters sent and what meaningful doing. See "Examples-> Communication", comes with the Arduino IDE
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #2 - Mar 21st, 2016 at 12:04pm
Print Post  
Visual Micro has a Serial Monitor (terminal) which in the latest release has an option called CStr

With CStr enabled you can escape data to be sent to the micro-controller

The Serial Monitor is located on the Visual Micro menu or the right of the COM port on the tool bar

With CStr enabled you can send \t \a \x100 \u0000 \U00000000 etc.
  
Back to top
IP Logged
 
DSalles
Newbies
*
Offline


Posts: 5
Joined: Mar 21st, 2016
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #3 - Mar 21st, 2016 at 6:07pm
Print Post  
Thank you I got it!
  
Back to top
 
IP Logged
 
DSalles
Newbies
*
Offline


Posts: 5
Joined: Mar 21st, 2016
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #4 - Mar 21st, 2016 at 6:26pm
Print Post  
Another question, if I do not want to upload a program to the arduino, but just to run or debug from Visual Studio, that sends data through the serial port to which the arduino is attached, how do I access the serial port? When I use Visual Micro it uploads to the arduino when I debug, overwriting the program that is supposed to be waiting for serial input.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12138
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #5 - Mar 21st, 2016 at 6:28pm
Print Post  
Just open the serial monitor and existing debug continues
  
Back to top
IP Logged
 
DSalles
Newbies
*
Offline


Posts: 5
Joined: Mar 21st, 2016
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #6 - Mar 22nd, 2016 at 5:07pm
Print Post  
I mean if I want to write a separate program like a C++ console application, that does not upload to the Uno but runs from the computer that the Uno is attached to and sends data, can I use visual micro for that or do I look for some other library that has a serial port class in it ?
  
Back to top
 
IP Logged
 
DSalles
Newbies
*
Offline


Posts: 5
Joined: Mar 21st, 2016
Re: Beginner: How do I send bytes from my computer through the serial port to the uno?
Reply #7 - Apr 6th, 2016 at 6:18pm
Print Post  
I had too much trouble getting a serial port with C++, as far as adding libraries. So I just used C# and System.IO.Ports and it works great.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint