Voice Activated Socket Selector - Particle Argon - IOS Shortcuts - Lane Tech

by bmuich in Circuits > Microcontrollers

710 Views, 5 Favorites, 0 Comments

Voice Activated Socket Selector - Particle Argon - IOS Shortcuts - Lane Tech

IMG-2855.jpg

I don't know about you, but I enjoy tinkering. Anything that has moving parts has always interested me. Recently, I have been interested in the restoration of vintage motorbikes. Anybody that has had a project like this understands that after about an hour of working on something, it is almost impossible to find the tool that you need. I came up with a device that allows you to ask for a socket, and it will get it for you. Rather than digging through a case with unorganized tools, you can simply use your phone.

This device will utilize the Shortcuts app on your iPhone in order to dictate your voice. This will allow you to send data to the microcontroller (Particle Argon) and will allow a stepper motor to turn to a desired position. This position will point to whichever socket, or item you want. Now you won't have to look through a box of tools to pick the right one!

Supplies

IMG_2795 (1).jpg
IMG_2803 (1) (1).jpg
IMG_2801 (1).jpg
IMG_2800 (1).jpg
IMG_2797 (1).jpg

Materials:

Particle Argon

Stepper Motor and Motor Driver

Led Light Strip (Individually Addressable)

5V Wall Wart

Barrel Adapter

Cardboard Scrap (or wood if you're feeling fancy)

iPhone (Shortcuts App)

Glue

Tools:

Soldering Iron

Hot Glue Gun

Copying the Code Into Your Argon

The code is essentially the brains of your code. It will determine what gets sent to your stepper motor. It utilizes a webhook that is sent to your argon, through a dictate function which is native to iOS Shortcuts. At the moment, the only way to trigger the webhook is through Shortcuts.


Please paste the code into your IDE in this order.

DO NOT copy the notes about the code.


//Global Variables:
bool signalRecieved = false; 
int control = 0;
int initControl = 0;
int origSocket[19] = {0,0,0,0,0,0,0, 205, 410 , 614 , 819 , 1024 , 1229, 1434 ,1638, 1843, 2048};

This array are the different degrees that the motor will turn when the webhook sends different values.

For example: If the number 10 is sent through the webhook, the motor will step 614 times. (This value is out of 2048)

If you want to have more items, divide the amount of items you have by 2048. Then, take these values and fill in the indexes in the array.

0's in the array are used a buffers because for my use case, there are not 1 millimeter sockets. It will only work if "8" or higher is sent through the webhook.


// These #include statement were automatically added by the Particle IDE.
#include <neopixel.h>
#include <Stepper.h>
#include <ArduinoJson.h>
#include <iostream>
//Stepper Pins
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 5
// IMPORTANT: Sets pixel COUNT, PIN and TYPE for Neo Pixle
#define PIXEL_COUNT 5
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
const int stepsPerRevolution = 2048;
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup(){
  myStepper.setSpeed(10);
  Serial.begin(9600);
  //Calibration occuring in setup (Motor moves clockwise, then counterclockwise one full rotation)
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  
  strip.begin();
  for(int i = 0; i < PIXEL_COUNT; i++){
    strip.setColor(i, 0,255,0);
  }
  strip.show();
  delay(1000);
  for(int i = 0; i < PIXEL_COUNT; i++){
    strip.setColor(i, 255,0,0);
  }
  strip.show();
  delay(1000);
  for(int i = 0; i < PIXEL_COUNT; i++){
    strip.setColor(i, 0,0,255);
  }
  strip.show();
  delay(1000);
  strip.clear();
  strip.show();
  Particle.subscribe("shortcut_sent", responseHandler);
}


//Parse data from webhook
void responseHandler(const char *event, const char *data) {
  // Handle the integration response
  Serial.print(", data: ");
  if (data) {
    control = (atof(data)); 
    Serial.println(data);
  } else {
    Serial.println("NULL");
  }


  if(control < 5 && control > 1){
        nullptr;
        for(int i = 0; i < PIXEL_COUNT; i++){
            strip.setColor(i, 255,0,0);
        }
        strip.show();
        delay(3000);
        strip.clear();
        strip.show();
    }else{
    signalRecieved = true; //activates loop (Constantly listening for condition)
    }
}

This if statement above can be changed if you need to disallow values from being used.


//function that constantly listens for the apple shortcut
void loop(){
    if(signalRecieved == true){
        for(int i = 0; i < PIXEL_COUNT; i++){
            strip.setColor(i, 0, 255,0);
        }
        strip.show();
        
        if(control == 1){
            for(int i = 0; i < PIXEL_COUNT; i++){
                strip.setColor(i, 0, 0,255);
            }
            strip.show();
            myStepper.step(-origSocket[initControl]);
            delay(3000);
            strip.clear();
            strip.show();
        }else{
            //initControl holds last value of Control and the motor is zeroed every time there is a new
//request.
            myStepper.step(-origSocket[initControl]);
            myStepper.step(origSocket[control]);
            initControl = control;
            delay(3000);
            strip.clear();
            strip.show();
            
        }


        signalRecieved = false;
        
    }
}

Set Up IOS Shortcuts

IMG_2829.PNG
IMG_2830.PNG
IMG_2831.PNG
IMG_2813.PNG
IMG_2814.PNG
IMG_2815.PNG
IMG_2826.PNG
IMG_2827.PNG
IMG_2828.PNG

iOS shortcuts is a great resource if you want to automate functions on your iPhone. You can send messages, perform an action when you go to a certain location, or even send webhooks. This is the key action that we will be using in our shortcut. It will allow you to send a variable that is created through dictating text, to your Particle Argon.

( I will not go through the steps in creating some of the extra pieces, I will just go through how to get started and how to send your webhook containing the data.)


In the example images, there is a list at the very top of the shortcut. This step is optional as it acts as a secondary safeguard against sending the wrong data.

  • If you have an iPhone, navigate to the iOS shortcuts app.
  • Press the blue "+" sign in the top right corner to create a new shortcut.
  • From here, press the blue "Add Action" button which is where you will start building your shortcut.
  • Then, type "dictate text" into the search bar.
  • There should be a dictate text function that shows up.
  • We will start with this to start as it will allow you to use your voice to create a variable containing whatever you said while the shortcut was active.
  • Next, create an If statement with the dictated text variable and set it up so that, if the dictated text contains a key word - in my case "mm" - (continue to the next step)
  • In the search bar, search for text. Once you have it, insert it just below the if statement and insert the "dictated text" variable into it
  • Because we want to isolate the integer in the dictated text, place the "replace" function under the text box.
  • Set the replace function so it will replace your key word (in my case "mm") with nothing in order to isolate just the integer.
  • This new text variable will be called "updated text"


  • OPTIONAL - Create a List that goes at the very beginning and include the values that you will only use.
  • Place an if statement after replace function (the step before this) and set it up so that: If the List contains the Updated Text, then... (continue to the next step)


  • In the search bar, search for "Get Contents Of" and place that next.
  • (If you DID do the optional step, place this webhook inside of the if statement that you created during the optional step)


  • Setting up the webhook gets complicated to bear with me. (please refer to the images for clarification)
  • First you need to create the webhook through the Particle Integrations.
  • Select "Webhook" as that is what we are creating then "Create New"
  • Name your event whatever you want. For example: "Selector"
  • Before creating your URL, you need to get your Access Token.
  • Go to the link, sign into your Particle account and scroll down to get your access token.
  • You will also need the name of your Particle Argon.
  • To do this, go to the Particle IDE and navigate to the "Devices" Page on the left side.
  • Use the following template in for the URL box:
  • "https://api.particle.io/v1/devices/[Name of Your Device]/[Event Name]/?access_token=[Access Token]"
  • Next, make the request type, "POST"
  • The request format should be "web form"
  • The devices should be set to "Any"
  • Finally, the status can be enabled or disabled


  • Next, in your shortcuts app:
  • Delete any variables in the very top box where it says, "Get Contents Of: [ URL ]"
  • In the empty space for the URL, paste the following: "https://api.particle.io/v1/devices/events"
  • Change the Method to a Post request NOT a get request
  • Add a new header:
  • For the Key, input, "Authorization"
  • For the Text, input, "Bearer [Access Token]"
  • Add two new fields:
  • The Key for the first one should be, "name"
  • The Text for the first one should be, "[Event Name]"
  • The Key for the second one should be, "data"
  • The Text for the second one should be the "Updated Text" Variable


There is still a lot you can do however, this should take you through the basics and the webhook.

(Refer to the Images for the rest of the shortcut)

Set Up the Breadboard!

IMG_2805 (1).jpg
IMG-2794.jpg
IMG-2785.jpg
IMG-2787.jpg
IMG-2790.jpg

This is a very important step as the wiring needs to be perfect in order for it to work.

Please refer to the wiring diagram and the wiring instructions below


DO NOT: Plug anything into the MD pin (Right next to the GND pin on the Argon)

Wiring Instructions

IMG_2810 (1).jpg

Barrel Plug:

  • Positive -> Positive Power Rail
  • Negative -> Negative Power Rail

Particle Argon (Power):

  • Positive Power Rail -> VUSB (Argon)
  • Negative Power Rail -> GND (Argon)

Led Light Strip:

  • Positive (5V) -> Positive Power Rail
  • Signal -> D6 (Argon)
  • Negative -> Negative Power Rail

Stepper Motor Driver:

  • Positive (5 - 12V) -> Positive Power Rail
  • Negative -> Negative Power Rail
  • IN1 -> D5 (Argon)
  • IN2 -> D4 (Argon)
  • IN3 -> D3 (Argon)
  • IN4 -> D2 (Argon)
  • Connector -> Stepper Motor


Base

IMG_2802.jpg

The Base of the rotating table


A sturdy piece of cardboard should be suitable for the base. If you want to build it to last, I would suggest a thin piece of plywood. I would ensure that the base is larger than or equal to the diameter of the top spinning plate to ensure it is sturdy.

To fasten the stepper motor to the base, I hot glued the 3D printed housing to the cardboard which made a very strong bond. This made a relatively sturdy base.

Finally, I would make a resting place for the top and the base to line up when the system has reset

(That is the little piece of paper)

Rotating Table

IMG_2833.jpg
IMG_2832.jpg

Rotating table with motor interface

The rotating top will spin in order to point to the correct tool using a series of markers on the surface.

In order to make your table spin with the motor, you will need something to interface with the key on the motor's output drive. I used a 3D printed gear which interfaces with the motor.

I used this gear to attach it to the cardboard by hot gluing it into a hole in the cardboard.

For the Top, I would recommend a diameter of at least 8 inches. (This turned out to be a little too small for my use case)

You may want to glue a piece of paper into the top to make the markers more legible.

Finally, make a reset point on the top to line up with the point on the base when the motor position is reset.

Assembly

IMG_2837.jpg
IMG_2835.jpg

Connect the motor and the top. This may sounds easy but it depends on how you interface your motor with the top. If you used something that was 3D printed this will be very easy however, if you just used hot glue, I would be careful of ruining the electronics

Running Project

Socket Selector Project

Demonstration of finished working project with voice activation