How to control a p5 sketch with a tablet

edited September 2016 in Raspberry PI

Hello!

I'm working on an installation, and I'd like to have a p5 sketch running on a tablet that controls a another p5 sketch running on a monitor.

Any ideas on how to set this up would be much appreciated. Web sockets?! Not sure where to start.

Answers

  • The easiest way to do this is using OSC, that (to be short) permits you to controls devices connected over a LAN network (or to "pass" controls over different apps in localhost). In Processing you can do it with oscP5 library, that is a good library to do this, and examples are a good way to start.

    If you have generic controls, you should have a look at TouchOSC, that is an app that "transform" your Android or iOS devices into a wifi controller (it works via OSC as well), so you have the tablet part ready to use. You can find it on the store. (remember that you need oscP5 installed on Processing to "receive" datas from the tablet).

  • Thanks a ton!

  • Your answer was super helpful! Prototyping now and able to send and receive a message across devices but can't figure out how to send and receive unique messages.

    I'm not sure what the best way to do this, is it with OscPlug? OscArgument? Having trouble understanding addrPattern and how to set and then extract a specific int or string to OscMessage. All the examples send one thing, or show how to use .add but not how to extract this on the other end.

    Thanks!

  • @kristaanie If you're using a Raspberry Pi with a touchscreen installed, you might also have a look at the "Simple Touch" library, and send OSC based on the finger locations & pressures. I can't comment on the OSC part, since I haven't used Processing's OSC libraries.

  • If you see one of the examples of oscP5, there is one called oscP5sendReceive, that it is for the most basic operations (the most important I would say) for oscP5.

    The function for incoming messages have some parameters.

    theOscMessage.addrPattern() is the pattern of the message received, to say, it is the "name" of the message, so you can "filter" messages.

    For example, if I want that my variable a changes everytime I receive the message named "b", I can say

    if (theOscMessage.addrPattern() == "b") {
    a = theOscMessage.getFloat(0);
    }
    

    theOscMessage.getFloat(); takes the argument that comes from the message, there can be all of type of variables in the messages and more than one variable, so the number is the index of the variable to take.

    theOscMessage.typeTag(); check the typetag of the incoming message. It can be something like "sifff", it means that there are 5 variables, the first (index 0) is a String (s), the second is an integer (i), and the other three values are floats (f). If I want to grab the first variable I say

    theOscMessage.getString(0); // because it is a String

    for the integer

    theOscMessage.getInt(1); // getInt because it is an Integer

    and so on, I hope that it helps

Sign In or Register to comment.