|
1 | 1 | # Chirp for Arduino |
2 | 2 |
|
3 | | -*Version 3.4.0, September 2019* |
| 3 | +Chirp for Arduino makes it quick and easy to integrate Chirp connectivity into your Arduino sketches. |
4 | 4 |
|
5 | | -## Overview |
6 | | - |
7 | | -Chirp is a library enabling Arduino-based devices to send and receive data using sound. You'll need: |
8 | | - |
9 | | - * A compatible Arduino board |
10 | | - * A digital I2S MEMS microphone (if your board does not contain a microphone) |
11 | | - * A digital I2S amplifier and compatible speaker |
12 | | - |
13 | | -For receiving data, you will need a digital MEMS microphone. Some boards (for example, the Nano 33 Sense and Microsoft MXChip) already include a MEMS mic so you are good to go. For others, you will need an external mic such as the [SPH0645](https://www.adafruit.com/product/3421) or [ICS-43434](https://www.mouser.co.uk/ProductDetail/TDK-InvenSense/ICS-43434?qs=u4fy%2FsgLU9PAgmWRI7%252BqXA%3D%3D). |
14 | | - |
15 | | -For sending data, we recommend using a digital I2S audio output such as the [UDA1334A](https://www.adafruit.com/product/3678) or [MAX98357A](https://www.adafruit.com/product/3006), connected to a compatible speaker. |
16 | | - |
17 | | -You can quickly test that your device is receiving chirps by playing some random test signals from the [Developer Hub](https://developers.chirp.io). |
18 | | - |
19 | | -To test whether your device is sending chirps OK, we recommend setting up the [Python command-line tools](https://developers.chirp.io/docs/tutorials/command-line) to receive data from the Arduino. |
20 | | - |
21 | | -## Supported hardware |
22 | | - |
23 | | -The following Arduino-compatible boards are able to both send and receive chirps: |
24 | | - |
25 | | - * Arduino Nano 33 Sense |
26 | | - * Microsoft MXChip |
27 | | - * ESP32 |
28 | | - |
29 | | -The following Arduino-compatible boards are only able to send chirps, as they are not able to do on-chip DSP: |
30 | | - |
31 | | - * Arduino MKRZero |
32 | | - * Arduino Vidor 4000 |
33 | | - * Genuino Zero |
34 | | - * MKR Fox 1200 |
35 | | - * MKR1000 WiFi |
36 | | - |
37 | | -## Installation |
38 | | - |
39 | | -Chirp is written for the Arduino IDE versions 1.8.6 and above. |
40 | | - |
41 | | -Install ChirpSDK as a library using "Manage Libraries". For instructions, see |
42 | | - |
43 | | -[http://arduino.cc/en/Guide/Libraries](http://arduino.cc/en/Guide/Libraries) |
44 | | - |
45 | | -Once installed, you can access the example programs from the menu: |
46 | | - |
47 | | -``` |
48 | | -File > Examples > ChirpSDK > Example |
49 | | -``` |
50 | | - |
51 | | -and you can include the headers to use Chirp in your own code by adding: |
52 | | - |
53 | | -``` |
54 | | -#include "chirp_sdk.h" |
55 | | -``` |
56 | | - |
57 | | -## Usage |
58 | | - |
59 | | -To set up the Chirp SDK, initialise and configure with your app key, |
60 | | -secret and config from the [Developer Hub](https://developers.chirp.io). |
61 | | - |
62 | | -*Note* You must select the `16khz-mono-embedded` protocol from the dropdown menu, when |
63 | | -selecting your chirp configuration. |
64 | | - |
65 | | - chirp = new_chirp_sdk(APP_KEY, APP_SECRET); |
66 | | - if (chirp == NULL) { |
67 | | - Serial.println("Chirp initialisation failed."); |
68 | | - return; |
69 | | - } |
70 | | - |
71 | | -Then set any required callbacks and start the SDK running. |
72 | | - |
73 | | - chirp_sdk_error_code_t err = chirp_sdk_set_config(chirp, APP_CONFIG); |
74 | | - if (err != CHIRP_SDK_OK) |
75 | | - return; |
76 | | - |
77 | | - chirp_sdk_callback_set_t callbacks = {0}; |
78 | | - callbacks.on_received = onReceivedCallback; |
79 | | - err = chirp_sdk_set_callbacks(chirp, callbacks); |
80 | | - if (err != CHIRP_SDK_OK) |
81 | | - return; |
82 | | - |
83 | | - err = chirp_sdk_set_callback_ptr(chirp, chirp); |
84 | | - if (err != CHIRP_SDK_OK) |
85 | | - return; |
86 | | - |
87 | | - err = chirp_sdk_set_input_sample_rate(chirp, input_sample_rate); |
88 | | - if (err != CHIRP_SDK_OK) |
89 | | - return; |
90 | | - err = chirp_sdk_set_output_sample_rate(chirp, output_sample_rate); |
91 | | - if (err != CHIRP_SDK_OK) |
92 | | - return; |
93 | | - |
94 | | - err = chirp_sdk_start(chirp); |
95 | | - if (err != CHIRP_SDK_OK) |
96 | | - return; |
97 | | - |
98 | | -## Callbacks |
99 | | - |
100 | | -The received data is passed back to the `onReceivedCallback` function. If the payload pointer is null then there has been an error decoding the data. |
101 | | - |
102 | | - void |
103 | | - onReceivedCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channel) { |
104 | | - if (payload) { |
105 | | - char *hexString = chirp_sdk_as_string(chirp, payload, length); |
106 | | - Serial.printf("Received data = %s\n", hexString); |
107 | | - chirp_sdk_free(hexString); |
108 | | - } else { |
109 | | - Serial.println("Decode failed."); |
110 | | - } |
111 | | - } |
112 | | - |
113 | | -A complete list of callbacks is shown below. |
114 | | - |
115 | | - void onStateChangedCallback(void *ptr, chirp_sdk_state_t old_state, chirp_sdk_state_t new_state) { |
116 | | - // Put here what you want to do when the SDK's state is changing. |
117 | | - } |
118 | | - |
119 | | - void onSendingCallback(void *ptr, uint8_t *bytes, size_t length, uint8_t channel) { |
120 | | - // Put here what you want to do when the SDK starts to send some data. |
121 | | - } |
122 | | - |
123 | | - void onSentCallback(void *ptr, uint8_t *bytes, size_t length, uint8_t channel) { |
124 | | - // Put here what you want to do when the SDK has sent some data. |
125 | | - } |
126 | | - |
127 | | - void onReceivingCallback(void *ptr, uint8_t *bytes, size_t length, uint8_t channel) { |
128 | | - // Put here what you want to do when the SDK starts receiving some data. |
129 | | - } |
130 | | - |
131 | | - void onReceivedCallback(void *ptr, uint8_t *bytes, size_t length, uint8_t channel) { |
132 | | - // Put here what you want to do when the SDK has received some data. |
133 | | - } |
134 | | - |
135 | | - // If you don't set all the callbacks, make sure the unused callbacks are set to NULL. |
136 | | - chirp_sdk_callback_set_t callbacks_set = { |
137 | | - .on_state_changed = on_state_changed_callback, |
138 | | - .on_sending = on_sending_callback, |
139 | | - .on_sent = on_sent_callback, |
140 | | - .on_receiving = on_receiving_callback, |
141 | | - .on_received = on_received_callback |
142 | | - }; |
143 | | - err = chirp_sdk_set_callbacks(chirp, callbacks_set); |
144 | | - if (err != CHIRP_SDK_OK) |
145 | | - { |
146 | | - const char *error_string = chirp_sdk_error_code_to_string(err); |
147 | | - printf("%s\n", error_string); |
148 | | - } |
149 | | - |
150 | | - |
151 | | -## Payloads |
152 | | - |
153 | | -A Chirp payload is simply an array of bytes. You can send a random data payload to the speakers like so. |
154 | | - |
155 | | - size_t payload_length = chirp_sdk_get_max_payload_length(chirp); |
156 | | - uint8_t *payload = chirp_sdk_random_payload(chirp, &payload_length); |
157 | | - |
158 | | - err = chirp_sdk_send(chirp, payload, payload_length); |
159 | | - if (err != CHIRP_SDK_OK) { |
160 | | - const char *error_string = chirp_sdk_error_code_to_string(err); |
161 | | - printf("%s\n", error_string); |
162 | | - } |
163 | | - |
164 | | -Or you can easily send an ASCII string |
165 | | - |
166 | | - char *identifier = "hello"; |
167 | | - err = chirp_sdk_send(chirp, (uint8_t *)identifier, strlen(identifier)); |
168 | | - if (err != CHIRP_SDK_OK) { |
169 | | - const char *error_string = chirp_sdk_error_code_to_string(err); |
170 | | - printf("%s\n", error_string); |
171 | | - } |
172 | | - |
173 | | -## Processing |
174 | | - |
175 | | -To process audio data from the microphone, and fill the output buffer with audio data, call the following functions with data periodically. |
176 | | - |
177 | | - err = chirp_sdk_process_input(chirp, input_buffer, input_buffer_length); |
178 | | - |
179 | | - err = chirp_sdk_process_output(chirp, output_buffer, output_buffer_length); |
| 5 | +* For step-by-step instructions, follow the [Chirp Getting Started Guide for Arduino](https://developers.chirp.io/docs/getting-started/arduino). |
| 6 | +* For an overview of Chirp technology, see our [Chirp Overview](https://developers.chirp.io/docs/). |
| 7 | +* To get in touch directly, visit [Chirp Developer Support](https://developers.chirp.io/support). |
180 | 8 |
|
181 | 9 | *** |
182 | 10 |
|
183 | | -All content copyright © Asio Ltd, 2013-2019. All rights reserved. |
| 11 | +This software is copyright © 2011-2019, Asio Ltd. All rights reserved. |
0 commit comments