C# 使用蓝牙将ASCII从C发送到Arduino

C# 使用蓝牙将ASCII从C发送到Arduino,c#,bluetooth,arduino,C#,Bluetooth,Arduino,我正在尝试将我的C应用程序从笔记本电脑连接到Arduino。蓝牙模块连接到Arduino上的Tx和Rx引脚。我的目标是在我输入字母“a”时点亮车载LED,但到目前为止还没有成功。我确信蓝牙已连接到我的笔记本电脑,但它没有响应我正在按的字母 C代码 阿杜伊诺代码 我发送的ASCII码是错误的还是遗漏了什么?可能与我回答的问题相同 我最近涉足了这一领域。Arduino在启动时自动复位 从Arduino以外的大多数设备接收串行通信 石斑鱼类。这就是为什么您可以从IDE发送,但不能从node.js发送

我正在尝试将我的C应用程序从笔记本电脑连接到Arduino。蓝牙模块连接到Arduino上的Tx和Rx引脚。我的目标是在我输入字母“a”时点亮车载LED,但到目前为止还没有成功。我确信蓝牙已连接到我的笔记本电脑,但它没有响应我正在按的字母

C代码 阿杜伊诺代码
我发送的ASCII码是错误的还是遗漏了什么?

可能与我回答的问题相同

我最近涉足了这一领域。Arduino在启动时自动复位 从Arduino以外的大多数设备接收串行通信 石斑鱼类。这就是为什么您可以从IDE发送,但不能从node.js发送

我有一个Uno,在复位和接地之间放了一个电容器 页面上有一些关于这个主题的好信息。祝你好运


可能和我回答的是同一个问题

我最近涉足了这一领域。Arduino在启动时自动复位 从Arduino以外的大多数设备接收串行通信 石斑鱼类。这就是为什么您可以从IDE发送,但不能从node.js发送

我有一个Uno,在复位和接地之间放了一个电容器 页面上有一些关于这个主题的好信息。祝你好运

public partial class Form1 : Form
{
    private Guid service = BluetoothService.SerialPort;
    private BluetoothClient bluetoothClient;

    public Form1()
    {
        InitializeComponent();

        this.KeyPreview = true;
        this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
    }

    void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 'a')
        {
            Stream peerStream = bluetoothClient.GetStream();
            Byte[] buffer = Encoding.ASCII.GetBytes("a");
            peerStream.Write(buffer, 0, buffer.Length);
        }
    }

    private void search_Click(object sender, EventArgs e)
    {
        BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
        BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
        bluetoothClient = new BluetoothClient();
        Cursor.Current = Cursors.WaitCursor;
        BluetoothDeviceInfo[] bluetoothDeviceInfo = { };
        bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
        comboBox1.DataSource = bluetoothDeviceInfo;
        comboBox1.DisplayMember = "DeviceName";
        comboBox1.ValueMember = "DeviceAddress";
        comboBox1.Focus();
        Cursor.Current = Cursors.Default;
    }

    private void Connect_Click(object sender, EventArgs e)
    {
        if (comboBox1.SelectedValue != null)
        {
            try
            {
                bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
                MessageBox.Show("Connected");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
int incomingByte = 0;   // For incoming serial data
void setup()
{
    pinMode(13, OUTPUT); // On-board LED as output
    Serial.begin(9600);     // Opens serial port, sets data rate to 9600 bit/s.
}

void loop()
{
    if (Serial.available() > 0)
    {
        // Read the incoming byte:
        incomingByte = Serial.read();

        if (incomingByte == 'a')
            digitalWrite(13, HIGH);
    }
}