Here at Chirp HQ, we were extremely excited to hear the announcement that Arduino would be releasing a new board with a whole host of new features. These features include a wide range of sensors, a powerful processor and most importantly - an on board microphone! The good people at Arduino sent us over a pre-release of the new Nano 33 Sense board, which is fully compatible with Chirp, allowing the maker community to send and receive data using sound.
Chirp adds a completely unique transport mechanism to Arduino boards, the added capabilities of data-over-sound means that hackers have more connectivity options at their fingertips. Some of the advantages of data-over-sound include:
- Device agnostic: data can be sent from mobile apps, web pages, or even with just an audio file
- One to many: any device within hearing range is able to receive data in one simple transaction
- Frictionless: doesn't need any pairing, passwords or initial setup
In this tutorial we will demonstrate how to use the Chirp SDK to send an RGB value to change the colour of the on board LED.
Chirp even works in noisy places, thanks to the years of research we’ve put into making the decoder robust to background sound. Read more about the benefits of using data-over-sound here.
If you are still sceptical, try it out yourself.
Getting started with Chirp is easier than ever...
Getting startedIf you have not done so already, you will need to sign up to Chirp at developers.chirp.io. Once you have signed up, you can get your app key, secret and audio configuration for your application.
Note: the 16khz-mono-embedded protocol should be selected from the dropdown when selecting your Chirp configuration.
Tip: you can select the ‘C’ code box below the configuration, and click ‘Copy to Clipboard’ to easily paste into the credentials.h file.Receiving data
Since the Nano 33 Sense comes packaged with an on board microphone, all you need to receive data using Chirp is the Chirp SDK which is available directly from the Library Manager.
Simply open the Library Manager, and search for Chirp SDK. Install v3.3.0 or later and you are ready to start coding.
Tools > Manage Libraries
You can open our example code to start with.
File > Examples > ChirpSDK > Nano33SenseReceive
You will need to copy and paste your credentials for the 16khz-mono-embedded protocol from developers.chirp.io into the credentials.h file.
It is also important to note here that the example code will not start until the Serial Monitor is opened, you can change this by commenting out the while(!Serial)
line.
The example code will simply print any received data to the Serial Monitor. However, we can easily change the behaviour to light the on board LEDs by editing the onReceivedCallback
function.
In your setup function, we must first set up the GPIO pins connected to the LEDs as outputs
#define R_LED_PIN 22
#define G_LED_PIN 23
#define B_LED_PIN 24
void setup()
{
pinMode(R_LED_PIN, OUTPUT);
pinMode(G_LED_PIN, OUTPUT);
pinMode(B_LED_PIN, OUTPUT);
}
To drive the LEDs we will need to pull out the RGB values from the data payload.
void onReceivedCallback(void *chirp, uint8_t *payload, size_t length,
{
if (length > 0) {
// High values mean lower brightness, so we
// subtract from UINT8_MAX
analogWrite(R_LED_PIN, UINT8_MAX - payload[0]);
analogWrite(B_LED_PIN, UINT8_MAX - payload[2]);
} else {
Serial.println(“Decode failed”);
}
}
You can now test your code by playing the audio files below, each one should change the LED colour from red to green to blue.
What’s next?The first iteration of the Chirp SDK for Arduino operates only on the audible 16khz-mono-embedded protocol. Over the coming months, we will be releasing an inaudible version that will work at near ultrasonic frequencies. With this you will be able to send data at frequencies that humans cannot hear, so for example, you could embed the chirp data in existing audio such as songs or videos to trigger actions.
We will also be following up with more tutorials on how you can utilise data-over-sound with Arduino. Let us know where you have used Chirp in your own Arduino projects by tagging us on twitter @chirp or get in contact with us at contact@chirp.io.
Comments