55 @file MKRZeroSend.ino
66
77 @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.
1010
1111 This example will start sending a random chirp payload on start up.
1212
1818 *Note*: This board is send-only, so cannot be configured to receive
1919 data due to the minimal memory available on the board
2020
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+
2124 Circuit:
2225 - Arduino MKRZero
2326 - Adafruit UDA1334
3841#include " chirp_connect.h"
3942#include " credentials.h"
4043
41- #define VOLUME 12000
44+ #define VOLUME 0.5 // Between 0 and 1
4245
4346#define NUM_BUFFERS 2
44- #define BUFFER_SIZE 256
47+ #define BUFFER_SIZE 1024
4548#define SAMPLE_RATE 44100
4649
47- // Global variables -------------------------------------------
50+ // Global variables ------------------------------------------------------------
4851
4952int buffer[NUM_BUFFERS][BUFFER_SIZE];
5053short tmpBuffer[BUFFER_SIZE / 2 ];
@@ -57,14 +60,15 @@ DmacDescriptor *desc;
5760static chirp_connect_t *chirp = NULL ;
5861static volatile bool dma_complete = true ;
5962
60- // Function definitions ---------------------------------------
63+ // Function definitions --------------------------------------------------------
6164
6265void dmaCallback (Adafruit_ZeroDMA *dma);
6366void dmaErrorCallback (Adafruit_ZeroDMA *dma);
6467void setupDMA (void );
6568void setupChirp (void );
69+ void sendChirp (void );
6670
67- // Function declarations --------------------------------------
71+ // Function declarations -------------------------------------------------------
6872
6973void setup ()
7074{
@@ -80,16 +84,7 @@ void setup()
8084 i2s.enableMCLK ();
8185 i2s.enableTx ();
8286
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 ();
9388
9489 ZeroDMAstatus stat = dma.startJob ();
9590 if (stat != DMA_STATUS_OK)
@@ -110,7 +105,7 @@ void loop()
110105
111106 // Copy the data into a stereo buffer for audio output
112107 for (int i = 0 ; i < BUFFER_SIZE / 2 ; i++) {
113- int value = tmpBuffer[i] * VOLUME ;
108+ int value = tmpBuffer[i] * INT16_MAX ;
114109 buffer[next][i * 2 ] = value;
115110 buffer[next][i * 2 + 1 ] = value;
116111 }
@@ -119,7 +114,7 @@ void loop()
119114 }
120115}
121116
122- // Chirp -----------------------------------------------------
117+ // Chirp -----------------------------------------------------------------------
123118
124119void chirpErrorHandler (chirp_connect_error_code_t code)
125120{
@@ -141,7 +136,19 @@ void onSentCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channe
141136 Serial.println (" Sent data..." );
142137}
143138
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 ()
145152{
146153 chirp = new_chirp_connect (CHIRP_APP_KEY, CHIRP_APP_SECRET);
147154 if (chirp == NULL )
@@ -167,14 +174,17 @@ void setupChirp(void)
167174 err = chirp_connect_set_output_sample_rate (chirp, SAMPLE_RATE);
168175 chirpErrorHandler (err);
169176
177+ err = chirp_connect_set_volume (chirp, VOLUME);
178+ chirpErrorHandler (err);
179+
170180 err = chirp_connect_start (chirp);
171181 chirpErrorHandler (err);
172182
173183 Serial.println (" Chirp SDK initialised." );
174184 Serial.flush ();
175185}
176186
177- // I2S DMA ---------------------------------------------------
187+ // I2S DMA ---------------------------------------------------------------------
178188
179189void dmaCallback (Adafruit_ZeroDMA *dma)
180190{
0 commit comments