Tuesday, August 30, 2016

Hopping Robot: How I made one


I found this very interesting video, and I will give the author +sauravchakra all the credit for the idea and the demonstration.

However, I would not call this a tutorial--it's a 4+ minute demo of the operation some information on the process. So, I decided to take it to he next step. First, here's all of what I used in the project. Others may add their own ideas, but this is a start, and more than was in the video.

See notes under "Step 5 -Hop!" for planned improvements.

Parts

aluminum: 2 pieces 3cmX1cm (I used scrap from a discarded light fixture)  Author says to drill a 2mm hole 5mm from edge. Since I used bigger screws, I used a 1/8" drill bit (~3mm)
batteries:  3 AAA
battery holder: 3XAAA; see Radio Shack (See note under step 5)
carriage bolt: 1 2" bolt--got it a local hardware store
DC Gear Motor: Only spec is 100RPM. It's a 90 degree shaft,
and we can intuit 4.5V from the power used.  See Jameco
I found one on Amazon for less but shipping takes over a month.
metal rod: 1" long, diameter small enought to fit the wheel, below.
I used parts from a printer tear-down.
plastic: you'll need to cut a piece 5" X 1". I had these around from Amazon.
plastic wheel : 1, small enough to fit in plastic and be held by metal rod above; I used parts from printer teardown, author used a bead
PVC pipe:  need 1 piece 1/2" wide.  Tutorial says 7 cm pipe = ~2.75in--I used 3.5in (outside dimension), from scrap.  Find it at a local hardware store or Home Depot
screws/nuts: author calls for tiny metric screws (like M1.5). I tried that, and my fingers are to fat and clumsy to get that done. I used some 1/2" 4-40 machine screws and nuts that I had bought from a local hardware store
slide switch  (SPDT):  This could be SPST, but this is what author used and also what I had, from Adafruit

Tools and Supplies

Coping Saw: to cut plastic, bought at local hardware store
Files: for deburring metal and plastic--I have this set from Harbor Freight
Hack Saw: for cutting metal and PVC, sourced locally
Heat Gun: to soften plastic for bending and for heat shrink;  inexpensive at Harbor Freight
Heat Shrink Tubing: to insulate soldered wires (batteries/motor/switch), from Radio Shack, Adafruit, et al.
Hot Glue Gun: to attach various components; Home Depot has this one
Snips: to trim metal and plastic--sourced locally
Soldering Tools:solder battery/motor/switch connections, from Radio Shack, Adafruit, et al.
Vise: I make great use of my bench vise like this Craftsman
Wire Strippers: for cutting and stripping the motor and battery wires to prepare for soldering--sourced locally

Assembly

The photo above shows the parts ready for assembly.  Clockwise from upper left:
  1. Slide switch
  2. 2" carriage bolt
  3. DC Gear Motor with aluminum pieces attached to rotating arms
  4. 2 halves of a 1/2" slice of PVC pipe, for the legs
  5. battery holder
  6. piece of ABS plastic, cut to size, bent at the 1/4 with indentation for the wheel, 1/16" holes for the switch leads, and a 1/8" hole for the battery wires
  7. I left the rod and wheel out of the photo. See Step 2.
The process

Step 1 - fabricate the parts
The PVC pipe, the plastic, and the aluminum pieces all needed to be cut out.  
PVC: I found a piece of 3.5" PVC pipe, cut off a half inch slice, then cut that in half
Plastic:  a had some sheets of 1/8" thick ABS, and in fact had plenty of scrap from other projects, so I took a small piece and cut it to size with a coping saw. Then I measured one quarter of the length, drew a line, hit that area with the heat gun, then put it in the vise and bent it to a 90 degree angle. Then I cut out about a 3/4" section, 3/8" high out of the bottom of the bent section.  That's where the wheel will go. I needed a hole for the battery wires and 3 hole for the switch pins, so I drilled those.
Aluminum: I had replaced a failed under-counter fluorescent light fixture and kept the old housing for scrap.  I cut out two 3cm by 1cm pieces (really about 1.25" X .5" ). I tried the small M1.5 screws but my fingers just would not cooperate, so instead of a 2cm hole I drilled a 1/8" hole to accommodate 4-40 machine screws.

legs hot glued to aluminum
Step 2 - attach the legs
one leg with hot glue treads
  1. Drill 1/8" holes in the rotating arms of the motor (make sure you put them on the same side so the metal pieces are oriented in the same direction--i.e., not one horizontal and the other vertical). My drill doesn't do metal too well, so I used a hammer and nail to complete the hole
  2. Fasten the aluminum pieces to the arms with 3/8" 4-40 screws and nuts
  3. Hot glue the PVC pieces, with the convex side facing the rear (opposite from the rotating end).
  4. Add lines of hot glue about every 1/2" along the outside of the PVC for traction.
Step3 - populate the frame
rod, wheel, and slot in frame
wheel hot glued to frame













  1. Put the rod through the wheel and hot glue it to the open area in the frame (making sure that the wheel clears the bottom of the frame and turns freely)
  2. Hot glue the switch to the frame, with the pins through the 3 holes
  3. Hot glue the battery holder to the frame and thread the wires through the 1/8" hole
  4. Hot glue the motor+legs to the frame--check the photos to be sure everything is facing in the right direction
Step4 - wire it up
  1. First connect the red wires and black wires from the motor and batteries to each other.  The legs should turn clockwise. If not, reverse the wires.
  2. With the polarity verified, start trimming and soldering.
  3. After wiring and testing, hot glue the 2" carriage bolt in place for stability




Step 5 - Hop!

It's done and it works, but I need to make some improvements.

  1. I couldn't find my hot glue gun, so I borrowed a low-temp one from my wife.  I'm blaming that for the fact that the legs come off at times, so I'm going to find mine or by a real one, and re-fasten the legs
  2. The open battery holder does not secure the batteries and the tend to fall out.  I have enclosed ones on order from eBay, but ti will take a while
  3. The PVC may be too heavy, because the legs what to stay still while the motor spins.  It's still amusing, but not as designed.  I may try thinner legs (e,g., 3/8" slices of PVC instead of 1/2")

Monday, August 22, 2016

Interference Problem Solved

For the category "better late than never"...

Before I left for Texas for a month, I disconnected the antenna cables to my Ten Tec Jupiter HF  rig and my Yaesu FT1900R 2 meter rig.  When I got back and reconnected everything,  I had major QRN on 2 meters. People could hear me fine, but reception was spotty at best.  

I tried moving the cable around with no success.  The only difference from before the trip is that central air conditioning unit was on.  I never got motivated to get into into in detail, because HF was fine (I thought) and I use 2 meters more for mobile.

This past weekend we had an ARES drill for which I was assigned to operate my base station. I turned off the A/C--no difference on 2M.  The next suspect was the computer, but that's always been right where it is.  I shut the computer down and the static disappeared. I looked online and found that the monitor may be the problem.  I tried just turning off the monitor without shutting down--that was it.  Brain jock that I am, I ran the antenna cable behind the monitor.  I moved it, running it under my desk to the Yaesu, and that was it.

We were also operating on 40 meters.  I was getting static there in about a 3kHz range. Since the radio gods have a sense of humor, the frequency we used was right in the middle of that range.  It turns out that the source was the A/C--when the unit switched on, I got static.

Moral of the story: don't run antenna cables behind a computer monitor, and A/C has potential  to produce interference.

Monday, August 15, 2016

Control AC Devices over the Internet



When I built the project described in my post on controlling devices from a smartphone, my brother-in-law said "yeah, but can you do that over the internet?"  The answer was yes, but I needed to wait until my +Adafruit Industries Feather Huzzah with ESP8266 WiFi arrived. I had already decided to use adafruit.io as the browser component.  It was super easy to set up a dashboard and two feeds-a button interface to turn the light on and off and a text feed (output from the Huzzah) so I could see what the code thinks it's doing (see the tutorials at the adafruit.io link provided above.

By following the tutorials and code examples, and cloning what I could from tmy bluetooth project (see above), I got it working very quickly.  However, I wanted it to be a useful device that I could give to my brother-in-law. As noted in other posts, he has helped with all kinds of projects.  So, I needed a project box, a circuit board and a few other things, and I needed to do some designing. My first thought was to find a 120V relay and make my own Power Switch Tail.  In studying the schematic, I found that there were all kinds of circuit protections included, so I decided to go with a commercial product.  The powerswitch was US$26, so I looked for an alternative.  I found this AC/DC Control Relay on Amazon. The price has gone up by $2 since I bought it, but it's still $9 less than the powerswitch and has more capability. For example, it has 4 receptacles, 2 normally off and 2 normally on, so it can control multiple devices.

Parts and supplies list, partially annotated

  • AC/DC Comtrol Relay (takes input from the Huzzah: a signal line and a ground line; different from powerswitch tail, which also takes a DC power input; in addition the logic is opposite--power swith tail closes the relay on LOW, this one closes it on HIGH) )
  • +Adafruit Industries Feather Huzzah with ESP8266 WiFi Board
  • 2-wire JST connectors (connect to the relay)
  • LEDs (I used 5mm, one green, one red)
  • resistors (current-limiting for LEDs--I used 330Ohm)
  • 22-gauge solid core hookup wire 
  • tinned copper bus wire
  • project box (this was tight, but I wanted it small)
  • circuit board (I started to use plain perf board, but it broke--these boards were not quite the right size, so I had to file them. The soldering pads were useful.)
  • 3/8" 4-40 machine screws (to attache the circuit board to the standoffs in the box)
  • Drill and bits
  • A set of files (to deburr the drilled holes, and to size the holes properly)
  • Normal project tools: soldering iron and accessories, multimeter, strippers, clippers, helping hands and/or Panavise Jr., and the like
  • Super Glue or the like to fix the LEDs and JST to the box
  • Heat shrink tubing

Concept

The circuit is very simple, maybe deceptively so.  As you will see in the code, it connects to wifi, then connects to adafruit.io, and turns everything off at the start (in setup), then waits for orders from adafruit.io.  The toggle button on the adafruit.io dashboard sends info to the Huzzah, and depending on the state of the lamp (or whatever device you have plugged into the relay), it toggles the state.

The LEDs are used as indicators.  The green LED turns on after successful connection to adafruit.io (if it's not on, there's a problem). The red LED turns on and off with the lamp or other device (also to help see what's going on).

Schematic


Assembly

I spent a lot of time planning where to put the LEDS and the JST connectot. I had some scrap ABS plastic left from my robot cart project, so I used that to test a few options:




I wanted the JST to be recessed, but that didn't work out. I liked the LED holders, but they took up too much room in the box.

I drilled a hole in one end of the box for the USB cable, then drilled 3 3/16" holes in one side for the LEDs and JST connector.  The holes needed to be enlarged, so I took time to get just enough room to get the components through, while still not allowing the whole component to pass.

I had to expand two of the mounting holes on the circuit board to get the screws through. The other two holes did not line up with the standoffs.  I planned to mount the board with the soldering pads down, so I could keep the minimal wiring out of the way.

I positioned the Huzzah on the board, and used hookup wire to fix the back end to the circuit board through the mounting holes.  I had to remove one later to allow access to one of the LED holes in the case.  I ran black hookup wire under the board from the HUZZAH GND pin to the Ground bus on the other side of the board.  I soldered the hookup wire to the GND pin and to the soldering pad in the corner of the opposite side.  I ran tinned copper bus wire from the hookup wire down that side of the board and soldered each corner.


Next, I conencted the 330Ohm resistors through the board to the Ground bus and soldered them to it, then cut the wires on the female end of the JST to length, positioned it in the hole in the box, and soldered the black wire to the Ground bus and the red wire to pin 2 (see schematic above).

Note: if I were to do this again, I would run the Ground bus down the opposite side of the board, solder one end of the resistors to it on the underside, and solder the other ends of the resistors to the ground leads of the LEDs. That would make it neater.

I then took the time to test the circuit to be sure the connections were OK.  Using the Arduino IDE serial monitor and the relay with a lamp plugged in, I found that all was good.  I then added the LEDs, connecting the proper leads to the resistors and to the correct pins, and soldering.  One more test showed the LEDs functioning properly, so I screwed the circuit board to the box.

The final touches were to trim the connections to the resistors, use some electrical tape for insulation, and to super glue the LEDs and JST connector to the box.  Finally, I spliced the male end of the JST to hookup wires leading to the corresponding connections on the relay (there is a terminal block on the relay).  After testing the connections for continuity with my multimeter, I applied heat shrink to each splice and then a long piece of heat shrink to the whole connection.
Enclosure before gluing LEDS and JST and adding screws

Project Video

On my youtube channel

Code

/***************************************************
  Adafruit MQTT Library ESP8266 Example

  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino

  Works great with Adafruit's Huzzah ESP board:
  ----> https://www.adafruit.com/product/2471
  products from Adafruit!

  Written by Tony DiCola for Adafruit Industries.
  Adafruit IO example additions by Todd Treece.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
/*  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing */

/*2015-08-15 Virgil Machine
  Light goes on, light goes off, internet style
  I used the adfruit.io tutorial and the adafruit esp8266
  tutorial and library examples to get the connection stuff.
  The logic is mainly cloned from my bluetooth example 
  (see virgilmachine.blogspot.com). Connects to WIFI, connects 
  to adafruit.io, turns on green LED to indicate connection,inbitializes 
  logic and devices to off, then waits for instructions from 
  adafruit.io--toggle switch to turn light on and off. Sets relay
  pin to HIGH, also turns on red LED and on-board LED, and vice versa.
  */
#include
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

// function prototypes
void connect(void);

/****************************** Pins ******************************************/

#define LAMP           2  // AC/DC Control Relay 
#define LED            0  // on-board LED
#define POWER_LED      4  // lED to show power on
#define LAMP_LED       5  // lED to show LAMP on

/************************* WiFi Access Point *********************************/
//use your own values here

#define WLAN_SSID       "SSID"
#define WLAN_PASS       "PASSWORD"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
//use your own values here
#define AIO_USERNAME    "USERNAME"
#define AIO_KEY         "adafruit.io KEY"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM  = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;
int current = 0;
char light_on[] = "Light Goes On";
char light_off[] = "Light Goes Off";
//2016-08-08 vm char stuff replaced by boolean
bool lamp_on = false;  //initalized to off to match the rest of the code

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

// Setup a feed called 'lamp' for subscribing to changes.
// Notice MQTT paths for AIO follow the form: /feeds/
const char LAMP_FEED[] PROGMEM = AIO_USERNAME "/feeds/UncleJimThing";
Adafruit_MQTT_Subscribe lamp = Adafruit_MQTT_Subscribe(&mqtt, LAMP_FEED);
// Use feed UncleJimText as TEXT_FEED for publishing changes.
// Notice MQTT paths for AIO follow the form: /feeds/
const char TEXT_FEED[] PROGMEM = AIO_USERNAME "/feeds/UncleJimText";
Adafruit_MQTT_Publish text = Adafruit_MQTT_Publish(&mqtt, TEXT_FEED);
/*************************** Sketch Code ************************************/

void setup() {

  // setup relay and LED pins as outputs and start off as LOW
  pinMode(LAMP, OUTPUT);
  digitalWrite(LAMP, LOW);  //default to off at startup (had this backwards) 
  pinMode(LED, OUTPUT);  //for testing
  digitalWrite(LED, LOW);  //default to off at startup
  // setup pins for indicator LEDS 
  pinMode(LAMP_LED, OUTPUT);
  digitalWrite(LAMP_LED, LOW);  //default to off at startup
  // POWER_LED IS SET to HIGH in connect() routine, after successful connection
  //but default to off until then
  pinMode(POWER_LED, OUTPUT);  //to show if we're connected
  digitalWrite(POWER_LED, LOW);  //default to off at startup 
  
  Serial.begin(115200);

  Serial.println(F("Uncle Jim IO Example"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // listen for events on the lamp feed
  mqtt.subscribe(&lamp);

  // connect to adafruit io
  /* when we connect successfully, the LED is turned on
  so we enter loop with the POWER_LED indicator on
  but it's off until then
  */
  connect();
/****2016-07-17 VM 
     We want the test to say "light goes off at startup, since we set if off in setup
     I think this will work here--***experiment***
****/
     text.publish(light_off);
}

void loop() {

  Adafruit_MQTT_Subscribe *subscription;

  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
    { digitalWrite(POWER_LED, LOW);  //turn off LED to show we're not connected  
      connect();
    }  
  }


  // this is our 'wait for incoming subscription packets' busy subloop
  while (subscription = mqtt.readSubscription(1000)) {

    // we only care about the lamp events
    if (subscription == &lamp) {

      // convert mqtt ascii payload to int
      char *value = (char *)lamp.lastread;
      Serial.print(F("Received: "));
      Serial.println(value);
      Serial.print(F("\nlamp-state in: "));
      Serial.println(lamp_on);
      int current = atoi(value);
      if (lamp_on) {  
        Serial.println(light_off);
        text.publish(light_off);
        digitalWrite(LAMP, LOW);  //RELAY
        digitalWrite(LED, LOW);  //ON-BOARD
        digitalWrite(LAMP_LED, LOW); //INDICATOR
      } else {  
        Serial.println(light_on);
        text.publish(light_on);
        digitalWrite(LAMP, HIGH); 
        digitalWrite(LED, HIGH);
        digitalWrite(LAMP_LED, HIGH);          
      } 
      lamp_on = !lamp_on; //toggle lamp state         
      Serial.print(F("\nlamp-state out: "));
      Serial.println(lamp_on);
  
      Serial.print(F("\nSending button value: "));
      Serial.print(value);
      Serial.print("... ");

    }   //if subscription is lamp
  }     //while subscription
}       //loop

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Uncle Jim IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Uncle Jim IO Connected!"));
  digitalWrite(POWER_LED, HIGH);  //turn on LED to show we're connected  
}