Close
0%
0%

Embedded Puredata + Wireless

Streaming data wirelessly into puredata using the NRF24L01+

Similar projects worth following
Ever wanted to stream data wirelessly from an arduino to puredata? I did, so I developed an external for puredata to do just that. Data from any sensor connected to the arduino can be streamed to a raspberry pi running puredata. This data can then be used to manipulate and generate sounds.

This project was developed as part of an artist in schools residency by myself and Claire Pendrigh. Sensors made from wool and conductive thread were embedded into a blanket made by the students. Pressing the sensors triggered playback of sounds that the students recorded. See our blog (link in sidebar) for a full description of the project!

IMPORTANT: I wrote and compiled this code on a raspberry pi 1 model B. The external will have to be recompiled for the raspberry pi 2, but should work fine provided the RF24 library works.

Firstly, here's a diagram to clarify how the system is connected:



In summary, the arduino converts the analog input from one or more (up to 8) sensors, concatenates the data into a 32 byte value, and sends the value over SPI to the NRF24 module. On the receiving end, puredata polls the NRF module at regular intervals to see if any data is available. If it is, then the received data is split into eight lots of two byte values, and output from the puredata extension as eight separate outputs. Note: I only transmitted data from eight sensors. However, by modifying the source code for the external you could have up to 16 sensors & outputs.

Why concatenate the data?

Concatenating allows us to transmit data from multiple (up to sixteen) sensors as a single packet, rather than sending the value of each sensor as a separate packet. This increases our bandwidth.

What happens to lost packets?

At the moment, the receiving and transmitting code isn't configured to use auto acknowledgement or to retransmit failed packets. This means that any data that isn't received properly - e.g. from interference - is lost forever.

How quickly can the data be received?

At the moment, about 1kHz, or one 32 byte packet every millisecond. The external I wrote for puredata is limited by the puredata programming environment, because it uses the metronome function to trigger polling of the NRF24 module.

What is the range of the NRF24L01+ modules?

In my setup, I used the cheap modules shown below:

With a 1uF capacitor soldered across the supply terminals (as suggested here), and the unit enclosed in a box made from 7mm plywood, the range was a measly 3m or so. As a few people have suggested, the poor range was likely due to the metal bolts and cable in the photo above - replacing them with nylon bolts would apparently fix the problem!

Can I transmit data from puredata to the arduino?

Not with the current code. However, the RF24 library I used does allow data to be transmitted and received both ways, so by modifying the source code for the puredata external you could definitely achieve this!

  • 1 × Raspberry pi 1 model B
  • 2 × NRF24L01+ modules Available from sparkfun, banggood, eBay, etc
  • 1 × Arduino pro mini You could also use an arduino UNO, mega, or another micro controller of your choice. Just remember that the NRF24L01+ requires a 3.3V supply.
  • 1 × analog sensor of your choice we made sensors from conductive wool, however you could use a potentiometer, a light sensor, etc. for examples see the links.
  • 1 × external USB sound card compatible with rasperry pi we used a GWC Technologies AA1570 USB soundbox. For a list of compatible cards see the links.

View all 6 components

  • 1
    Step 1

    Before we get started, here's a brief summary of what we're going to do:

    • install puredata on the raspberry pi.
    • install and test the RF24 library on the raspberry pi & arduino.
    • install the puredata external.
    • transmit data to puredata using an arduino.
  • 2
    Step 2

    Getting puredata on the raspberry pi

    The easiest way that I've found is to download one of the image files from the pd-la group. Their image files have puredata and all the required dependencies pre-installed, simply follow their instructions to copy the image to an SD card and away you go. Use a 16gb card, as an 8gb SD card won't leave you with much free space.

    At this point, if you want to start puredata and have a play around, just type pd into a terminal window and hit enter.

  • 3
    Step 3

    Optional: Running the pi headless

    At the moment you probably have a screen and keyboard plugged into the pi. I'd recommend keeping it this way for the moment, rather than trying to log in over SSH or X over SSH, because the puredata external will only execute if puredata is run as root.

    If, despite what I've said, you wish to run the raspberry pi headless (i.e. without a screen), I'd suggest following the instructions from the linux laptop orchestra. You will then have to work out how to execute commands as root. These instructions worked for me, but I'm no linux expert.

View all 10 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates