Thanks for this info Gordon - and apologies for the delay in getting this updated. I think I'm really stuck on the eval aspect of how to receive data to the Puck.js. I'm sure I'm just missing something trivial in the library that once I see it, it will be so obvious. I tried to reduce the code to just a basic - send a simple vale "1" to the Arduino board, and once the board receives a value of "1" return back to the Puck a value of "1" to confirm the data.
Puck Code:
// Variables
var feather = "ff:8d:05:ae:17:64 random";
var uart;
function sendMessage() {
console.log("Trying to Connect");
NRF.requestDevice({ filters: [{ id: feather }], active:true }).then(function(device) {
//return require("ble_simple_uart").write(device, "1");
return require("ble_uart").connect(device);
}).then(function(uart) {
uart.write("1");
}).then(function() {
console.log("Message sent successfully.");
uart.on('data', function(d) {
console.log("Got:"+JSON.stringify(d));
});
});
}
// Send a message when the button is pressed
setWatch(function() {
sendMessage();
}, BTN, { edge: "rising", debounce: 50, repeat: true });
Arduino Code:
[#include](https://forum.espruino.com/search/?q=%23include) <Arduino.h>
[#include](https://forum.espruino.com/search/?q=%23include) <SPI.h>
[#include](https://forum.espruino.com/search/?q=%23include) "Adafruit_BLE.h"
[#include](https://forum.espruino.com/search/?q=%23include) "Adafruit_BluefruitLE_SPI.h"
[#include](https://forum.espruino.com/search/?q=%23include) "Adafruit_BluefruitLE_UART.h"
[#include](https://forum.espruino.com/search/?q=%23include) "BluefruitConfig.h"
[#if](https://forum.espruino.com/search/?q=%23if) SOFTWARE_SERIAL_AVAILABLE
[#include](https://forum.espruino.com/search/?q=%23include) <SoftwareSerial.h>
[#endif](https://forum.espruino.com/search/?q=%23endif)
[#define](https://forum.espruino.com/search/?q=%23define) FACTORYRESET_ENABLE 1
[#define](https://forum.espruino.com/search/?q=%23define) MINIMUM_FIRMWARE_VERSION "0.6.6"
[#define](https://forum.espruino.com/search/?q=%23define) MODE_LED_BEHAVIOUR "MODE"
[#define](https://forum.espruino.com/search/?q=%23define) LED_BUILTIN 13
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
void error(const __FlashStringHelper* err) {
Serial.println(err);
while (1);
}
int incomingByte = 0;
String readString;
void startRaceSequence() {
Serial.println(F("if statement worked"));
Serial.print("Sending Start: 1");
ble.println("1");
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial1.begin(9600);
Serial.begin(115200);
ble.echo(false);
Serial.println("Requesting Bluefruit info:");
ble.info();
Serial.println();
ble.verbose(false);
Serial.println(F("Setting device name to 'Splitz Start Beacon'"));
if (!ble.sendCommandCheckOK(F("AT+GAPDEVNAME=Splitz Start Beacon"))) {
error(F("Could not set device name?"));
}
Serial.println(F("Switching to DATA mode!"));
ble.setMode(BLUEFRUIT_MODE_DATA);
while (!ble.isConnected()) {
delay(500);
}
if (ble.isConnected()) {
Serial.println(F("BLE device is connected."));
}
}
void loop() {
while (ble.available()) {
Serial.println("Waiting for message.");
char c = ble.read();
readString += c;
delay(2);
}
if (readString.length() > 0) {
Serial.println(readString);
if (readString == "1") {
// Send back a response message after receiving "1"
ble.write("Received '1', race sequence triggered");
startRaceSequence();
}
}
readString = "";
}
I am able to send the value to the Arduino board, and can trigger a function on the Arduino board based on the value sent by the Puck (but usually only when I use the ble uart simple). But am not able to get a value back. I usually receive a CCCD error.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Thanks for this info Gordon - and apologies for the delay in getting this updated. I think I'm really stuck on the eval aspect of how to receive data to the Puck.js. I'm sure I'm just missing something trivial in the library that once I see it, it will be so obvious. I tried to reduce the code to just a basic - send a simple vale "1" to the Arduino board, and once the board receives a value of "1" return back to the Puck a value of "1" to confirm the data.
Puck Code:
Arduino Code:
I am able to send the value to the Arduino board, and can trigger a function on the Arduino board based on the value sent by the Puck (but usually only when I use the ble uart simple). But am not able to get a value back. I usually receive a CCCD error.
Any direction would be greatly appreciated!