Lots of progress - thank you both for your patience and guidance!!! In the process, I'm learning a lot about the environments (BLE, Aurduino, and Espruino).
I have the Puck and the Feather talking to each other!!! I'm not sure EXACTLY what made it happen, but I'll go with it
Here is what I have on the Puck that works.
var feather = "ff:8d:05:ae:17:64 random";
// Blink green for 100ms
function blinkGreen() {
LED2.write(true);
setTimeout(function () { LED2.write(false); }, 100);
}
// Function to send a message
function sendMessage() {
console.log("Trying to Connect");
NRF.requestDevice({ filters: [{ id: feather }], active:true }).then(function(device) {
print(device);
return require("ble_simple_uart").write(device, "true");
}).then(function() {
console.log('Done!');
});
}
// Send a message when the button is pressed
setWatch(function() {
blinkGreen();
sendMessage();
}, BTN, { edge: "rising", debounce: 50, repeat: true });
Here is what I have on the Feather. I am able to read the serial and then I have an if statement to check the value and if it matches then it triggers another function. This is just a simple example to test it, but it works.
[#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);
// 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)
*/
/**************************************************************************/
int incomingByte = 0; // for incoming serial data
String readString;
void testFunction(){
Serial.println(F("if statement worked"));
}
void setup() {
// Start the hardware serial communication at 9600 baud rate
Serial.begin(115200); // Serial Monitor
Serial1.begin(115200); // UART Communication (Replace Serial1 with appropriate Serial for your Feather)
/* Initialise the module */
Serial.print(F("Initialising the Splitz Start Beacon"));
Serial.println(F("---------------------------------------"));
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();
ble.verbose(false); // debug info is a little annoying after this point!
/* Change the device name to make it easier to find */
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?"));
}
// Set module to DATA mode
Serial.println( F("Switching to DATA mode!") );
ble.setMode(BLUEFRUIT_MODE_DATA);
/* Wait for connection */
while (! ble.isConnected()) {
delay(500);
}
if(ble.isConnected()){
Serial.println(F("Device is connected."));
}
pinMode(13, OUTPUT); // Optional: Use the built-in LED to indicate received data
}
void loop() {
// Echo received data
while ( ble.available() )
{
char c = ble.read();
readString += c; //makes the String readString
delay(3); //slow looping to allow buffer to fill with next character
}
if (readString.length() > 0) {
Serial.println(readString); //so you can see the captured String
if (readString == "true"){
testFunction();
}
readString = "";
}
}
The only issue is that it disconnects after it sends the info. How would I be able to persist the connection?
I tried the below. It connects to the board but doesn't write to the serial like "requestDevice " did.
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.
Lots of progress - thank you both for your patience and guidance!!! In the process, I'm learning a lot about the environments (BLE, Aurduino, and Espruino).
I have the Puck and the Feather talking to each other!!! I'm not sure EXACTLY what made it happen, but I'll go with it
Here is what I have on the Puck that works.
Here is what I have on the Feather. I am able to read the serial and then I have an if statement to check the value and if it matches then it triggers another function. This is just a simple example to test it, but it works.
The only issue is that it disconnects after it sends the info. How would I be able to persist the connection?
I tried the below. It connects to the board but doesn't write to the serial like "requestDevice " did.