|
6 | 6 | https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
|
7 | 7 |
|
8 | 8 | This example shows how to use Inkplate as a peripheral device over Bluetooth.
|
9 |
| - Note: for this to work you need to use ESP32 Wroover Board definition, as ours currently has a bug :( |
| 9 | + More about peripheral mode: https://inkplate.readthedocs.io/en/latest/peripheral-mode.html |
| 10 | +
|
| 11 | + Upload this example to the Inkplate and connect your phone to it via Bluetooth. |
| 12 | + First, you have to pair the Inkplate with your phone in Bluetooth settings in your phone, then go to the |
| 13 | + Serial Bluetooth Terminal app and you can find the Inkplate in the device list. You can use another similar app. |
| 14 | + If Bluetooth starts successfully, you can send commands from your phone. Don't forget you need to send #L(1)* after |
| 15 | + each command to show it on the display (equal to display->display()). |
10 | 16 |
|
11 | 17 | Want to learn more about Inkplate? Visit www.inkplate.io
|
12 | 18 | Looking to get support? Write on our forums: https://forum.soldered.com/
|
13 |
| - 15 July 2020 by Soldered |
| 19 | + 28 March 2023 by Soldered |
14 | 20 | */
|
15 | 21 |
|
16 | 22 | // Next 3 lines are a precaution, you can ignore those, and the example would also work without them
|
17 | 23 | #if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
|
18 |
| -#error "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu." |
| 24 | +#error \ |
| 25 | + "Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu." |
19 | 26 | #endif
|
20 | 27 |
|
21 |
| -#include "Inkplate.h" |
22 |
| - |
| 28 | +// Include Inkplate and BluetoothSerial library to the sketch |
23 | 29 | #include "BluetoothSerial.h"
|
| 30 | +#include "Inkplate.h" |
24 | 31 |
|
25 |
| -#define BUFFER_SIZE 1000 |
26 |
| - |
| 32 | +// Include peripheral functions |
27 | 33 | #include "Peripheral.h"
|
28 | 34 |
|
29 |
| -// Declare Inkplate and SerialBluetooth objects |
| 35 | +// Create an object on Inkplate library and also set library into 1-bit mode (BW) |
30 | 36 | Inkplate display(INKPLATE_1BIT);
|
| 37 | + |
| 38 | +// Create SerialBT object for Bluetooth communication |
31 | 39 | BluetoothSerial SerialBT;
|
32 | 40 |
|
| 41 | +// Size of buffer for receiving commands |
| 42 | +#define BUFFER_SIZE 1000 |
| 43 | + |
33 | 44 | // Temporary buffer to send to Peripheral mode code
|
34 | 45 | char commandBuffer[BUFFER_SIZE + 1];
|
35 | 46 |
|
36 | 47 | void setup() // Initialize everything
|
37 | 48 | {
|
| 49 | + // Init serial communication |
38 | 50 | Serial.begin(115200);
|
39 | 51 |
|
40 |
| - if (!SerialBT.begin("ESP32")) |
| 52 | + // Init Inkplate library (you should call this function ONLY ONCE) |
| 53 | + display.begin(); |
| 54 | + |
| 55 | + // Init BT communication |
| 56 | + if (!SerialBT.begin("Inkplate10")) |
41 | 57 | {
|
42 | 58 | Serial.println("An error occurred initializing Bluetooth");
|
43 | 59 | }
|
44 |
| - |
45 |
| - display.begin(); |
| 60 | + else |
| 61 | + { |
| 62 | + Serial.println("The device started, now you can pair it with Bluetooth and send commands!"); |
| 63 | + } |
46 | 64 | }
|
47 | 65 |
|
48 | 66 | void loop()
|
49 | 67 | {
|
50 |
| - while (SerialBT.available()) // When Bluetooth available save it and pass to Peripheral.h code |
| 68 | + // When Bluetooth available save it and pass to Peripheral.h code |
| 69 | + while (SerialBT.available()) |
51 | 70 | {
|
52 | 71 | for (int i = 0; i < (BUFFER_SIZE - 1); i++)
|
53 | 72 | {
|
54 | 73 | commandBuffer[i] = commandBuffer[i + 1];
|
55 | 74 | }
|
56 | 75 | commandBuffer[BUFFER_SIZE - 1] = SerialBT.read();
|
57 |
| - Serial.print(commandBuffer[BUFFER_SIZE - 1]); |
58 | 76 | }
|
59 | 77 |
|
60 | 78 | // Function in peripheral.h
|
61 |
| - run(commandBuffer, BUFFER_SIZE); |
| 79 | + run(commandBuffer, BUFFER_SIZE, &display, &SerialBT); |
62 | 80 |
|
| 81 | + // Wait a bit |
63 | 82 | delay(50);
|
64 | 83 | }
|
0 commit comments