You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/02.hero/boards/uno-r4-wifi/tutorials/cheat-sheet/cheat-sheet.md
+166Lines changed: 166 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -622,6 +622,172 @@ To learn more about the Wi-Fi® capabilities of the UNO R4 WiFi, try out the [Ne
622
622
623
623
Thanks to the ESP32 module, the UNO R4 WiFi has Bluetooth® LE and Bluetooth® 5 capabilities, at a speed of up to 2 Mbps. The ESP32 module has a built in trace-antenna, meaning that you do not need an external one to use the connectivity features of the board. However, this trace antenna is shared with the Bluetooth® module, which means that you cannot use Bluetooth® and Wi-Fi® at the same time.
624
624
625
+
Below is an example sketch scans for bluetooth devices:
626
+
627
+
```arduino
628
+
#include <ArduinoBLE.h>
629
+
630
+
void setup() {
631
+
Serial.begin(9600);
632
+
while (!Serial);
633
+
634
+
// begin initialization
635
+
if (!BLE.begin()) {
636
+
Serial.println("starting Bluetooth® Low Energy module failed!");
637
+
638
+
while (1);
639
+
}
640
+
641
+
Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer");
642
+
643
+
// start scanning for peripherals
644
+
BLE.scan();
645
+
}
646
+
647
+
void loop() {
648
+
// check if a peripheral has been discovered
649
+
BLEDevice peripheral = BLE.available();
650
+
651
+
if (peripheral) {
652
+
// discovered a peripheral, print out address, local name, and advertised service
653
+
Serial.print("Found ");
654
+
Serial.print(peripheral.address());
655
+
Serial.print(" '");
656
+
Serial.print(peripheral.localName());
657
+
Serial.print("' ");
658
+
Serial.print(peripheral.advertisedServiceUuid());
659
+
Serial.println();
660
+
661
+
// check for peripheral's name
662
+
if (peripheral.localName() == "<PERIPHERAL_NAME>") {
663
+
// stop scanning
664
+
BLE.stopScan();
665
+
666
+
explorerPeripheral(peripheral);
667
+
668
+
// peripheral disconnected, we are done
669
+
while (1) {
670
+
// do nothing
671
+
}
672
+
}
673
+
}
674
+
}
675
+
676
+
void explorerPeripheral(BLEDevice peripheral) {
677
+
// connect to the peripheral
678
+
Serial.println("Connecting ...");
679
+
680
+
if (peripheral.connect()) {
681
+
Serial.println("Connected");
682
+
} else {
683
+
Serial.println("Failed to connect!");
684
+
return;
685
+
}
686
+
687
+
// discover peripheral attributes
688
+
Serial.println("Discovering attributes ...");
689
+
if (peripheral.discoverAttributes()) {
690
+
Serial.println("Attributes discovered");
691
+
} else {
692
+
Serial.println("Attribute discovery failed!");
693
+
peripheral.disconnect();
694
+
return;
695
+
}
696
+
697
+
// read and print device name of peripheral
698
+
Serial.println();
699
+
Serial.print("Device name: ");
700
+
Serial.println(peripheral.deviceName());
701
+
Serial.print("Appearance: 0x");
702
+
Serial.println(peripheral.appearance(), HEX);
703
+
Serial.println();
704
+
705
+
// loop the services of the peripheral and explore each
706
+
for (int i = 0; i < peripheral.serviceCount(); i++) {
707
+
BLEService service = peripheral.service(i);
708
+
709
+
exploreService(service);
710
+
}
711
+
712
+
Serial.println();
713
+
714
+
// we are done exploring, disconnect
715
+
Serial.println("Disconnecting ...");
716
+
peripheral.disconnect();
717
+
Serial.println("Disconnected");
718
+
}
719
+
720
+
void exploreService(BLEService service) {
721
+
// print the UUID of the service
722
+
Serial.print("Service ");
723
+
Serial.println(service.uuid());
724
+
725
+
// loop the characteristics of the service and explore each
726
+
for (int i = 0; i < service.characteristicCount(); i++) {
void printData(const unsigned char data[], int length) {
777
+
for (int i = 0; i < length; i++) {
778
+
unsigned char b = data[i];
779
+
780
+
if (b < 16) {
781
+
Serial.print("0");
782
+
}
783
+
784
+
Serial.print(b, HEX);
785
+
}
786
+
}
787
+
```
788
+
789
+
If you want to learn more about Bluetooth LE check out our article [here](/learn/communication/bluetooth).
790
+
625
791
### Programming the ESP32 (Advanced)
626
792
627
793
The ESP32 module and the Renesas RA4M1-chip are part of a sophisticated USB-Serial system that is highly flexible and adaptive to allow for HID features while still keeping the ability to program both the main MCU, and the ESP32, if you so wish. By default, the ESP32's is used mainly as a radio module using Wi-Fi® and Bluetooth®.
0 commit comments