• mrjack

    Dear Pd'ers… I'm fairly new to Pd and have been using it during my 'Audio Production' degree at SAE college in London. I'm here to ask for help on my final degree project, which aims to control objects within Pd by way of proximity sensors connected to Arduino.

    I have had moderate success, first using a Sharp GPD12 IR sensor connected to an analog port on an Arduino Diecimila, then a Devantech SRF02 connected via I2C to Arduino. I have managed to get Pure Data reading the sensor values using the Pure Data example included in SimpleMessageSystem (http://www.arduino.cc/playground/uploads/Code/SimpleMessageSystem.zip)... and only altering the number of the comport the Arduino appears on.

    On the Arduino end, I have added the SimpleMessageSystem library, and am using the following sketch to run one or both of the sensors depending on whether or not I omit the SRF02 or GPD12 parts of the code.

    // top //

    #include <Wire.h>
    #include <Servo.h>
    #include <SimpleMessageSystem.h>

    int sensorPin = 0;
    int sensorValue = 0;

    Servo servo1;

    #define sensorAddress 0x70
    #define readInches 0x50
    #define readCentimeters 0x51
    #define readMicroseconds 0x52
    #define resultRegister 0x02

    void setup()
    {
    Wire.begin();
    Serial.begin(9600);
    }

    void sendCommand (int address, int command) {
    Wire.beginTransmission(address);
    Wire.send(0x00);
    Wire.send(command);
    Wire.endTransmission();
    }

    void setRegister(int address, int thisRegister) {
    Wire.beginTransmission(address);
    Wire.send(thisRegister);
    Wire.endTransmission();
    }
    int readData(int address, int numBytes) {

    int result = 0;

    Wire.requestFrom(address, numBytes);
    while (Wire.available() < 2 );{
    }

    result = Wire.receive() * 256;
    result = result + Wire.receive();
    return result;
    }

    void loop()
    {
    // SRF02 READING //
    sendCommand(sensorAddress, readInches);
    delay(70);
    setRegister(sensorAddress, resultRegister);
    int sensorReading = readData(sensorAddress, 2);
    Serial.println(sensorReading);

    delay (200);

    // GPD12 READING //
    sensorValue = analogRead(sensorPin);
    int range = (6787 / sensorValue);
    Serial.println(range);

    delay(200);
    }

    // bottom //

    Pure data is picking up the sensor's output as a decimal number, through the serial port, correctly, and showing this as a number in the SPECIAL CHARACTER section of the Pd patch, which I can then use to control various Pd parameters, like a slider for example.

    If printing both sensor readings to the serial, the Pd patch will pick up the two sensor values alternately, but there seems no way of differentiating the two sensors within Pd, as they both come through the serial. I have tried prepending the serial print at the Arduino stage with a tag such as "IR" or "UL" for each sensor, but this simply ends up in nothing coming through in Pd.

    Using one sensor gives the ability to control parameters with a fairly narrow detection range, but for the final version I would like to incorporate 4 or 5 sensors in order that I can cover nearly a full 360 degree range.

    After a bit of research I have gone and bought 4 x Maxsonar EZ0's. They've got a wider range than the Devantech sensors, and can operate via I2C, serial or PWM. A number of people online seem to mention the improved stability when operating via PWM, so I thought this could be kinda useful.

    I am going to London Hackspace tomorrow to get help with wiring up the sensors to my Arduino Diecimila, but for now, my main problem seems to be how to achieve greater communication between Pure Data and the sensors. It's all very good and well being able to take the decimal readout from an analog input to give one set of values in Pd, but I would like to know how to either to read (and trigger) each sensor discretely via PWM, or to somehow differentiate between each sensor's analog output, so that I can have the different sensors controlling different objects within Pd.

    As well as SimpleMessageSystem, I looked at using the Pduino object. But to be honest, it is either not working properly (I have noticed reported issues with bugginess), or I am being stupid, as it has totally boggled my brain. In theory though, it seems like it should be able to do what I want, ie. send and receive commands between Arduino and Pd.

    ****************************************
    So&#8230;. my questions for anyone out there with a knowledge of using Arduino + multiple sensors (preferably Maxsonar EZ's) with Pd are:

    What is most appropriate for my project?

    • Simple Message System or Pduino?
    • analog or PWM?
      And how do I get proper communication between the two platforms so I can discern discrete values from each sensor?

    I'd really like to get a discussion going with this as (a) it would really help me in my degree (which ends in about 4 weeks!!!) and (b) I really want to share what I am doing, especially as the discussions on Arduino/Pd communication on the various forums seem a little patchy (at least for noobs like me). I also hope to continue my research in the future, sharing any findings I make with the community&#8230;
    ****************************************

    PS. In the sharing spirit, please check out the Radio Tuner patch I've just posted over on the patch section of this forum - it's my first successful attempt at Pd... I hope you enjoy :)

    posted in I/O hardware diyread more
  • mrjack

    I'm new to the forums here and to Pd in general, so I would like to share my little creation with the Pd community as, although it's pretty simple, I think it's kinda of fun and I'm kinda proud of it for being my first foray into open source programming.

    Enjoy :)

    http://www.pdpatchrepo.info/hurleur/Radio_Tuner.pd

    posted in patch~ read more
  • mrjack

    actually no, gladly I can say that was completely unintentional... although I'm not quite sure how I missed it!

    posted in I/O hardware diyread more
Internal error.

Oops! Looks like something went wrong!