Go Down

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

avi_soomirtee

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 Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

avi_soomirtee

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 Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

avi_soomirtee

so no one can figure this out here ? :/

zoomkat

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up