Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with Adafruit Bluefruit LE UART Friend #6

Closed
techniq opened this issue Nov 20, 2016 · 17 comments
Closed

Trouble with Adafruit Bluefruit LE UART Friend #6

techniq opened this issue Nov 20, 2016 · 17 comments

Comments

@techniq
Copy link

techniq commented Nov 20, 2016

I recently purchased Adafruit's Bluefruit LE UART Friend and have been struggling to get it working with ble-serial. I've followed Adafruit's instructions outlined here and here to wire up and flash their special version of firmata to work with the module. I am able to connect to the device successfully using their Android mobile app and control the onboard LED (pin 13) of my Arduino Nano using their app.

When using ble-serial and firmata.js, I succesfully connect (blue connection light on the module turns on), but it just hangs (I never see the 'board created' log message).

var BLESerialPort = require('ble-serial').SerialPort;
var firmata = require('firmata');

var serialPort = new BLESerialPort();

console.log('creating board...');
var board = new firmata.Board(serialPort, function (err, ok) {
  console.log('board created'); // <-- Never get here
  if (err){ throw err; }
  console.log('writing high...');
  board.digitalWrite(13, 1);
  console.log('done');
});

I ran the script with DEBUG=ble-serial set.

Click here for the logging output

 ble-serial found peripheral: { localName: 'BLE_Firmata',
  txPowerLevel: 0,
  manufacturerData: undefined,
  serviceData: [],
  serviceUuids: [ '6e400001b5a3f393e0a9e50e24dcca9e' ] } +0ms
  ble-serial connected undefined +258ms
  ble-serial discoverServices null [ Service {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    uuid: '000015301212efde1523785feabcd123',
    name: null,
    type: null,
    includedServiceUuids: null,
    characteristics: null },
  Service {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    uuid: '180a',
    name: 'Device Information',
    type: 'org.bluetooth.service.device_information',
    includedServiceUuids: null,
    characteristics: null },
  Service {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    uuid: '6e400001b5a3f393e0a9e50e24dcca9e',
    name: null,
    type: null,
    includedServiceUuids: null,
    characteristics: null } ] +3ms
  ble-serial found service Service {
  _noble: 
   Noble {
     state: 'poweredOn',
     address: '00:1a:7d:da:71:13',
     _bindings: 
      NobleBindings {
        _peripherals: [Object],
        _xpcConnection: [Object],
        _events: [Object],
        _eventsCount: 38,
        sendCBMsg: [Function],
        init: [Function],
        startScanning: [Function],
        stopScanning: [Function],
        connect: [Function],
        disconnect: [Function],
        updateRssi: [Function],
        discoverServices: [Function],
        discoverIncludedServices: [Function],
        discoverCharacteristics: [Function],
        read: [Function],
        write: [Function],
        broadcast: [Function],
        notify: [Function],
        discoverDescriptors: [Function],
        readValue: [Function],
        writeValue: [Function],
        readHandle: [Function],
        writeHandle: [Function] },
     _peripherals: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _services: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _characteristics: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _descriptors: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _discoveredPeripheralUUids: [ '5942b53822a94b219aaf79447595da4e' ],
     _events: 
      { warning: [Function: bound ],
        stateChange: [Function],
        discover: [Function] },
     _eventsCount: 3,
     _allowDuplicates: false },
  _peripheralId: '5942b53822a94b219aaf79447595da4e',
  uuid: '000015301212efde1523785feabcd123',
  name: null,
  type: null,
  includedServiceUuids: null,
  characteristics: null } +3ms
  ble-serial found service Service {
  _noble: 
   Noble {
     state: 'poweredOn',
     address: '00:1a:7d:da:71:13',
     _bindings: 
      NobleBindings {
        _peripherals: [Object],
        _xpcConnection: [Object],
        _events: [Object],
        _eventsCount: 38,
        sendCBMsg: [Function],
        init: [Function],
        startScanning: [Function],
        stopScanning: [Function],
        connect: [Function],
        disconnect: [Function],
        updateRssi: [Function],
        discoverServices: [Function],
        discoverIncludedServices: [Function],
        discoverCharacteristics: [Function],
        read: [Function],
        write: [Function],
        broadcast: [Function],
        notify: [Function],
        discoverDescriptors: [Function],
        readValue: [Function],
        writeValue: [Function],
        readHandle: [Function],
        writeHandle: [Function] },
     _peripherals: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _services: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _characteristics: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _descriptors: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _discoveredPeripheralUUids: [ '5942b53822a94b219aaf79447595da4e' ],
     _events: 
      { warning: [Function: bound ],
        stateChange: [Function],
        discover: [Function] },
     _eventsCount: 3,
     _allowDuplicates: false },
  _peripheralId: '5942b53822a94b219aaf79447595da4e',
  uuid: '180a',
  name: 'Device Information',
  type: 'org.bluetooth.service.device_information',
  includedServiceUuids: null,
  characteristics: null } +5ms
  ble-serial found service Service {
  _noble: 
   Noble {
     state: 'poweredOn',
     address: '00:1a:7d:da:71:13',
     _bindings: 
      NobleBindings {
        _peripherals: [Object],
        _xpcConnection: [Object],
        _events: [Object],
        _eventsCount: 38,
        sendCBMsg: [Function],
        init: [Function],
        startScanning: [Function],
        stopScanning: [Function],
        connect: [Function],
        disconnect: [Function],
        updateRssi: [Function],
        discoverServices: [Function],
        discoverIncludedServices: [Function],
        discoverCharacteristics: [Function],
        read: [Function],
        write: [Function],
        broadcast: [Function],
        notify: [Function],
        discoverDescriptors: [Function],
        readValue: [Function],
        writeValue: [Function],
        readHandle: [Function],
        writeHandle: [Function] },
     _peripherals: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _services: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _characteristics: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _descriptors: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _discoveredPeripheralUUids: [ '5942b53822a94b219aaf79447595da4e' ],
     _events: 
      { warning: [Function: bound ],
        stateChange: [Function],
        discover: [Function] },
     _eventsCount: 3,
     _allowDuplicates: false },
  _peripheralId: '5942b53822a94b219aaf79447595da4e',
  uuid: '6e400001b5a3f393e0a9e50e24dcca9e',
  name: null,
  type: null,
  includedServiceUuids: null,
  characteristics: null } +3ms
  ble-serial found characteristics null [ Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '000015301212efde1523785feabcd123',
    uuid: '000015321212efde1523785feabcd123',
    name: null,
    type: null,
    properties: [ 'writeWithoutResponse' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '000015301212efde1523785feabcd123',
    uuid: '000015311212efde1523785feabcd123',
    name: null,
    type: null,
    properties: [ 'write', 'notify' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '000015301212efde1523785feabcd123',
    uuid: '000015341212efde1523785feabcd123',
    name: null,
    type: null,
    properties: [ 'read' ],
    descriptors: null } ] +139ms
  ble-serial found characteristic: 000015321212efde1523785feabcd123 +3ms
  ble-serial found characteristic: 000015311212efde1523785feabcd123 +0ms
  ble-serial found characteristic: 000015341212efde1523785feabcd123 +0ms
  ble-serial missing characteristics +1ms
  ble-serial found characteristics null [ Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '180a',
    uuid: '2a29',
    name: 'Manufacturer Name String',
    type: 'org.bluetooth.characteristic.manufacturer_name_string',
    properties: [ 'read' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '180a',
    uuid: '2a24',
    name: 'Model Number String',
    type: 'org.bluetooth.characteristic.model_number_string',
    properties: [ 'read' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '180a',
    uuid: '2a28',
    name: 'Software Revision String',
    type: 'org.bluetooth.characteristic.software_revision_string',
    properties: [ 'read' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '180a',
    uuid: '2a26',
    name: 'Firmware Revision String',
    type: 'org.bluetooth.characteristic.firmware_revision_string',
    properties: [ 'read' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '180a',
    uuid: '2a27',
    name: 'Hardware Revision String',
    type: 'org.bluetooth.characteristic.hardware_revision_string',
    properties: [ 'read' ],
    descriptors: null } ] +62ms
  ble-serial found characteristic: 2a29 +4ms
  ble-serial found characteristic: 2a24 +1ms
  ble-serial found characteristic: 2a28 +0ms
  ble-serial found characteristic: 2a26 +0ms
  ble-serial found characteristic: 2a27 +0ms
  ble-serial missing characteristics +0ms
  ble-serial found characteristics null [ Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '6e400001b5a3f393e0a9e50e24dcca9e',
    uuid: '6e400003b5a3f393e0a9e50e24dcca9e',
    name: null,
    type: null,
    properties: [ 'notify' ],
    descriptors: null },
  Characteristic {
    _noble: 
     Noble {
       state: 'poweredOn',
       address: '00:1a:7d:da:71:13',
       _bindings: [Object],
       _peripherals: [Object],
       _services: [Object],
       _characteristics: [Object],
       _descriptors: [Object],
       _discoveredPeripheralUUids: [Object],
       _events: [Object],
       _eventsCount: 3,
       _allowDuplicates: false },
    _peripheralId: '5942b53822a94b219aaf79447595da4e',
    _serviceUuid: '6e400001b5a3f393e0a9e50e24dcca9e',
    uuid: '6e400002b5a3f393e0a9e50e24dcca9e',
    name: null,
    type: null,
    properties: [ 'writeWithoutResponse', 'write' ],
    descriptors: null } ] +78ms
  ble-serial found characteristic: 6e400003b5a3f393e0a9e50e24dcca9e +4ms
  ble-serial found characteristic: 6e400002b5a3f393e0a9e50e24dcca9e +0ms
  ble-serial have both characteristics Characteristic {
  _noble: 
   Noble {
     state: 'poweredOn',
     address: '00:1a:7d:da:71:13',
     _bindings: 
      NobleBindings {
        _peripherals: [Object],
        _xpcConnection: [Object],
        _events: [Object],
        _eventsCount: 38,
        sendCBMsg: [Function],
        init: [Function],
        startScanning: [Function],
        stopScanning: [Function],
        connect: [Function],
        disconnect: [Function],
        updateRssi: [Function],
        discoverServices: [Function],
        discoverIncludedServices: [Function],
        discoverCharacteristics: [Function],
        read: [Function],
        write: [Function],
        broadcast: [Function],
        notify: [Function],
        discoverDescriptors: [Function],
        readValue: [Function],
        writeValue: [Function],
        readHandle: [Function],
        writeHandle: [Function] },
     _peripherals: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _services: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _characteristics: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _descriptors: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _discoveredPeripheralUUids: [ '5942b53822a94b219aaf79447595da4e' ],
     _events: 
      { warning: [Function: bound ],
        stateChange: [Function],
        discover: [Function] },
     _eventsCount: 3,
     _allowDuplicates: false },
  _peripheralId: '5942b53822a94b219aaf79447595da4e',
  _serviceUuid: '6e400001b5a3f393e0a9e50e24dcca9e',
  uuid: '6e400002b5a3f393e0a9e50e24dcca9e',
  name: null,
  type: null,
  properties: [ 'writeWithoutResponse', 'write' ],
  descriptors: null } Characteristic {
  _noble: 
   Noble {
     state: 'poweredOn',
     address: '00:1a:7d:da:71:13',
     _bindings: 
      NobleBindings {
        _peripherals: [Object],
        _xpcConnection: [Object],
        _events: [Object],
        _eventsCount: 38,
        sendCBMsg: [Function],
        init: [Function],
        startScanning: [Function],
        stopScanning: [Function],
        connect: [Function],
        disconnect: [Function],
        updateRssi: [Function],
        discoverServices: [Function],
        discoverIncludedServices: [Function],
        discoverCharacteristics: [Function],
        read: [Function],
        write: [Function],
        broadcast: [Function],
        notify: [Function],
        discoverDescriptors: [Function],
        readValue: [Function],
        writeValue: [Function],
        readHandle: [Function],
        writeHandle: [Function] },
     _peripherals: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _services: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _characteristics: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _descriptors: { '5942b53822a94b219aaf79447595da4e': [Object] },
     _discoveredPeripheralUUids: [ '5942b53822a94b219aaf79447595da4e' ],
     _events: 
      { warning: [Function: bound ],
        stateChange: [Function],
        discover: [Function] },
     _eventsCount: 3,
     _allowDuplicates: false },
  _peripheralId: '5942b53822a94b219aaf79447595da4e',
  _serviceUuid: '6e400001b5a3f393e0a9e50e24dcca9e',
  uuid: '6e400003b5a3f393e0a9e50e24dcca9e',
  name: null,
  type: null,
  properties: [ 'notify' ],
  descriptors: null } +0ms
  ble-serial notify null +149ms
  ble-serial writing <Buffer f9> +4s
  ble-serial writing <Buffer f0 79 f7> +1ms
  ble-serial read <Buffer f9 02 03> true +86ms


Any thoughts on how I can troubleshoot further?

@techniq
Copy link
Author

techniq commented Nov 26, 2016

@monteslu @soundanalogous Any thoughts on this? It seems like an issue with ble-serial or firmata.js but I'm having difficulty troubleshooting further (I'm reading up on the firmata spec to better understand).

Maybe a timing issue over the BLE connection since I see writing/reading of the data, but ready is never emitted...

  ...
  ble-serial notify null +149ms
  ble-serial writing <Buffer f9> +4s
  ble-serial writing <Buffer f0 79 f7> +1ms
  ble-serial read <Buffer f9 02 03> true +86ms

See full log output in issue description above.

@soundanalogous
Copy link
Contributor

Try setting skipCapabilities to true like this:

var board = new firmata.Board(serialPort, {skipCapabilities: true}, function (err, ok) {
  console.log('board created'); // <-- Never get here
  if (err){ throw err; }
  console.log('writing high...');
  board.digitalWrite(13, 1);
  console.log('done');
});

@techniq
Copy link
Author

techniq commented Nov 26, 2016

@soundanalogous same result (no ready emitted)

  ble-serial notify null +150ms
  ble-serial writing <Buffer f9> +4s
  ble-serial writing <Buffer f0 79 f7> +2ms
  ble-serial read <Buffer f9 02 03> true +131ms

@techniq
Copy link
Author

techniq commented Nov 26, 2016

I'm currently using:

Not sure if this will help, but here's a picture of it wired up and connected (blue led).
img_20161126_173105


Here is also the serial debug output from the Nano:
screen shot 2016-11-26 at 5 34 27 pm


I've also chatted via an issue with Adafruit as I initially thought this was an issue with the board/custom firmata version, but I am able to use their Android app to control the onboard LED on the Nano.

Btw, you have an issue open about them using an old version of firmata. Not sure if this has any relevancy to the issue.

@soundanalogous
Copy link
Contributor

Try this:

var BLESerialPort = require('ble-serial').SerialPort;
var firmata = require('firmata');

// seeing if swapping RX and TX makes any difference:
var serialPort = new BLESerialPort({
  receiveCharacteristic: '6e400002b5a3f393e0a9e50e24dcca9e',
  transmitCharacteristic: '6e400003b5a3f393e0a9e50e24dcca9e'
});

console.log('creating board...');
// because the payload of the capability reply is huge and will crash if the
// packets are not buffered properly from the firmware
var opts = {skipCapabilities: true};
var board = new firmata.Board(serialPort, opts, function (err, ok) {
  console.log('board created'); // <-- Never get here
  if (err){ throw err; }
  console.log('writing high...');
  board.digitalWrite(13, 1);
  console.log('done');
});

@techniq
Copy link
Author

techniq commented Nov 26, 2016

Using the above, I now only get the write debug messages:

  ble-serial writing <Buffer f9> +4s
  ble-serial writing <Buffer f0 79 f7> +1ms

Swapping TX/RX errors in the Arduino serial console that it can't find the communicate with the Bluefruit:

Adafruit Bluefruit LE Firmata test
Total pins: 20
Analog pins: 0
Initialising the Bluefruit LE module: ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?

I need to step away for a few hours but would love to troubleshoot later tonight (or when you have something else to try). Thanks again for you help. I've been trying to get this to work for the last week off and on with only frustration to show for it.

@soundanalogous
Copy link
Contributor

That's about all as I can do on the javascript since I don't maintain ble-serial. You'll have to wait for @monteslu to help. I maintain Firmata, but since you're using a modified version from Adafruit that I'm not even sure is compatible with firmata.js, that makes things much more complicated.

I do know that an Arduino 101 will work with StandardFirmataBLE and ble-serial out of the box. The Red Bear Labs BLE Nano is also compatible, but requires some modification to the RBL firmware.

@techniq
Copy link
Author

techniq commented Nov 27, 2016

Thanks for the help. Hopefully @monteslu has some ideas I can try.

It would be nice if I could use StandardFirmataBLE, but I guess that will have to wait for this issue if it does come. Adafruit's Bluefruit LE UART Friend is based on the same nRF51822 chip as Red Bear Labs' so it seems like it wouldn't be too far off to get supported (says the guy not doing the work though :) ).

I currently have an existing project using a Nano with a large number of its pins being utilized (it has 3 stepper motors drivers, 2 large CIM motors with an external motor driver using PWM, and a couple potentiometers (not wired in the picture)). This is actually for the same project I still need to test some issues with ConfigurableFirmata for you (I haven't had the motors in my possession since the report and have been on vacation this week, but plan to test things out once I do).

img_20161110_233531

Currently this project utilizes a Raspberry PI which which acts as a wireless AP and hosts a mobile webapp, and powers/interfaces the nano over USB. I was looking to simplify this (and speed up power to connect time) by writing a React Native app that drives the Nano remotely. I initially started with bluetooth classic using a JY-MCU, but I was having trouble figuring out how to do this via react-native (as on my Mac it just creates a virtual /dev/tty* interface).

This then lead me down the path of using ble-serial (and react-native-ble, which ultimately can polyfill noble). It seems like this direction has promise if I can get over this initial roadblock.

Btw, I just tried to connect over to the Nano over USB (flashed with Adafruit's firmata sketch) and it doesn't connect either, but this could be due to not supporting this type of communication.

Sorry for the long, and mostly off topic, comment on this issue. I appreciate your help and hopefully @monteslu has some ideas (although it could stem from a firmata compatibility issue which I'm not sure how/when that might get fixed if so).

If their was another BLE hardware module that could work with my existing Arduino and worked with ble-serial better, I would purchase it in a heartbeat.

@soundanalogous
Copy link
Contributor

Wait... the Bluefruit LE UART is just a UART to BLE converter. That should just work with StandardFirmata, you don't need any BLE libraries on the board. Looks like the only thing you'd need to change is the baud rate (from 57600 to 9600).

@techniq
Copy link
Author

techniq commented Nov 27, 2016

@soundanalogous I flashed the Nano with StandardFirmata, and moved the TX/RX pins from 9/10 (was setup for software serial under Adafruit's firmata) to pins 0/1 on the Nano.

I then tried running the following, setting the baud rate to 9600:

var BLESerialPort = require('ble-serial').SerialPort;
var Board = require('firmata').Board;
var serialPort = new BLESerialPort();

var opts = {
  serialport: {
    baudrate: 9600,
    buffersize: 1
  }
};
console.log('creating board...');
var board = new Board(serialPort, opts, function (err, ok) {
  console.log('board created');
  if (err){ throw err; }
  console.log('writing high...');
  board.digitalWrite(13, 1);
  console.log('done');
})

I now only see the writing (no reading) in the logs:

  ble-serial notify null +134ms
  ble-serial writing <Buffer f9> +4s
  ble-serial writing <Buffer f0 79 f7> +1ms

I tried swapping RX/TX pins with the same result. Tomorrow I'll pull out my JY-MCU Bluetooth Classic module and make sure it still works in a similar setup with my Nano running StandardFirmata. It eliminates the ble-serial module since when I pair to the JY-MCU I then access it via the /dev/LynchBot serial device on my Mac (the name I setup following this guide).

@techniq
Copy link
Author

techniq commented Nov 27, 2016

I forgot I would need to set the baud rate within StandardFirmata as well. Changing Firmata.begin(57600); to Firmata.begin(9600); didn't improve anything though.

I did come across something interesting though. While making sure I had the baud rate setup, I decided to test it over USB using the following:

var Board = require('firmata').Board;

var opts = {
  serialport: {
    baudrate: 9600,
    buffersize: 1
  }
};

console.log('creating board...');
var board = new Board('/dev/tty.wchusbserialfd130', opts, function (err, ok) {
  console.log('board created');
  if (err){ throw err; }
  console.log('writing high...');
  board.digitalWrite(13, 1);
  console.log('done');
});

This works successfully as long as the RX/TX pins are also not plugged into the Bluefruit UART module, but hangs when they are.

I had oddities when trying to use pins 0/1 when I first started with the Bluefruit UART and is one reason I was using software serial on pins 9/10. Also, leaving these connected causes errors when attempting to upload sketches from the Arduino IDE:

Sketch uses 11,114 bytes (36%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,031 bytes (50%) of dynamic memory, leaving 1,017 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
An error occurred while uploading the sketch

@techniq
Copy link
Author

techniq commented Nov 28, 2016

@soundanalogous I decided to try to get my Bluetooth Classic JY-MCU working at 9600 baud rate and in hopes to reveal an issue with my BLE setup but I'm having difficulty. I'm using the same Arduino Nano, and all works fine with the default StandardFirmata (running at 57600), but if I try switching to 9600, I receive errors.

I'm changing this line from Firmata.begin(57600); to Firmata.begin(9600); and then running the following sketch (I'm using Johnny-Five in this example, but shoudn't matter I don't believe:

var five = require("johnny-five");
var SerialPort = require("serialport").SerialPort;

var board = new five.Board({
  port: new SerialPort('/dev/tty.LynchBot-DevB', {
    baudrate: 9600,
    buffersize: 1
  })
});

board.on('ready', function() {
  this.pinMode(13, this.MODES.OUTPUT);

  this.loop(500, () => {
    this.digitalWrite(13, this.pins[13].value ? 0 : 1);
  });
});

This is the error:

➜  johnny-five-bluetooth node index.js
1480356380920 SerialPort /dev/tty.LynchBot-DevB  
1480356380923 Connected /dev/tty.LynchBot-DevB  
1480356390929 Device or Firmware Error A timeout occurred while connecting to the Board. 

Please check that you've properly flashed the board with the correct firmware.
See: https://github.com/rwaldron/johnny-five/wiki/Getting-Started#trouble-shooting

If connecting to a Leonardo or Leonardo clone, press the 'Reset' button on the board, wait approximately 11 seconds for complete reset, then run your program again.  
events.js:165
      throw err;
      ^

Error: Uncaught, unspecified "error" event. ([object Object])
    at Board.emit (events.js:163:17)
    at Board.log (/Users/smlynch/Development/playground/johnny-five-bluetooth/node_modules/johnny-five/lib/board.js:630:8)
    at Board.(anonymous function) [as error] (/Users/smlynch/Development/playground/johnny-five-bluetooth/node_modules/johnny-five/lib/board.js:641:14)
    at Board.<anonymous> (/Users/smlynch/Development/playground/johnny-five-bluetooth/node_modules/johnny-five/lib/board.js:390:14)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

If I switch back to Firmata.begin(57600); and rerun the code above (leaving baudrate: 9600), it connects and runs just fine, which I figured shouldn't with the baudrate mismatch.

Thoughts?

Btw, here's a picture of the setup (probably not useful). This also has the issue if I leave TX/RX hooked up I receive the stk500_getsync() errors, so I just unplug them temporarily when I flash the Nano.

img_20161128_130130

@techniq
Copy link
Author

techniq commented Nov 28, 2016

Btw, I also just tried an uppercase R for baudRate and removing buffersize...

...
var board = new five.Board({
  port: new SerialPort('/dev/tty.LynchBot-DevB', {
    baudRate: 9600
  })
});
...

...after seeing it defined this way in the docs, but it had no improvement.

@monteslu
Copy link
Owner

thanks for all the details. I'll have a BLEFriend device with me tomorrow to try and replicate. In the meantime, it does look like there's an AT command for setting the baud rate on the BLEFriend itself if you want to try that.

@techniq
Copy link
Author

techniq commented Nov 29, 2016

@monteslu You are awesome 😄

I didn't realize you could change the baud rate based on this:

screen shot 2016-11-29 at 9 56 15 am


I found the docs and changed it to 57600 using AT+BAUDRATE=57600 (after first toggling the slide switch to CMD, although you can also switch using +++ while in UART mode) and it works!!!

Just a heads up if/when you test it yourself, don't forget to also set CTS to ground if using hardware UART. Here's a picture of my successful setup:

img_20161129_111044

Now I can move on to getting this to work on a phone using React Native and react-native-ble (hopefully...)

Thanks @monteslu and @soundanalogous for all your help.

@techniq techniq closed this as completed Nov 29, 2016
@soundanalogous
Copy link
Contributor

@techniq did you end up using StandardFirmata or Adafruit's modified version?

@techniq
Copy link
Author

techniq commented Nov 29, 2016

StandardFirmata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants