Square wave detection for wireless uploading. Either analog or ATtiny.

If anyone has time to help, I will summarize my requirement in one line: I require a circuit that can detect the presence of a 2Hz square wave.

I bought a extremely cheap bluetooth module from China that looks like this JY-MCU module: http://www.dealextreme.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299

This thing is very nice for the price. I can hook it up very easily and receive serial messages as if a wire was connected. The cons to this product are 1) no documentation at all. There is no datasheet for this device, and any datasheets that you find will probably be wrong. 2) no reverse voltage protection. (I cooked one of these already. this is my second.)

I want to be able to upload sketches with this thing. I have already changed the baud rate to 57600 for my Arduino Nano and am now at the point where I can hit upload and press the reset button at a certain time and it will upload, but I want auto-reset. There is an LED on the bluetooth board that blinks when disconnected and is solid on when connected. For many hours, I have looked all over the board for a simpler indicator and cannot find anything, so now I need to make a circuit that pulses a reset pin whenever the ~2Hz square wave turns solid 3.3V.

I had a friend with a larger bluetooth module with a simpler indicator that was OFF,ON and not BLINK,ON. He put together this circuit (requires Java) that pulses a reset pin whenever the input goes HIGH, but in this case it needs to pulse whenever the square wave stops.

I recently learned how to program an ATtiny85, so I am going to use that if no one can come up with any analog equivalent. I know it is overkill but I think this is one of the niche uses of them.

so now I need to make a circuit that pulses a reset pin whenever the ~2Hz square wave turns solid 3.3V.

I am not sure that this will hit the reset at the right time.

The circuit you need is called a "missing pulse detector" and is best done with an NE555 chip. Just google, there are lots of circuits for this.

I think it will hit it at the right time since my eyes and finger can program the Arduino three times in a row.

Thanks for the circuit. I didn't know it was possible with a 555 timer. Now I have to decide whether I want the 555+pulse creator I linked to up there (lots of space) or an ATtiny (very little space).

Would it be possible to wire up the 555 as bistable for say, 10ms?

Why do you want a bi-stable? You need a missing pulse detector. Basically you use your square wave output to discharge the capacitor that is charging for the mono stable to fire. When the square wave stops it allows the monostable to fire and this is connected to your reset pin through a capacitor. You have to arrange the capacitor to be discharged when the square wave is off so this might mean inverting the signal with a transistor.

Ah, my mistake. I thought I could have bistable and the missing pulse detector at once. I'll use this circuit then.

In case you decide to use an ATtiny processor, this should get you started...

typedef enum { sIdle, sUpload } state_t;

static state_t state;
static unsigned long mark;

void setup( void )
{
  // Configure the input (connection LED)
  pinMode( 3, INPUT );
  // Configure the output (RESET)
  pinMode( 4, INPUT );
  digitalWrite( 4, HIGH );
  // Initialize our data
  state = sIdle;
  mark = millis();
}

void loop( void )
{
  switch ( state )
  {
    case sIdle:
      if ( ! digitalRead( 3 ) )
      {
        mark = millis();
      }
      else
      {
        if ( millis() - mark >= 500ul + 50ul )
        {
          // Reset the target
          pinMode( 4, OUTPUT );
          delay( 50 );
          pinMode( 4, INPUT );
          // Wait for the upload to finish
          state = sUpload;
        }
      }
      break;

    case sUpload:
      if ( ! digitalRead( 3 ) )
      {
        mark = millis();
        state = sIdle;
      }
      break;
  }
}