Boss Detector

by drtonis in Circuits > Remote Control

2764 Views, 9 Favorites, 0 Comments

Boss Detector

2022-09-14 19.00.39.jpg
2022-09-14 19.00.56-1.jpg
2022-09-14 19.01.03.jpg

I was contacted from Seeed Studio to make a project with their new XIAO BLE products. I had already had some time in my mind a so-called boss detector project. Several years already one can see in the internet a gif about similar device. I decided to try it with the new XIAOs.

Here is a GIF from the web I found.

I thought about using two BLE boards to make the detector. One is at the door and sends an alarm to the other one that is connected to the PC and acts like a keyboard. If the movement is detected an “Alt-Tab” combination is pressed and the screen switched.

Why two BLE devices? The one on the door could act like a Bluetooth keyboard itself. However, what happens when somebody plays with the door or the “boss” is next to you and somebody else is opening the door again. To prevent multiple triggers I thought to add a reset switch to the second one and one could reset it after the air is clear again.

One can find more information about the XIAO boards on the XIAO BLE homepage

The XIAO BLE Sense has an onboard 6-axis IMU that would be perfect for this project. Alternatively, one could use a PIR sensor or some other movement registering device. The door sensor would need a battery or a discrete power cable. 

Supplies

At the beginning of September I received

  • 1x XIAO BLE nRF52840
  • 1x XIAO BLE nRF52840 Sense

They both look nice and small. I really like the dimentions and the look. Although it seems that Seeed has done a good job with the hardware the software is left behind. Yes, the blink function works, however these boards are able to do much more. I had so much difficulty getting the BLE and Keyboard working. Even the BLE example shown on the home page didn’t compile (after I contacted the technical support they made some changes and now it works). Not to mention the simple onboard RGB LED colors. The red is no problem, however I was not able to control green and blue LEDs.

In the end I made 3 different “devices”:

  • simple one connected with a cable to a PC - USB keyboard
  • Bluetooth sensor that triggers a button pressing - Bluetooth keyboard
  • Two Bluetooth devices working together

In the following chapters I talk more about each of them.

Now let's dive into the project. I received the boards and decided to test the IMU with Arduino IDE. Unfortunately, the example I got didn’t work (or it had no IMU on it). After using the I2C scanner, it was clear that there are no I2C devices connected. It’s a pity, nevertheless I decided to simulate the sensor with a mechanical switch.

I assumed that the digital input part should work, thus I focused on the Keyboard aspect. The examples in Arduino IDE were relatively complicated. However, after some detective work I managed to get an example so far that, when I triggered my “sensor”, I was able to press “a”. Nevertheless, the keyboard key stayed pressed and it was splitting “key”-s as long as I restarted the XIAO. No delay nor “button release” commands helped. Eventually after trying different methods I was not able to reprogram the board since the serial was always busy by sending the keyboard commands.

To overcome the problem I did what Adafruit recommends with their boards and installed Circuitpython. I tried (Adafruit) Circuitpython Keyboard example (link) and it worked directly without any hassle and fighting. Even the "Alt-Tab" combination worked with the first try. OK, let’s use Circuitpyhton then.

Next important step was getting Bluetooth working. For Circuitpython Seeed has basically no examples nor support. The simplest solution is to look again at what Adafruit is doing. Unfortunately, the BLE library didn’t work with XIAO and I was back to Arduino IDE. I asked Seeed technical support about Circuitpython BLE examples and they were not able to provide any.

I was already ready to give up the project when I found from Adafruit another keyboard library for Arduino IDE. With that I was able to send only a single key press and after some trials even the “Alt-Tab” combination worked. Good!

Simple USB-Keyboard

2022_09_14_11_29_12_BossDetector1_Arduino_1.8.19.jpg
Boss Detector 1

Connecting the XIAO with an USB cable to a PC makes it already a usable sensor. I attached a button between GND and D10 that behaves as my sensor. One could use something else here, the logic stays the same. 

Some important things to notice:

  • Under Boards Manager you should install “Seeed nrf52 Boards” (not the “mbed” version).
  • Install Adafruit “TinyUSB_Mouse_and_Keyboard” library (Link)

The attached code “BossDetector1.ino” should be self-explaining. After pressing the button “Alt-Tab” keys are pressed and there is one second delay before something else can be done.

Downloads

Bluetooth-Keyboard

Boss Detector 2

Back to the Bluetooth issue. I tried the simplest Bluetooth example shown on the Seeed homepage and again it didn’t work. Obviously not a very motivating situation. Where to get help? Of course from Adafruit. They had a keyboard example where I was able to use the XIAO as a Bluetooth keyboard. It worked exactly as it should. 

Some important things to notice:

  • Under Boards Manager you should install “Seeed nrf52 Boards” (not the “mbed” version).
  • Install Adafruit “BLE52_Mouse_and_Keyboard” library (Link)

The attached code “BossDetector2.ino” should be self-explaining. At least for me the Bluetooth device name was "Bluefruit52" and I think it's hardcoded somewhere in the library. After connecting the XIAO with a PC or a phone, it behaves like a Bluetooth keyboard. It takes a moment to connect and afterwards the button pressing triggers “Alt-Tab” key combination. It works exactly as it should. However, as explained in the introduction, I was aiming for a slightly different configuration.

Downloads

2 Device Sensor

Boss Detector 3

After contacting the technical support I was informed that I need another board library and then suddenly I was able to use the BLE examples, however not all the libraries were compatible with the "new board". I find it really annoying that Seeed has two different Board versions for the same board and the libraries are not compatible. Now I was able to control the LED on one of the XIAO by pressing a button on the other one.

Next I wanted to get the keyboard running. Since the previous libraries were not working I tried the examples that were with the given boards. The example in Arduino IDE was not very helpful and after short googling I found one that was sufficient: Example (and here the available keys). And again a problem - the given example library doesn't have a “Tab”- Key. 

That was enough for me and I decided to close this project.

Some important things to notice:

  • Under Boards Manager you should install “Seeed nrf52 mbed-enabled Boards”
  • The libraries used with the previous two stages don't work with this Board version.
  • The attached code “BossDetector3_PC.ino” is for connecting with a PC over an USB cable, since there is no keyboard pressing you don't really need the PC connection and you can just observe the LED behavior.
  • The attached code “BossDetector3_Sensor.ino” is for the senor

Conclusion

Seeed has wonderful products, however the software support is lacking. I was able to show that the advertised XIAO BLE functions work if you find the suitable library. I’m not a software programmer and I need simple libraries. That is lacking at the moment with XIAO BLE boards, especially compared to the competitors. Maybe it will change in the near future.

Although the programming was like riding a rollercoaster I learned a lot about BLE and probably would use this communication method for some other future project. Let's see what comes up next.

Anyway, the proof of concept of the Boss Detector is done. Now I need an IMU or a new board with working IMU on it. 

The simplest would be using the bluetooth keyboard version , however some thinking would be needed to prevent multiple triggers in a short time. A quick work around would be a long delay. At least in the moment I will leave the project for a moment and maybe I will get inspired by some good ideas.

Hopefully my examples inspire somebody to use the XIAO boards for some BLE communication.