|
| 1 | +/* |
| 2 | + Inkplate4_Bluetooth_Peripheral_Mode example for Soldered Inkplate 4 |
| 3 | + For this example you will need a USB-C cable, Inkplate 4 and smartphone. |
| 4 | + Select "Soldered Inkplate4" from Tools -> Board menu. |
| 5 | + Don't have "Soldered Inkplate4" option? Follow our tutorial and add it: |
| 6 | + https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/ |
| 7 | +
|
| 8 | + This example shows how to use Inkplate as a peripheral device over Bluetooth. |
| 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()). |
| 16 | +
|
| 17 | + Want to learn more about Inkplate? Visit www.inkplate.io |
| 18 | + Looking to get support? Write on our forums: https://forum.soldered.com/ |
| 19 | + 5 April 2023 by Soldered |
| 20 | +*/ |
| 21 | + |
| 22 | +// Next 3 lines are a precaution, you can ignore those, and the example would also work without them |
| 23 | +#ifndef ARDUINO_INKPLATE4 |
| 24 | +#error "Wrong board selection for this example, please select Soldered Inkplate4 in the boards menu." |
| 25 | +#endif |
| 26 | + |
| 27 | +// Include Inkplate and BluetoothSerial library to the sketch |
| 28 | +#include "BluetoothSerial.h" |
| 29 | +#include "Inkplate.h" |
| 30 | + |
| 31 | +// Include peripheral functions |
| 32 | +#include "Peripheral.h" |
| 33 | + |
| 34 | +// Create an object on Inkplate library |
| 35 | +Inkplate display; |
| 36 | + |
| 37 | +// Create SerialBT object for Bluetooth communication |
| 38 | +BluetoothSerial SerialBT; |
| 39 | + |
| 40 | +// Size of buffer for receiving commands |
| 41 | +#define BUFFER_SIZE 1000 |
| 42 | + |
| 43 | +// Temporary buffer to send to Peripheral mode code |
| 44 | +char commandBuffer[BUFFER_SIZE + 1]; |
| 45 | + |
| 46 | +void setup() |
| 47 | +{ |
| 48 | + // Init serial communication |
| 49 | + Serial.begin(115200); |
| 50 | + |
| 51 | + // Init Inkplate library (you should call this function ONLY ONCE) |
| 52 | + display.begin(); |
| 53 | + |
| 54 | + // Init BT communication |
| 55 | + if (!SerialBT.begin("Inkplate4")) |
| 56 | + { |
| 57 | + Serial.println("An error occurred initializing Bluetooth"); |
| 58 | + } |
| 59 | + else |
| 60 | + { |
| 61 | + Serial.println("The device started, now you can pair it with Bluetooth and send commands!"); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +void loop() |
| 66 | +{ |
| 67 | + // When Bluetooth available save it and pass to Peripheral.h code |
| 68 | + while (SerialBT.available()) |
| 69 | + { |
| 70 | + for (int i = 0; i < (BUFFER_SIZE - 1); i++) |
| 71 | + { |
| 72 | + commandBuffer[i] = commandBuffer[i + 1]; |
| 73 | + } |
| 74 | + commandBuffer[BUFFER_SIZE - 1] = SerialBT.read(); |
| 75 | + } |
| 76 | + |
| 77 | + // Function in peripheral.h |
| 78 | + run(commandBuffer, BUFFER_SIZE, &display, &SerialBT); |
| 79 | + |
| 80 | + // Wait a bit |
| 81 | + delay(50); |
| 82 | +} |
0 commit comments