I'm having trouble getting the DF Robot Wireless Gamepad to be able to communicate with an Arduino MKR Wifi 1010 board. The MKR Wifi board uses a NINA W10 chip to handle all RF transmissions. According to the datasheet, the chip supports Bluetooth v4.2 modes. So, when I was looking at the gamepad, I decided to buy the Bluno Bee module that mates with it so that I could enable the underlying Leonardo board to send bluetooth v.4 notifications to the other Arduino MKR board. However, I'm struggling to get the two to be able to communicate with each other.
I have followed the Bluno wiki page and I've entered into AT mode and set all of the relevant commands. I've set the Bluno Bee's role to be a PERIPHERAL device (since the MKR board will be the central device). I've told it to BIND to the MAC address of the MKR board (again the command response was OK). I've set the CMODE to ANYONE although I also tried UNIQUE. I've also updated the NAME of my Bluno Bee to be "Gamepad" just so that I know what device I should be looking for. And then I've uploaded the Arduino sketch (see below) that comes with the gamepad to the Leonardo board. I made sure that I changed all the Serial.() commands to Serial1.() functions per the instructions on the wiki pages. However, I can not seem to get the Arduino to even find the Bluno Bee as a peripheral device when I try to scan.
I've tried a simple "Scan" for peripheral devices (see below) but the the code never shows the MAC address or the local name of the Bluno Bee (it should report the name Gamepad). I've also tried a more advanced scan but this fails to recognize the Bluno Bee too. I've set the baudrate in all of my sketches to 115200 so I don't think that could be the issue. And, I've used an external app on my phone (called nRF Connect) just to scan for bluetooth devices in the area and I can indeed see the device called "Gamepad" so it's definitely sending something... And yet, the Arduino never seems to be able to find the peripheral device. Does anyone have any ideas?
Uploaded to Gamepad Leonardo board:
/*
// #
// # Editor : Tong Hui from DFRobot, based on Lauren from DFRobot v1.0 code
// # Date : 18.01.2012
// # Product name: Wireless Gamepad v2.2 for Arduino
// # Product SKU : DFR0182
// # Code Version: 2.1
// # Description:
// # The sketch for using the gamepad and print the button state and the analog values of the gamepad
// # Enable the vibration function
// # Send 'v' via the Arduino Serial1 monitor to enable the vibration
// # Send 's' via the Arduino Serial1 monitor to stop it
*/
int buttonState[17];
int joystick[4];
int AnalogButton[2];
int inputCommand = 0;
#define virbrationMotorPin 2
void setup()
{
Serial1.begin(115200); //Init the Serial1 baudrate
//Serial11.begin(9600); //Init the Serial11 port to enable the xbee wireless communication
InitIO(); //Initialize the inputs/outputs and the buffers
}
void InitIO(){
for(int i = 0; i < 17; i++) pinMode(i, INPUT);
pinMode(virbrationMotorPin,OUTPUT);
digitalWrite(virbrationMotorPin,LOW); // Stop shacking of the gamepad
}
unsigned long timer = 0;
void loop()
{
if(millis() - timer > 100){ // manage the updating freq of all the controlling information
DataUpdate(); //read the buttons and the joysticks data
printData(); //print the datas and states
timer = millis();
}
if(Serial1.available()){
char input = Serial1.read();
switch(input){
case 'v':
Serial1.println("Vibration");
inputCommand = input;
digitalWrite(virbrationMotorPin,HIGH);
break;
case 's':
Serial1.println("Stop");
inputCommand = input;
digitalWrite(virbrationMotorPin,LOW);
break;
default:
break;
}
}
}
void DataUpdate(){
for(int i = 3; i < 17; i++) buttonState[i] = digitalRead(i);
buttonState[0] = analogRead(0);
buttonState[1] = analogRead(1);
for(int i = 0; i < 4; i++) joystick[i] = analogRead(i);
for(int i = 4; i < 6; i++) AnalogButton[i-4] = analogRead(i);
}
String Buttons[17] = {
"J2","J1","","S2","S1","UP","LEFT","DOWN","RIGHT","1","4","2","3","RZ1","RZ2","LZ1","LZ2"};
// Buttons Nmes
void printData(){
//for(int i = 0; i < 17; i++) Serial1.print(buttonState[i]),Serial1.print(" ");
for(int i = 0; i < 4; i++) Serial1.print(joystick[i]),Serial1.print(" ");
//for(int i = 0; i < 2; i++) Serial1.print(AnalogButton[i]),Serial1.print(" ");
Serial1.println("");
/*Serial1.print("Button Pressed:");
for(int i = 0; i < 2; i++) if(buttonState[i] < 100) Serial1.print(Buttons[i]),Serial1.print(",");
for(int i = 3; i < 17; i++) if(buttonState[i] == 0) Serial1.print(Buttons[i]),Serial1.print(",");
Serial1.println("");
Serial1.print("Analog Sticks:");
for(int i = 0; i < 4; i++) Serial1.print(joystick[i]),Serial1.print(",");
for(int i = 0; i < 2; i++) Serial1.print(AnalogButton[i]),Serial1.print(",");
Serial1.println("");
Serial1.println(inputCommand);*/
}
Uploaded to MKR Wifi 1010 Board to Scan for Peripherals:
/*
Scan
This example scans for BLE peripherals and prints out their advertising details:
address, local name, adverised service UUID's.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
void setup() {
Serial.begin(115200);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
Serial.println("BLE Central scan");
// start scanning for peripheral
BLE.scan();
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral
Serial.println("Discovered a peripheral");
Serial.println("-----------------------");
// print address
Serial.print("Address: ");
Serial.println(peripheral.address());
// print the local name, if present
if (peripheral.hasLocalName()) {
Serial.print("Local Name: ");
Serial.println(peripheral.localName());
}
// print the advertised service UUIDs, if present
if (peripheral.hasAdvertisedServiceUuid()) {
Serial.print("Service UUIDs: ");
for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
Serial.print(peripheral.advertisedServiceUuid(i));
Serial.print(" ");
}
Serial.println();
}
// print the RSSI
Serial.print("RSSI: ");
Serial.println(peripheral.rssi());
Serial.println();
}
}