Bluetooth 处理/蓝牙到Arduino

Bluetooth 处理/蓝牙到Arduino,bluetooth,arduino,serial-port,processing,Bluetooth,Arduino,Serial Port,Processing,我想通过处理无线点亮LED 到目前为止我所拥有的 我可以(无线)使用一个叫做“Bluterm”的串行终端打开我的LED 在处理过程中,我可以通过按1或0来打开和关闭LED 如何将bluerm排除在等式之外,并使用处理通过蓝牙发送1和0 以下是我的处理代码: import processing.serial.*; Serial port; String string; void setup(){ String portName = Serial.list()[2]; //change

我想通过处理无线点亮LED

到目前为止我所拥有的

  • 我可以(无线)使用一个叫做“Bluterm”的串行终端打开我的LED
  • 在处理过程中,我可以通过按1或0来打开和关闭LED
  • 如何将bluerm排除在等式之外,并使用处理通过蓝牙发送1和0

    以下是我的处理代码:

    import processing.serial.*;
    
    Serial port;
    
    
    String string;
    void setup(){
        String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
        port = new Serial(this, portName, 9600);
        port.bufferUntil('\n');
    }
    
    void draw() {
    
      printArray(string); 
    }
    
    void keyPressed() { 
      if (key =='1'){port.write('1');}
        if (key=='0') {port.write('0');}
        }
    
        void serialEvent(Serial port) {
          string = port.readStringUntil('\n');}
    
    
    还有Arduino密码

    
    char data;
    int led = 13;
    
    void setup() { 
      pinMode(led, OUTPUT);
      Serial.begin(9600); 
    
    }
    
    void loop() { 
      if (Serial.available()>0){
        data = Serial.read(); 
      }
    
    
      if (data=='1'){
        Serial.println("HELLO");
        digitalWrite(led, HIGH);
    
    
        }
    
        else if (data=='0'){
          digitalWrite(led, LOW);
          Serial.println("BYE");}
        }
    
    
    我有点迷路了,我能和蓝牙通话吗?还是我总是需要一个终端

    如果有什么不清楚的地方,请尽管问

    谢谢你抽出时间


    Juriaan

    处理代码很有意义

    它可以做一些格式化和错误检查,但基本上都是这样:

    import processing.serial.*;
    
    Serial port;
    
    
    String string = "";
    void setup() {
      String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
      try{
        port = new Serial(this, portName, 9600);
        port.bufferUntil('\n');
      }catch(Exception e){
        e.printStackTrace();
      }
    }
    
    void draw() {
      background(0);
      text(string,10,15);
    }
    
    void keyPressed() { 
      if(port != null){
        if (key =='1') {
          port.write('1');
        }
        if (key=='0') {
          port.write('0');
        }
      }
    }
    
    void serialEvent(Serial port) {
      string = port.readString();
      if(string == null){
        println("null serial string");
        string = "";
      }
    }
    
    Arduino密码看起来也是合法的

    目前尚不清楚的是您使用的是什么蓝牙模块以及如何设置

    例如,如果您正在使用BlueSmirf之类的东西,请确保 供应

    要点是:

  • 确保您正在使用SerialPortProfile
  • 仔细检查您的接线:按照您的Arduino代码读取方式,您将连接BT模块的TX到Arduino的RX引脚0,并将BT模块的RX引脚连接到Arduino的TX引脚1注意在使用Arduino上传固件后,您可能需要执行该操作(因为pin的0和1是Arduino的硬件序列),否则转到第3点:)(建议)
  • 如果您使用具有多个硬件串行端口的Arduino(如Arduino mega),请使用这些端口(如
    Serial1
    ,而不是
    serial
    ),否则请使用波特率较低的软件串行库(如9600),避免波特率较高
  • 更新

    HC-05模块使用3.3V逻辑,而Arduino使用5V逻辑。 使用双向3.3V 5V逻辑电平转换器或电阻器,否则可能会炸坏HC-05模块:


    快速搜索返回一个详细的

    我看到你正在使用hc05蓝牙设备我自己也有这个,但我真的不知道你想用什么来发送1和0到你的hc05,你是否只使用led,因为如果它是,我可以帮上忙(如果你想用移动应用程序发送蓝牙信号,试试app store或google play store的blynk应用程序)

    你好,乔治,我用的是HC05。它是这样连接的:5V-5V,GRN-GRN,TX-RX,RX-TX。我的代码中如何暗示SPP?虽然HC05是3.3V逻辑(不是5V),但足够接近了.希望你还没有炒了你的董事会,你可以继续我上面链接的教程。