Using the Esplora hardware device with Keyboard Maestro

I own a working Esplora which I haven't used much:

I'm unsure what I need to do to see if it is recognized by KM. I've tried getting the KM "Device Key Trigger" to recognize the buttons, but it doesn't see them. I believe there's a serial port I can use to talk to and receive text from the Esplora. Is that my fallback solution?

1 Like

I have no idea. It looks a bit like the one i posted above. All buttons work on that one, except for the x-y. Just as you say, as USB device key trigger. I have no idea why yours doesn’t. Is there a specific reason you want to use this one? Otherwise, maybe just use something else… like this one

The only Joystick (or do they call them controllers now?) that I own is the Esplora. If I bought the $5 controller you recommend then I’d also have to buy a joystick. Besides, the Explore has controllable lights, sliders, speakers, accelerometers and more. It looks like a good match for the power of KM.

yes, you have to buy buttons etc, true. But that was my initial goal. i wanted to have these.

How could we use led’s on devices to lit up using KM?

Talking to the Esplora is generally done via a serial port, which on a Mac is usually /dev/cu.usbmodem1641. No drivers need to be installed. You (ie, macOS) can send any characters to the device via that port and the Esplora device can read your characters and send responses back via the same port. So hypothetically I could decide that sending the characters “Red” to the Explore would set the multicolour button to Red. And the Esplora could decide to report the 27 degree temperature by sending T27 back through the port. You invent your own protocol to read and control the device.

Is this what you are asking? I’m not sure. The Explore has 4 buttons, so that would also meet your needs.

The serial port isn’t the only way to talk to it. The device can also send ascii characters through the USB port it is connected to. So it can act as a keyboard (or even a mouse). So for example I could easily set up that little joystick to send the codes to move the mouse right or left. But this is one way communication from the device to the computer. For return data, I think you need to use the serial port.

P.S. Something is auto-correcting the name of the product to “Explore” even when I type the name correctly, sorry about that.

Here is the actual code I uploaded to my Esplora. Notice that it simply reports every 0.1 seconds through a series of text lines to the device /dev/cu.usbmodem1461 and how to handle that in KM follows this:

#include <Esplora.h>

void setup() { Serial.begin(9600); } // initialize serial communications with your computer

void loop()
{
Serial.println(Esplora.readButton(SWITCH_1));
Serial.println(Esplora.readButton(SWITCH_2));
Serial.println(Esplora.readButton(SWITCH_3));
Serial.println(Esplora.readButton(SWITCH_4));
Serial.println(Esplora.readSlider());
Serial.println(Esplora.readTemperature(DEGREES_C));
Serial.println(Esplora.readTemperature(DEGREES_F));
Serial.println(Esplora.readLightSensor());
Serial.println(Esplora.readMicrophone());
Serial.println(Esplora.readJoystickSwitch());
Serial.println(Esplora.readAccelerometer(X_AXIS));
Serial.println(Esplora.readAccelerometer(Y_AXIS));
Serial.println(Esplora.readAccelerometer(Z_AXIS));
Serial.println(Esplora.readJoystickX());
Serial.println(Esplora.readJoystickY());
Serial.println(Esplora.readRed());
Serial.println(Esplora.readGreen());
Serial.println(Esplora.readBlue());
Serial.println("EOF");

delay(100); // delay in between reads for stability
}

Every tenth of a second that information is written to /dev/cu.usbmodem1461 and you can read that data using the following KM action: (it wasn't easy to figure out how to make this action work, it involves a little trickery with sed)

Of course then you have to extract the relevant information. If you are reading this you can probably handle that part.

The other half of the problem is sending data to the Esplora from KM. That would involve sending data to the same device and having the Esplora read the commands. The device has a single light diode that can handle a range of RGB brightnesses (0-255 each) and a simple sound generator. My approach to handling that would be for KM to write 4 numbers per line. The first three values represent the RGB diode intensity (or -1 for no change) and the fourth value represents the speaker frequency (-1 for no change). If anyone wants to see that I can post it.

There’s more than one way to encode signals to the Esplora from the Mac via the serial port. If you don’t like the way I’m posting below, find another way. If you want to merge the above program with the below program for a two-way driver, it should work.

#include <Esplora.h>

void setup() { Serial.begin(9600); } // initialize serial communications with your computer

// routine to read an integer (A=0, B=1, C=2... up to the letter P=15) from Serial port
int getint()   { char hex1 = Serial.read(); char hex2 = Serial.read(); 
                 char hex3 = Serial.read(); char hex4 = Serial.read(); 
                 return (hex1-'A')*4096+(hex2-'A')*256+(hex3-'A')*16+(hex4-'A'); }

void loop() {
  char code,r,g,b; int t; Serial.setTimeout(50); // not too sure if this helps or hurts
  if (Serial.available()>0) 
  {
    code=Serial.read();
    if (code=='1') 
    {r=getint(); Esplora.writeRed(r); delay(1);}
    else if (code=='2') 
         {g=getint(); Esplora.writeGreen(g); delay(1);}
         else if (code=='3') 
              {b=getint(); Esplora.writeBlue(b); delay(1);}
              else if (code=='#') 
                   {t=getint();  Esplora.tone(t); delay(1);}
                   else 
                   {while (Serial.available()>0) Serial.read();}
     // the delay(1) routine seems to fix a timing issue, seems to be required for colour Red only
  }
}

I tried using integers, carriage returns and spaces rather than this pseudo-hex approach, but this was much easier to code and debug. If you can do better, let me know.

Creating a KM action to control the Esplora should be obvious (enough) given the code above, but less obvious is how to create an action to read the Esplora's values. So I'm attaching the actions below.



Whenever you need to fetch data from the Esplora, just call those actions. In fact, you could put them in an infinite loop if it's convenient for you.

sounds like you can make your own thread about this.

I didn’t know that when I started. Life is unpredictable.