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) How can i read data from my ARDUINO without using serial port (Read 28786 times)
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
How can i read data from my ARDUINO without using serial port
Dec 1st, 2012 at 8:23am
Print Post  
Hello there people.

ive been using visualmicro for a couple of days now and i know now how to debug my arduino programs.

now my question is the following:
How can i make a windows form that takes the data from my arduino and visualize it without using the serial port communication... ive seen many ways to control the arduino with visual studio through the serial port, making it send and recieve data with small messages.

Now what i want to accomplish is the exact opposite, i want to connect my arduino to my computer and i want my windows aplication to read the events i set, for example: i press a button and depending on which pin it is connected it will make a box red indicating i have pressed the button on my arduino related to that box.... 

i know the digitalpin example with the debugger does that but i have failed to understand how it is done... can anybody please help me with that?

here is what i want: Exclaim
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #1 - Dec 1st, 2012 at 7:05pm
Print Post  
Hi,

You should be able to find some c# examples that show you how to open and read a windows serial port. This means that on the arduino you can use the arduino methods such as Serial.println() to send data to the pc. If you don't want to use the main serial port then you can use SoftwareSerial on any digital pins that support interrupts.

The arduino.cc forum or playground should have examples for you.

This c# syntax should give you some hints but you have a little bit of learning to do.

Code
Select All
using System.IO.Ports;

namespace ArduinoTest
{
    class Program
    {

        static void Main(string[] args)
        {
            SerialPort serialPort1 = new SerialPort();
            serialPort1.PortName = "COM3";
            serialPort1.BaudRate = 9600;
            serialPort1.Open();

            String sDataIn = serialPort1.ReadLine();
        }
    }
}

 



Out of interest, Why don't you want to use serial?
« Last Edit: Dec 1st, 2012 at 7:11pm by Tim@Visual Micro »  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #2 - Dec 1st, 2012 at 7:47pm
Print Post  
Hey there.

well Tim as you see the debugger you made does not use the serial port, it reads directly from the arduino chip without having to put in a code into the serial communications port.

When debugging a arduino code with you're debugger i can put the code directly in and i have no need to use the serial port to see what the arduino is doing, that is what i want.

Basically what i want Tim is to know whats happening with the arduino  and see it on the pc, your debugger does exactly what i want but i DONT want it in form of a debugger. i want it as a real time event viewer that just checks the state of every pin i have connected in a WINDOWS FORM and nothing else.

But nobody seems to understand me. i DO NOT want to control the ARDUINO with my program , INSTEAD i want to SEE what is happening with the ARDUINO, i want to see WHAT is being done with it which BUTTON is pressed, what value has the ANALOG read, etc....   

I don't want to use the serialport because i want to send messages through that AND independently read the data from it..... it cant be that hard Cry
  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #3 - Dec 1st, 2012 at 7:58pm
Print Post  
Ok to make things easier.... i want the DigitalPins example in a WINDOWS FORM.... can i get an example of that?? or a code??? when i try to run the DigitalPins example it gives me a error

here:
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #4 - Dec 1st, 2012 at 8:03pm
Print Post  
Okay I think there is some confusing here. The Visual Studio debugger DOES use serial. 
The debugger works by adding special hidden serial instructions to your program when you debug compile. The plugin then looks for these special serial messages so that it can show you information in the debug windows such as expressions, digital pins, trace etc.

There is no hardware debug for arduino so this debugger is a simple solution to a difficult problem  Smiley

When I find time I plan to make some examples of what you want to do. The examples would be unconnected to the debugger but would be useful for many new users who want to do what you have described.

In any event you have to communicate with the arduino some way. Either serial, or network (with a arduino LAN connection), or bluetooth (still serial) or something else??

It sounds like you do not need the debugger or your own arduino code. Instead why not look at http://arduino.cc/en/Reference/Firmata

  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #5 - Dec 1st, 2012 at 8:07pm
Print Post  
Now that I can see the picture of the error in your I can tell you that error is because you have created a class library instead of a windows application.

You can create a windows application project and "add reference" to your class library or copy the code/forms/controls from the class library into the application project.

The visual micro examples are user controls not applications. You can use them in your own application but you can not run them directly.

If you use vm class examples then make sure you COPY them and use the copy. Do not alter them directly because the next upgrade will overwrite your changes.
  
Back to top
IP Logged
 
RayLivingston
Full Member
***
Offline


Posts: 158
Location: California
Joined: Nov 24th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #6 - Dec 1st, 2012 at 10:26pm
Print Post  
Tim,

Perhaps I'm missing something, but if the debugger isn't running, can't an Arduino application simply read/write to Serial0, and have the PC application monitor the COM port that represents the Arduino?  Of course, it's even a bit simpler to use a USB/Serial adaptor, and another Arduino serial port, as I've been doing, so it's not necessary to "share" with the downloader and debugger.

Regards,
Ray L.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #7 - Dec 1st, 2012 at 10:41pm
Print Post  
Ray, yes thanks that all makes sense. I think the confusion is that kireita wants to do some great things but doesn't yet know how to use arduino serial, how to use c# to make applications and needs to learn how to use c# to read the serial.

Info: Prior to this thread there was an email request to have a single control that can be used for debug and also run standalone. 

So to be clear, I think we recommend learning how to create a windows application that uses the serial port. Then how to program the arduino to send the states of the buttons of interest and send the states (using serial) to the pc.

If the debugger is required then an FTDI cable on a different serial port (or RemoteTransport=SoftwareSerial) will be required.
« Last Edit: Dec 1st, 2012 at 10:53pm by Tim@Visual Micro »  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Now it all makes sense.
Reply #8 - Dec 2nd, 2012 at 12:51am
Print Post  
Hey Tim.

basically that is what i wanted to know i taught the debugger was reading from the arduino directly without adding any codes.

But i had it all wrong. So basically to make everything in my mind clear is the following:

1-the debugger ADDS some secret arduino code that the regular user doesn't see .
2-The secret code DOES use the serial communication but instead of using the main serial communication it uses SOFTWARE SERIAL for each and every PIN in the arduino itself  to report status.
3-To make the Arduino compatible with a windows form i will need to add several serial ports to the windows form and send messages to each serial port when its HIGH or LOW correct?. But to make that happen i will need a separate arduino class which has all pins with software serial communication sending a message whenever a change has been made.

I will start reading about Firmata and the software serial communication.

but if any of you already has something for me it will be greatly appreciated  Grin
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #9 - Dec 2nd, 2012 at 1:03am
Print Post  
Hi kireita,

Well that is getting closer  Smiley

The hidden serial code is actually visible in the temp folder after compile so it isn't so secret but the point is that your arduino code is not altered directly. It remains safe and unchanged

The debugger uses normal Serial unless you specify it should use SoftwareSerial and also set the RemoteRx and RemoteTx pins in the project properties. When you debug using the same port as the upload port then you are certainly using normal Serial. SoftwareSerial is only used if the main serial port is being used for other things. 

So if you use the main serial port for your windows app then you will need to read in the wiki how to configure softwareSerial for the debugger. In that case you will also need an ftdi cable. 

To understand these concepts you should step back a little and read the standard arduino.cc tutorials and example that show how to configure and use both standard serial and softwareSerial in your own simple arduino programs. When you have used these two methods to send data from arduino to pc, without the debugger and without firmata, then things will be much clearer to you.
  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
ROGER!!! ;D
Reply #10 - Dec 2nd, 2012 at 1:14am
Print Post  
I will start making regular serial communication programs to understand how everything works between them  Smiley.

After i actually know how to use simple serial communication with arduino then i will start messing with making several pins a serial communication.... Smiley

also i will try to check that code located in the temp folder to see how you do ite Smiley...

i think that from here on i can handle my own hehe thanks for the great software tim and ill keep you guys updated for any questions or doubts on making this program Smiley
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #11 - Dec 2nd, 2012 at 1:49pm
Print Post  
Okay good except that you should not bother to look at what vm does in the temp files.

Just follow all the standard tutorials from arduino.cc
  
Back to top
IP Logged
 
RayLivingston
Full Member
***
Offline


Posts: 158
Location: California
Joined: Nov 24th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #12 - Dec 2nd, 2012 at 6:30pm
Print Post  
I have a very simple C# SerialPort class you might find helpful on the PC side - if you start your application, THEN plug in the Arduino or USB serial adaptor, it will automatically find the port, and open it for you.  You don't have to tell it what COM port to connect to.  I don't know how to post it here, since there does not seem to be a way to post files, and the source code, while small, is still over the 4,000 character limit.

On the Arduino side, all you have to do is 

Serial.begin(BAUDRATE);  // BAUDATE == the numeric baudrate you want to use.

Serial.print("Any String"); // to print a string to the serial port

You can also use Serial1, Serial2, Serial3, if your Arduino board supports multiple serial ports.



Regards,
Ray L.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #13 - Dec 2nd, 2012 at 6:47pm
Print Post  
I've got a permissions problem on the forum with the attachment folder that I haven't had time to look into so attachment upload is disabled. 
Feel free to email it to me and I will add a link to your post.  It sounds interesting Smiley
  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #14 - Dec 2nd, 2012 at 8:07pm
Print Post  
Hey mister Ray & Tim. Grin

Ive been advancing very much in my little proyect and finally got the hand of it, right now im using the regular Serial communication and im slowly advancing on using SoftwareSerial... Cool


here is a little sketch off my advancement and also how the program is looking. later when i complete my proyect ill post it, ill make sure its compatible with any arduino. Smiley

windows form:


hardware sketch:


i hope you guys are liking it up until now  Tongue.

PS: right now my problem is that the softwareserial does not turn off even if i use Serial1.end().... very weird well if you guys have any recomendations please post it!!! Smiley.

also thank you guys so much in helping me out. Cheesy
« Last Edit: Dec 2nd, 2012 at 8:19pm by kireita »  
Back to top
IP Logged
 
RayLivingston
Full Member
***
Offline


Posts: 158
Location: California
Joined: Nov 24th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #15 - Dec 2nd, 2012 at 8:33pm
Print Post  
Quote:
right now my problem is that the softwareserial does not turn off even if i use Serial1.end()....
 

Not sure what you mean by this.  What are you expecting it to do?

Regards,
Ray L.
« Last Edit: Dec 2nd, 2012 at 8:51pm by Tim@Visual Micro »  
Back to top
 
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #16 - Dec 2nd, 2012 at 9:06pm
Print Post  
RayLivingston wrote on Dec 2nd, 2012 at 8:33pm:
"right now my problem is that the softwareserial does not turn off even if i use Serial1.end()...." - Not sure what you mean by this.  What are you expecting it to do?

Regards,
Ray L.


Hey Ray.

Basically i want to control my serialport by turning it on and off on the Arduino, in some cases i want it open, and in other cases i want it closed.

so to open it normally you would just do Serial.begin(9600); and to close it it would be Serial.end(); but when using software serial somehow when i try to turn it off it doesn't work for example:

i use this part of the code to read the button by turning on the serial port and turning it back off whenever the button is released and to print out an "X" to make sure it is closed, that way i avoid that the serialport gets filled with characters:

     if (digitalRead(boton1) == HIGH)
     {
           Serial.begin(9600);
           Serial.print("A");
     }
     else
     {
           Serial.print("X");
           Serial.end();
     }

but when declaring a softwareserial:

SoftwareSerial Serial1(0,1);

     if (digitalRead(boton4) == HIGH)
     {
           Serial1.begin(4800);
           Serial1.print("L");
     }
     else
     {
           Serial1.print("X");
           Serial1.end();
     }

i test the code but it constantly keeps printing the "X" and its the exact same code but just with a softwareserial.... Sad

any suggestions?
« Last Edit: Dec 2nd, 2012 at 9:08pm by kireita »  
Back to top
IP Logged
 
RayLivingston
Full Member
***
Offline


Posts: 158
Location: California
Joined: Nov 24th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #17 - Dec 2nd, 2012 at 10:33pm
Print Post  
That seems to be a "feature" of SoftwareSerial - the end() call does nothing but turn off the interrupt on the Rx pin.  It does nothing to disable transmit, which is purely a software function.  You need to create your own flag indicating whether the port *should* currently be enabled, and if that flag is not set, then don't call Serial1.print().  You could also re-configure the the Tx pin as an input when you want the port disabled, so even though the software will try to transmit the data, it won't actually make it out the pin.  You could also modify your copy of SoftwareSerial to include this change.

Regards,
Ray L.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #18 - Dec 2nd, 2012 at 11:12pm
Print Post  
Or you can do it an easier way. it's good practice to do as little as possible leaving the arduino free for other tasks.

Setup two globals to save the last button states and only send a serial message when the state changes. Something like this...

Code
Select All
int myBtnState1;
int myBtnState4;

void setup()
{
  Serial1.begin(4800);
}

void loop()
{
 int currentState;


 //process button 4
 currentState = digitalRead(button4);
 if (currentState!=myBtnState4)
 {
    myBtnState4 = currentState
    if (myBtnState4 == HIGH)
     {
           Serial1.println("4:H");
     }
     else
     {
           Serial1.println("4:L");
     }
 } 

 //process button 1
 currentState = digitalRead(button1);
 if (currentState!=myBtnState1)
 {
    myBtnState1 = currentState
    if (myBtnState1 == HIGH)
     {
           Serial1.println("1:H");
     }
     else
     {
           Serial1.println("1:L");
     }
 } 
} 


The code above could be much less verbose, it is expanded for the purposed of this example.

It's also easier to use println() because then you can use the following c# to read the serial packet

Code
Select All
String sIn = mySerialPort.ReadLine(); 



Using a separator for multiple data items in a packet is a good idea. the example above used a colon :

The c# to split the packet into an array is

Code
Select All
String[] sPacketItems = sIn.Split(':'); 



So you can know in c# that button 4 is HIGH like this

Code
Select All
String BtnId = sPacketItems[0];
String BtnState = sPacketItems[1];
if (BtnState=="H")
  MessageBox.Show(String.Format("Button {0} has been pressed",BtnId));
 

« Last Edit: Dec 2nd, 2012 at 11:36pm by Tim@Visual Micro »  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #19 - Dec 2nd, 2012 at 11:21pm
Print Post  
Perfect!!! Thank you Tim. Cheesy

I will put these codes in good practice you'll hear from me soon Smiley
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #20 - Dec 2nd, 2012 at 11:24pm
Print Post  
By the way you should not define SoftwareSerial as Serial1 because some arduino boards have numerous serial ports and Serial1 will certainly fail. 
If you switch board in the future you will have to rewrite your code. A good rule... Don't prefix softwareSerial variables with "Serial". "mySerial1" would work, or something that you like. 
« Last Edit: Dec 2nd, 2012 at 11:25pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How can i read data from my ARDUINO without using serial port
Reply #21 - Dec 2nd, 2012 at 11:32pm
Print Post  
Modified my example. It was a bit confusing with the HIGH/LOW indicator and thanks to Ray for the help.
« Last Edit: Dec 2nd, 2012 at 11:35pm by Tim@Visual Micro »  
Back to top
IP Logged
 
kireita
Junior Member
**
Offline


Posts: 12
Location: Dominican Republic
Joined: Nov 28th, 2012
Re: How can i read data from my ARDUINO without using serial port
Reply #22 - Dec 2nd, 2012 at 11:34pm
Print Post  
Tim@Visual Micro wrote on Dec 2nd, 2012 at 11:24pm:
By the way you should not define SoftwareSerial as Serial1 because some arduino boards have numerous serial ports and Serial1 will certainly fail. 
If you switch board in the future you will have to rewrite your code. A good rule... Don't prefix softwareSerial variables with "Serial". "mySerial1" would work, or something that you like. 


That makes perfect sense.

ill give it another name and see how it works out. Smiley once again thank you for those codes  Cheesy. you are like a programming guru hehehe XD.
  
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 
Send TopicPrint