arduino and c#

Hi forum!
I wrote a simple piece of code for arduino that will return 1 if a switch is pressed and 0 otherwise. The goal is learn how to send data from arduino to a c# interface.
I read this tut:

Unfortunatelly I´m not getting "0" and "1" when I set the textbox multiline property to false! instead I get "0/r/n" or "1/r/n" . Obviously that when I try to convert the string to int I get an error...
What should I do to get only "0" and "1"?

Hope you can help me!
best regards and thanks for your time!

Eduardo

Change "Serial.println" to "Serial.print".

Coding Badly!
Thanks! That´s it, you solved my problem! :wink:

Thanks again! :slight_smile:
cheers,
Eduardo

Hi!
As I´m improving my skills a lot of doubts are appearing :-?

#Q1 -" How can we separate serial data coming from arduino??"
I´m getting data in c# using this small piece of code:

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            RxString = serialPort1.ReadExisting();//this is a string to collect data
            this.Invoke(new EventHandler(DisplayText));
        }

The problem is that the string is being populated with all the received data in a serial mode, i.e, something like {00000000000000111111111100000000011111111000000}
How can I get the instant port value at c#, i.e , only {0} or only {1} ?

#Q2 -"How can we get data from 2 switches?"
Now Imagine that I´ve 2 switches (A and B) .They are connected to different ports. I want to press switchA to activate a C #stopwatch, and switch B will stop the C # stopwatch.
Ok, the problem is... How can I mark data coming from arduino as data belonging to swtich A and data belonging to switch B? If this not happen I will not be able to distinguish between them, and I wil get {0000000011111000000111110000000011111}...

Could you give me some help to move ahead ?

thanks for your time!

Best Regards

Eduardo

I´ve alredy solved Q2...
But Q1 is unsolved yet ::slight_smile:
could you help me? :wink:

rgds
Eduardo

You should only receve one byte for each time you press a switch right ?

so when your datarecieved event is triggered if there are multiple bytes it is probably because you are not debouncing the switches in the Arduinocode so they are sending multiple bytes when you press it.

Hi mates!
Thanks for all answers and sorry for this late reply!
However during these weekends I didn´t have enough free time to have fun with arduino! Btw, I solved the problem with your kindly help!
Thanks for all!
Now as soon as possible I will try to write data (collected by a sensor) to a memory card. Hope you can help me ;D

Best

Eduardo