Search This Blog

Saturday, December 23, 2017

Prometheus: Stealing the "Gift" of Vaping from the gods...

(Cheat: Like Prometheus, who gave men the gift of fire and metal work against the wishes of the gods, we are able to very cleverly include all of humanities accomplishments with respect to music, movies and sound within the FDA's definition of "tobacco product" while still allowing "man" the gift of fire and metal work vaping.)

In the 2012 movie "Prometheus" a team of human's follows various markings in caves to a distant star where the "Engineers," aliens with the same DNA as humans, have established a base station.  Within the base station "David" - a robot - discovers the command center of an alien ship.  A holographic movie shows David how the aliens use a simple musical flute to control the ship (see starting at 1:06 here).

An "Engineer" operating the ship - from the linked video

This is not unlike the 1970's movie "Close Encounters of the Third Kind" where sound is used to communicate with the alien mother ship (see starting 0:05 here).

So as I have been thinking about the history of the PrimusZ and all the work that was required to make phones communicate with it I came upon the Adafruit Bluefruit MIDI code.

Since the OSP uses the Adafruit Bluefruit Feather (Feather) it's sort of a no-brainer that MIDI is the way to talk to and from your OSP.

This is because there is already a vast, vast infrastructure of software, tools, apps, etc. available in the world that allows you to quickly and easily control things via MIDI.

But before committing to this path I whipped up a simple test with the Feather.  I have an iPhone so I used the following apps:

bismark bs-16i - This is a small MIDI piano app.  The important elements are that under the MIDI symbol you can set the CORE MIDI INPUTS/OUTPUTS.

midimittr - This is a MIDI routing application that allows you to connect to wireless Bluetooth MIDI devices.  In this case the Feather, using the menu item Files -> Examples -> AdafruitBluefruitLE nRF51 -> midi app (with slight modifications listed below) you can connect your phone to the Feather and send and receive MIDI commands.

So what you do is fire up the Adafruit MIDI code linked above (you don't code need changes to try this) on your Feather.

Next you start midimittr and choose the three-bar menu at the upper left and select "Clients."

A list of BLUETOOTH MIDI DEVICES appear.  If you've successfully built and install the Adafruit MIDI code on your Feather you should see an entry for "Adafruit Bluefruit LE" that's "Not Connected."

Tap the "Not Connected" and your phone should connect to the Feather as a MIDI device.  (Haven't yet tried for Android but I plan on it soon).

The default MIDI code simply sends notes.

Then you select the MIDI piano app, select the menu to set the MIDI Input and assign it to the "Adafruit Bluefruit LE."  Immediately the piano should start playing an ascending sequence of notes.

Once I had this working I diddled the sample code to produce the following:



(There is a little read light where the USB cable connects that turns on and off after each keyboard sequence.)

Clearly here I am controlling the Feather on the table, not the OSP (yet).  Now that this is working we can proceed to merging the OSP and Adafruit MIDI code onto the OSP.  This will open the full world of OSC and MIDI apps (this for example or Lemur):

TouchOSC

Like Prometheus, we are able to cleverly include all of humanities accomplishments with respect to music and sound and so forth within the FDA's definition of "tobacco product" while allowing "man" the gift of fire and metal work vaping.

(Previous posts on this here: http://lwgat.blogspot.com/2017/12/multi-use-osp-making-facebook-fda-ends.html)

EDIT: Bluetooth MIDI connection works via Android "MIDI+BTLE" app (free).  Haven't been able to find a decent keyboard app to test the rest but it seems like it should work just fine.

Changes I made for the video to the Adafruit MIDI (two routines):

bool cmdMode = false;
int cmdState = 0;

void BleMidiRX(uint16_t timestamp, uint8_t status, uint8_t byte1, uint8_t byte2)
{
  Serial.print("[MIDI ");
  Serial.print(timestamp);
  Serial.print(" ] ");

  Serial.print(status, HEX); Serial.print(" ");
  Serial.print(byte1 , HEX); Serial.print(" ");
  Serial.print(byte2 , HEX); Serial.print(" ");
  Serial.print(cmdState , HEX); Serial.print(" ");
  Serial.print(cmdMode? 1: 0 , HEX); Serial.print(" ");

  Serial.println();

  if (status != 0x90) // chan 1
    return;

  switch (cmdState)
  {
    case 0:
      if (byte1 == 0x4F)
      {
        if (byte2 == 0) cmdState++;
      }
      else
      {
        cmdState = 0;
        cmdMode = false;
      }
      break;

    case 1:
      if (byte1 == 0x51)
      {
        if (byte2 == 0) cmdState++;
      }
      else
      {
        cmdState = 0;
        cmdMode = false;
      }
      break;

    case 2:
      if (byte1 == 0x4D)
      {
        if (byte2 == 0) cmdState++;
      }
      else
      {
        cmdState = 0;
        cmdMode = false;
      }
      break;

    case 3:
      if (byte1 == 0x41)
      {
        if (byte2 == 0) cmdState++;
      }
      else
      {
        cmdState = 0;
        cmdMode = false;
      }
      break;

    case 4:
      if (byte1 == 0x48)
      {
        if (byte2 == 0) 
        {
          cmdMode = !cmdMode;
          cmdState = 0;
        }
      }
      else
      {
        cmdState = 0;
        cmdMode = false;
      }
      break;

    default:
      cmdState = 0;
      cmdMode = false;
      break;
  }

  Serial.print(cmdState , HEX); Serial.print(" ");
  Serial.print(cmdMode? 1: 0 , HEX); Serial.print(" ");

  Serial.println();
  
  digitalWrite(LED_BUILTIN, cmdMode? (byte2 != 0? LOW : HIGH) : (byte2 != 0? HIGH : LOW));
}

void loop(void)
{
  // interval for each scanning ~ 500ms (non blocking)
  ble.update(100);

  // bail if not connected
  if (! isConnected)
    return;
}

1 comment:

  1. I think you shold quit smoking. It's bad to your health. You can use crystals to help you heal your mody and mental. Try to buy raw green aventurine, you will love the energy of green aventurine.

    ReplyDelete