Go Down

Topic: Serial communication from arduino to c# (Read 171 times) previous topic - next topic

Hi guys, am working on a home automation project and am implementing arduino with an AI. But am having trouble to make the arduino send an int to serial port that the AI can catch in C# and interpret it.

can anyone help me please.
thank you very much in advance. :)

wildbill

Post your code - both C# and what's on the arduino

zoomkat

Quote
can anyone help me please.
Start out using the serial monitor for testing, then move to your C application.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

code in c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;

namespace arduino_test_2
{
    class Program
    {
       
            public static void Main()
{
    SerialPort mySerialPort = new SerialPort("COM6");

    mySerialPort.BaudRate = 9600;
    mySerialPort.Parity = Parity.None;
    mySerialPort.StopBits = StopBits.One;
    mySerialPort.DataBits = 8;
    mySerialPort.Handshake = Handshake.None;

    mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

    mySerialPort.Open();

    Console.WriteLine("Press any key to continue...");
    Console.WriteLine();
    Console.ReadKey();
    mySerialPort.Close();
}

private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort sp = (SerialPort)sender;
    string indata = sp.ReadExisting();
    Console.Write("Data Received:");
    Console.Write(indata);
}

public static object on { get; set; }
    }
    }



but with this code i can only see the data, i can`t use it.

and the code for arduino its working its sending " on " when a button is pressed. But i want in c# to differentiate from all the data it gets.

it should be able to notice the " on " and do an action or an " off " to do another action..

Am stuck with it for like two weeks, plz help, that would be great if i get this to work.
thank you guys in advance

zoomkat

Quote
Am stuck with it for like two weeks, plz help, that would be great if i get this to work.
Have you looked for a C programming forum? The Processing programming application might be of use as it is apparently similar to the arduino type coding.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


zoomkat

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy