Skip to content

Commit 8f043cb

Browse files
author
Damien Laidin
authored
Merge pull request #11 from chirp/feature/send-messages-not-random
Send ascii messages instead of random chirps
2 parents 6ae4f0e + 6612286 commit 8f043cb

File tree

9 files changed

+81
-60
lines changed

9 files changed

+81
-60
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Recent changes to the [Chirp Arduino SDK](https://developers.chirp.io/docs).
44

5-
## v3.3.0 (beta)
6-
- Added send-only support for cortex-m0plus (MKRZero, MKR Vidor 4000)
5+
## v3.3.0 (09/08/2019)
76
- Added support for cortex-m4 (Nano 33 Sense)
7+
- Added send-only support for cortex-m0plus (MKRZero, MKR Vidor 4000)
88
- Build v3.3.0-rc1
99

10-
## v3.2.0 (14/03/2019)
10+
## v3.2.0 (14/03/2019)
1111

1212
- Build v3.2.9
1313
- Optimised DSP for ESP32

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ and you can include the headers to use Chirp in your own code by adding :
5353
To set up the Chirp SDK, initialise and configure with your app key,
5454
secret and config from the [Developer Hub](https://developers.chirp.io).
5555

56-
*Note* You must select the `arduino` protocol from the dropdown menu, when
56+
*Note* You must select the `16khz-mono-embedded` protocol from the dropdown menu, when
5757
selecting your chirp configuration.
5858

5959
chirp = new_chirp_connect(APP_KEY, APP_SECRET);

examples/ESP32Receive/ESP32Receive.ino

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
@file ESP32Receive.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 the "16khz-mono"
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 listening for chirps and print to the terminal
1212
when anything is received.
@@ -43,11 +43,13 @@
4343
#define CONVERT_INPUT(sample) (((int32_t)(sample) >> 14) + MIC_CALIBRATION)
4444

4545
// Global variables ------------------------------------------------------------
46+
4647
static chirp_connect_t *chirp = NULL;
4748
static chirp_connect_state_t currentState = CHIRP_CONNECT_STATE_NOT_CREATED;
4849
static bool startTasks = false;
4950

5051
// Function definitions --------------------------------------------------------
52+
5153
void setupChirp();
5254
void chirpErrorHandler(chirp_connect_error_code_t code);
5355
void setupAudioInput(int sample_rate);
@@ -137,10 +139,11 @@ void
137139
onReceivedCallback(void *chirp, uint8_t *payload, size_t length, uint8_t channel)
138140
{
139141
if (payload) {
140-
char *data = chirp_connect_as_string((chirp_connect_t *)chirp, payload, length);
141-
Serial.printf("data = %s\n", data);
142-
digitalWrite(LED_PIN, LOW);
143-
chirp_connect_free(data);
142+
char *data = (char *)calloc(length + 1, sizeof(uint8_t));
143+
memcpy(data, payload, length * sizeof(uint8_t));
144+
Serial.print("Received data: ");
145+
Serial.println(data);
146+
free(data);
144147
} else {
145148
Serial.println("Decode failed.");
146149
}

examples/ESP32Send/ESP32Send.ino

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
@file ESP32Send.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 the "arduino"
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
When the EN switch is pressed on the board, a random chirp will be sent to
1212
the audio output.
@@ -30,16 +30,19 @@
3030
#define LED_PIN 2 // LED
3131
#define SWITCH_PIN 0 // Switch
3232

33+
#define VOLUME 0.5 // Between 0 and 1
3334
#define BUFFER_SIZE 512
3435
#define SAMPLE_RATE 16000
3536

3637
// Global variables ------------------------------------------------------------
38+
3739
static chirp_connect_t *chirp = NULL;
3840
static chirp_connect_state_t currentState = CHIRP_CONNECT_STATE_NOT_CREATED;
3941
static volatile bool buttonPressed = false;
4042
static bool startTasks = false;
4143

4244
// Function definitions --------------------------------------------------------
45+
4346
void IRAM_ATTR handleInterrupt();
4447
void setupChirp();
4548
void chirpErrorHandler(chirp_connect_error_code_t code);
@@ -73,12 +76,12 @@ loop()
7376
}
7477

7578
if (buttonPressed) {
76-
size_t payloadLength = 0;
77-
uint8_t *payload = chirp_connect_random_payload(chirp, &payloadLength);
78-
chirp_connect_send(chirp, payload, payloadLength);
79-
Serial.println("Sending data...");
79+
char *payload = "hello";
80+
chirpError = chirp_connect_send(chirp, (uint8_t *)payload, strlen(payload));
81+
chirpErrorHandler(chirpError);
82+
Serial.print("Sending data: ");
83+
Serial.println(payload);
8084
buttonPressed = false;
81-
chirp_connect_free(payload);
8285
}
8386
}
8487

@@ -176,8 +179,8 @@ setupChirp()
176179
err = chirp_connect_start(chirp);
177180
chirpErrorHandler(err);
178181

179-
// Set volume to 0.5 to not distort output
180-
chirp_connect_set_volume(chirp, 0.5);
182+
err = chirp_connect_set_volume(chirp, VOLUME);
183+
chirpErrorHandler(err);
181184

182185
Serial.println("Chirp SDK initialised.");
183186
}

examples/MKRZeroSend/MKRZeroSend.ino

+31-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
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
@@ -18,6 +18,9 @@
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
@@ -38,13 +41,13 @@
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

4952
int buffer[NUM_BUFFERS][BUFFER_SIZE];
5053
short tmpBuffer[BUFFER_SIZE / 2];
@@ -57,14 +60,15 @@ DmacDescriptor *desc;
5760
static chirp_connect_t *chirp = NULL;
5861
static volatile bool dma_complete = true;
5962

60-
// Function definitions ---------------------------------------
63+
// Function definitions --------------------------------------------------------
6164

6265
void dmaCallback(Adafruit_ZeroDMA *dma);
6366
void dmaErrorCallback(Adafruit_ZeroDMA *dma);
6467
void setupDMA(void);
6568
void setupChirp(void);
69+
void sendChirp(void);
6670

67-
// Function declarations --------------------------------------
71+
// Function declarations -------------------------------------------------------
6872

6973
void 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

124119
void 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

179189
void dmaCallback(Adafruit_ZeroDMA *dma)
180190
{

examples/MXChipSendReceive/MXChipSendReceive.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @file MXChipSendReceive.ino
66
*
77
* @brief After creating a developer account on https://developers.chirp.io, get
8-
* your key, secret and config string from your account using the "16kHz-mono"
8+
* your key, secret and config string from your account using the "16kHz-mono-embedded"
99
* protocol, and set them in this file (in CHIRP_APP_KEY, CHIRP_APP_SECRET, CHIRP_APP_CONFIG).
1010
*
1111
* This example will start in listening mode. The listening and playing modes

examples/Nano33SenseReceive/Nano33SenseReceive.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
@file Nano33SenseReceive.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 the "arduino"
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 listening for chirps and print to the terminal
1212
when anything is received.
1313
14-
Note: this example can be used in conjunction with the send example,
14+
*Note*: this example can be used in conjunction with the send example,
1515
to send and receive data in the same application.
1616
17+
*Important*: The example will not start until this Serial Monitor is opened.
18+
To disable this behaviour, comment out the while(!Serial) line.
19+
1720
Circuit:
1821
- Arduino Nano 33 BLE board
1922

examples/Nano33SenseSend/Nano33SenseSend.ino

+17-15
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
@file Nano33SenseSend.ino
77
88
@brief Create a developer account at https://developers.chirp.io,
9-
and copy and paste your key, secret and config string for the "arduino"
10-
protocol into the credentials.h file.
9+
and copy and paste your key, secret and config string for the
10+
"16khz-mono-embedded" protocol into the credentials.h file.
1111
1212
This example will start listening for chirps and print to the terminal
1313
when anything is received.
1414
15+
*Important*: The example will not start until this Serial Monitor is opened.
16+
To disable this behaviour, comment out the while(!Serial) line.
17+
1518
Circuit:
1619
- Arduino Nano 33 BLE board
1720
- Adafruit MAX98357A amplifier
@@ -24,11 +27,12 @@
2427
#include "chirp_connect.h"
2528
#include "credentials.h"
2629

30+
#define VOLUME 0.3 // Between 0 and 1
2731
#define BUFFER_SIZE 256
2832
#define OUTPUT_SAMPLE_RATE 16667
2933

30-
#define I2S_SCK_PIN 23 // D7
31-
#define I2S_DATA_PIN 21 // D8
34+
#define I2S_DATA_PIN 23 // D7
35+
#define I2S_SCK_PIN 21 // D8
3236
#define I2S_LRCK_PIN 27 // D9
3337

3438
// Global variables ------------------------------------------------------------
@@ -42,6 +46,7 @@ short buffer_two[BUFFER_SIZE];
4246

4347
void chirpErrorHandler(chirp_connect_error_code_t code);
4448
void setupChirp(void);
49+
void sendChirp(void);
4550
void i2s_init(void);
4651
void i2s_start(void);
4752

@@ -53,7 +58,7 @@ void setup()
5358
while(!Serial); // Wait for Serial monitor before continuing
5459

5560
setupChirp();
56-
sendRandomChirp();
61+
sendChirp();
5762

5863
i2s_init();
5964
i2s_start();
@@ -123,7 +128,7 @@ void setupChirp(void)
123128
err = chirp_connect_set_output_sample_rate(chirp, OUTPUT_SAMPLE_RATE);
124129
chirpErrorHandler(err);
125130

126-
err = chirp_connect_set_volume(chirp, 0.5);
131+
err = chirp_connect_set_volume(chirp, VOLUME);
127132
chirpErrorHandler(err);
128133

129134
err = chirp_connect_start(chirp);
@@ -133,19 +138,16 @@ void setupChirp(void)
133138
Serial.flush();
134139
}
135140

136-
void sendRandomChirp()
141+
void sendChirp()
137142
{
138-
size_t payload_len = 5;
139-
uint8_t *payload = chirp_connect_random_payload(chirp, &payload_len);
140-
141-
char *hex = chirp_connect_as_string(chirp, payload, payload_len);
142-
Serial.print("Generated payload: ");
143-
Serial.println(hex);
143+
chirp_connect_error_code_t err;
144144

145-
chirp_connect_error_code_t err = chirp_connect_send(chirp, payload, payload_len);
145+
char *payload = "hello";
146+
err = chirp_connect_send(chirp, (uint8_t *)payload, strlen(payload));
146147
chirpErrorHandler(err);
147148

148-
chirp_connect_free(payload);
149+
Serial.print("Sending data: ");
150+
Serial.println(payload);
149151
}
150152

151153
// I2S Audio -------------------------------------------------------------------

keywords.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ chirp_connect_get_output_sample_rate KEYWORD2
3838
chirp_connect_set_input_sample_rate KEYWORD2
3939
chirp_connect_set_output_sample_rate KEYWORD2
4040
chirp_connect_get_auto_mute KEYWORD2
41-
chirp_connect_set_auto_mute KEYWORD2
41+
chirp_connect_set_listen_to_self KEYWORD2
4242
chirp_connect_set_callback_ptr KEYWORD2
4343
chirp_connect_set_frequency_correction KEYWORD2
4444
chirp_connect_get_version KEYWORD2

0 commit comments

Comments
 (0)