5
5
@file MKRZeroSend.ino
6
6
7
7
@brief Create a developer account at https://developers.chirp.io,
8
- and copy and paste your key, secret and config string for chosen
9
- protocol into the credentials.h file.
8
+ and copy and paste your key, secret and config string for the
9
+ "16khz-mono-embedded" protocol into the credentials.h file.
10
10
11
11
This example will start sending a random chirp payload on start up.
12
12
18
18
*Note*: This board is send-only, so cannot be configured to receive
19
19
data due to the minimal memory available on the board
20
20
21
+ *Important*: The example will not start until this Serial Monitor is opened.
22
+ To disable this behaviour, comment out the while(!Serial) line.
23
+
21
24
Circuit:
22
25
- Arduino MKRZero
23
26
- Adafruit UDA1334
38
41
#include " chirp_connect.h"
39
42
#include " credentials.h"
40
43
41
- #define VOLUME 12000
44
+ #define VOLUME 0.5 // Between 0 and 1
42
45
43
46
#define NUM_BUFFERS 2
44
- #define BUFFER_SIZE 256
47
+ #define BUFFER_SIZE 1024
45
48
#define SAMPLE_RATE 44100
46
49
47
- // Global variables -------------------------------------------
50
+ // Global variables ------------------------------------------------------------
48
51
49
52
int buffer[NUM_BUFFERS][BUFFER_SIZE];
50
53
short tmpBuffer[BUFFER_SIZE / 2 ];
@@ -57,14 +60,15 @@ DmacDescriptor *desc;
57
60
static chirp_connect_t *chirp = NULL ;
58
61
static volatile bool dma_complete = true ;
59
62
60
- // Function definitions ---------------------------------------
63
+ // Function definitions --------------------------------------------------------
61
64
62
65
void dmaCallback (Adafruit_ZeroDMA *dma);
63
66
void dmaErrorCallback (Adafruit_ZeroDMA *dma);
64
67
void setupDMA (void );
65
68
void setupChirp (void );
69
+ void sendChirp (void );
66
70
67
- // Function declarations --------------------------------------
71
+ // Function declarations -------------------------------------------------------
68
72
69
73
void setup ()
70
74
{
@@ -80,16 +84,7 @@ void setup()
80
84
i2s.enableMCLK ();
81
85
i2s.enableTx ();
82
86
83
- size_t payload_len = 5 ;
84
- uint8_t *payload = chirp_connect_random_payload (chirp, &payload_len);
85
-
86
- char *hex = chirp_connect_as_string (chirp, payload, payload_len);
87
- Serial.print (" Generated payload: " );
88
- Serial.println (hex);
89
- chirp_connect_free (hex);
90
-
91
- chirp_connect_error_code_t err = chirp_connect_send (chirp, payload, payload_len);
92
- chirpErrorHandler (err);
87
+ sendChirp ();
93
88
94
89
ZeroDMAstatus stat = dma.startJob ();
95
90
if (stat != DMA_STATUS_OK)
@@ -110,7 +105,7 @@ void loop()
110
105
111
106
// Copy the data into a stereo buffer for audio output
112
107
for (int i = 0 ; i < BUFFER_SIZE / 2 ; i++) {
113
- int value = tmpBuffer[i] * VOLUME ;
108
+ int value = tmpBuffer[i] * INT16_MAX ;
114
109
buffer[next][i * 2 ] = value;
115
110
buffer[next][i * 2 + 1 ] = value;
116
111
}
@@ -119,7 +114,7 @@ void loop()
119
114
}
120
115
}
121
116
122
- // Chirp -----------------------------------------------------
117
+ // Chirp -----------------------------------------------------------------------
123
118
124
119
void chirpErrorHandler (chirp_connect_error_code_t code)
125
120
{
@@ -141,7 +136,19 @@ void onSentCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channe
141
136
Serial.println (" Sent data..." );
142
137
}
143
138
144
- void setupChirp (void )
139
+ void sendChirp ()
140
+ {
141
+ chirp_connect_error_code_t err;
142
+
143
+ char *payload = " hello" ;
144
+ err = chirp_connect_send (chirp, (uint8_t *)payload, strlen (payload));
145
+ chirpErrorHandler (err);
146
+
147
+ Serial.print (" Sending data: " );
148
+ Serial.println (payload);
149
+ }
150
+
151
+ void setupChirp ()
145
152
{
146
153
chirp = new_chirp_connect (CHIRP_APP_KEY, CHIRP_APP_SECRET);
147
154
if (chirp == NULL )
@@ -167,14 +174,17 @@ void setupChirp(void)
167
174
err = chirp_connect_set_output_sample_rate (chirp, SAMPLE_RATE);
168
175
chirpErrorHandler (err);
169
176
177
+ err = chirp_connect_set_volume (chirp, VOLUME);
178
+ chirpErrorHandler (err);
179
+
170
180
err = chirp_connect_start (chirp);
171
181
chirpErrorHandler (err);
172
182
173
183
Serial.println (" Chirp SDK initialised." );
174
184
Serial.flush ();
175
185
}
176
186
177
- // I2S DMA ---------------------------------------------------
187
+ // I2S DMA ---------------------------------------------------------------------
178
188
179
189
void dmaCallback (Adafruit_ZeroDMA *dma)
180
190
{
0 commit comments