App inventor / Arduino Nano33Ble BlueTooth - Communication issue

Hi everybody, being a newbie in App Inventor, I am looking for support, regarding an issue with the building of the Bluetooth App for a Moto g(9) SmartPhone. I have tried several times to upload an MIT APP INVENTOR app with no success. I can only display the app on the phone, but it does not scan neither offer the option to "PAIR" nor "BOND" the Arduino Nano 33IoT that I'm using. I have managed to write data bidirectionally with a free app available from LightBlue and another one from nRFConnect. The codes as follows =>

Block Code:

Code used in the Arduino Nano 33IoT:

/*
Arduino Nano 33 BLE Getting Started
BLE peripheral with a simple Hello World greeting service that can be viewed
on a mobile phone
Adapted from Arduino BatteryMonitor example
*/

#include <ArduinoBLE.h>
byte val1=3;

static const char* greeting = "Hello World!";

BLEService greetingService("180C"); // User defined service

BLEStringCharacteristic greetingCharacteristic("2A56", // standard 16-bit characteristic UUID
BLERead, 13); // remote clients will only be able to read this

void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial);
//byte val1=3;

pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin

if (!BLE.begin()) { // initialize BLE
Serial.println("starting BLE failed!");
while (1);
}

BLE.setLocalName("Nano33BLE"); // Set name for connection
BLE.setAdvertisedService(greetingService); // Advertise service
greetingService.addCharacteristic(greetingCharacteristic); // Add characteristic to service
BLE.addService(greetingService); // Add service
greetingCharacteristic.setValue(greeting); // Set greeting string

BLE.advertise(); // Start advertising
Serial.print("Peripheral device MAC: ");
Serial.println(BLE.address());
Serial.println("Waiting for connections...");
}

void loop() {
BLEDevice central = BLE.central(); // Wait for a BLE central to connect

// if a central is connected to the peripheral:
if (central) {
Serial.print("Connected to central MAC: ");
// print the central's BT address:
Serial.println(central.address());
// turn on the LED to indicate the connection:
digitalWrite(LED_BUILTIN, HIGH);

while (central.connected()) // keep looping while connected - READINGS FOR APP GRAPH
{
    //byte val1=3;
    //int numero = 1;
    String NS = String(val1);
    greetingCharacteristic.setValue(NS);
    //myString.getBytes(buf, 10)
    Serial.write(val1);                                //Serial.write will send only one byte at a time  
    Serial.println(val1);
    val1 = val1 +1;
    delay(400);                                        //Small delay between each data send     
} 

// when the central disconnects, turn off the LED:
digitalWrite(LED_BUILTIN, LOW);
Serial.print("Disconnected from central MAC: ");
Serial.println(central.address());

}
}

Your blocks are using the pre-BLE BlueTooth component to try to connect to a Ble device.

ABG - Many THX

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.