• I've got the Puck to connect and return the promise using requestDevice. I just don't see the result on the Arduino board. I know they connect.

    // Blink green for 100ms
    function blinkGreen() {
      LED2.write(true);
      setTimeout(function () { LED2.write(false); }, 100);
    }
    
    // Function to send a message
    function sendMessage(message) {
      NRF.requestDevice({ filters: [{ id: 'ff:8d:05:ae:17:64 random' }], timeout: 2000, active:true }).then(function(device) {
        print(device);
        return require("ble_simple_uart").write(device,­ message);
        }).then(function() {
          print('Done!');
      });
    }
    
    // Send a message when the button is pressed
    setWatch(function() {
      sendMessage("Hello, Arduino!/n");
      blinkGreen();
    }, BTN, { edge: "rising", debounce: 50, repeat: true });
    

    This is my arduino code with the libraries included.

    [#include](https://forum.espruino.com/se­arch/?q=%23include) <Arduino.h>
    [#include](https://forum.espruino.com/se­arch/?q=%23include) <SPI.h>
    [#include](https://forum.espruino.com/se­arch/?q=%23include) "Adafruit_BLE.h"
    [#include](https://forum.espruino.com/se­arch/?q=%23include) "Adafruit_BluefruitLE_SPI.h"
    [#include](https://forum.espruino.com/se­arch/?q=%23include) "Adafruit_BluefruitLE_UART.h"
    
    [#include](https://forum.espruino.com/se­arch/?q=%23include) "BluefruitConfig.h"
    
    [#if](https://forum.espruino.com/search/­?q=%23if) SOFTWARE_SERIAL_AVAILABLE
      [#include](https://forum.espruino.com/se­arch/?q=%23include) <SoftwareSerial.h>
    [#endif](https://forum.espruino.com/sear­ch/?q=%23endif)
    
    /*======================================­===================================
        ----------------------------------------­-------------------------------*/
        [#define](https://forum.espruino.com/sea­rch/?q=%23define) FACTORYRESET_ENABLE         1
        [#define](https://forum.espruino.com/sea­rch/?q=%23define) MINIMUM_FIRMWARE_VERSION    "0.6.6"
        [#define](https://forum.espruino.com/sea­rch/?q=%23define) MODE_LED_BEHAVIOUR          "MODE"
        [#define](https://forum.espruino.com/sea­rch/?q=%23define) LED_BUILTIN                 13
    /*======================================­===================================*/
    
    Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
    
    // A small helper
    void error(const __FlashStringHelper*err) {
      Serial.println(err);
      while (1);
    }
    
    /***************************************­***********************************/
    /*!
        @brief  Sets up the HW an the BLE module (this function is called
                automatically on startup)
    */
    /***************************************­***********************************/
    
    void setup() {
      // Start the hardware serial communication at 9600 baud rate
      Serial.begin(9600); // Serial Monitor
      Serial1.begin(9600); // UART Communication (Replace Serial1 with appropriate Serial for your Feather)
    
      Serial.println(F("Adafruit Bluefruit Command Mode Example"));
        Serial.println(F("----------------------­-----------------"));
    
        /* Initialise the module */
        Serial.print(F("Initialising the Bluefruit LE module: "));
    
        if ( !ble.begin(VERBOSE_MODE) ){
          error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
        }
        Serial.println( F("OK!") );
    
        if ( FACTORYRESET_ENABLE ){
          /* Perform a factory reset to make sure everything is in a known state */
          Serial.println(F("Performing a factory reset: "));
          if ( ! ble.factoryReset() ){
            error(F("Couldn't factory reset"));
          }
        }
    
        /* Disable command echo from Bluefruit */
        ble.echo(false);
    
        Serial.println("Requesting Bluefruit info:");
        /* Print Bluefruit information */
        ble.info();
    
        Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
        Serial.println(F("Then Enter characters to send to Bluefruit"));
        Serial.println();
    
        ble.verbose(false);  // debug info is a little annoying after this point!
    
        /* Wait for connection */
        while (! ble.isConnected()) {
            delay(500);
        }
    
        while(ble.isConnected()){
          Serial.println(F("Device is connected."));
          delay(5000);
        }
    
        pinMode(13, OUTPUT); // Optional: Use the built-in LED to indicate received data
    }
    
    void loop() {
      // Check if there is any data available on Serial1
      Serial.println("Serial is Available");
      if (Serial.available()) {
        Serial.println("Serial is Available");
        // Read the incoming byte
        String incomingMessage = "";
        while (Serial.available()) {
          char incomingByte = Serial.read();
          incomingMessage += incomingByte;
        }
        // Print the incoming message to the Serial Monitor
        Serial.println("Received: " + incomingMessage);
        
        // Optional: Blink LED to indicate message received
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
      }
    }
    
  • I just don't see the result on the Arduino board.

    you should perhaps work with the ble object to read/write data, something like

      while ( ble.available() )
      {
        Serial.print(ble.read());
      }
    

    inside the loop could get the data?

About

Avatar for fanoush @fanoush started