Sunday, December 22, 2013

Adafruit Trinket USB Problem -- Intermittent issues/problems [Solved]

When I first bought Adafruit's Trinket, I was experiencing an issue with my Windows 7 desktop PC.
I could not get my Trinket's red LED to pulsate for 10 seconds after it had power.  As it was suppose to do (http://learn.adafruit.com/introducing-trinket/starting-the-bootloader).
Adafruit's Trinket


I finally was able to get the Trinket to work correctly by adding a powered USB hub to my desktop PC.  I assume that it may have been a power issue, but I am still uncertain. 

Here is the video: 

Saturday, December 21, 2013

Adafruit Trinket as an 'Enter' button

Industrial E-Stop Button

I am using Adafruit's Trinket to create a simple HID keyboard 'Enter' button.
I started by using the example sketch "TrinketKeyboardExample" and modifying it.

The button is actually an emergency stop button with a normally closed switch.






This is the original code "TrinketKeyboardExample":
 /*  
 TrinketKeyboard example  
 For Trinket by Adafruit Industries  
 */  
 #include <TrinketKeyboard.h>  
 #define PIN_BUTTON_CAPITAL_A 0  
 #define PIN_BUTTON_STRING  2  
 void setup()  
 {  
  // button pins as inputs  
  pinMode(PIN_BUTTON_CAPITAL_A, INPUT);  
  pinMode(PIN_BUTTON_STRING, INPUT);  
  // setting input pins to high means turning on internal pull-up resistors  
  digitalWrite(PIN_BUTTON_CAPITAL_A, HIGH);  
  digitalWrite(PIN_BUTTON_STRING, HIGH);  
  // remember, the buttons are active-low, they read LOW when they are not pressed  
  // start USB stuff  
  TrinketKeyboard.begin();  
 }  
 void loop()  
 {  
  TrinketKeyboard.poll();  
  // the poll function must be called at least once every 10 ms  
  // or cause a keystroke  
  // if it is not, then the computer may think that the device  
  // has stopped working, and give errors  
  if (digitalRead(PIN_BUTTON_CAPITAL_A) == LOW)  
  {  
   TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_A);  
   // this should type a capital A  
   TrinketKeyboard.pressKey(0, 0);  
   // this releases the key  
  }  
  if (digitalRead(PIN_BUTTON_STRING) == LOW)  
  {  
   // type out a string using the Print class  
   TrinketKeyboard.print("Hello World!");  
  }  
 }  

Here is my modified code:
 /*  
 TrinketKeyboard example  
 For Trinket by Adafruit Industries
 Modified by PlatinumFusion
 */  
 #include <Bounce.h>  
 #include <TrinketKeyboard.h>  
 //#define button0 0  
 #define PIN_BUTTON_STRING  2  
 Bounce button0 = Bounce(0, 10);  
 void setup()  
 {  
  // button pins as inputs  
  pinMode(0, INPUT_PULLUP);  
  // setting input pins to high means turning on internal pull-up resistors  
  digitalWrite(0, LOW);  
  // remember, the buttons are active-low, they read LOW when they are not pressed  
  // start USB stuff  
  TrinketKeyboard.begin();  
 }  
 void loop()  
 {  
  TrinketKeyboard.poll();  
  button0.update();  
  // the poll function must be called at least once every 10 ms  
  // or cause a keystroke  
  // if it is not, then the computer may think that the device  
  // has stopped working, and give errors  
  if (button0.risingEdge()) {  
   TrinketKeyboard.pressKey(0, KEYCODE_ENTER);  
   // this should be the 'Enter' key  
   TrinketKeyboard.pressKey(0, 0);  
  }  
 }  

 The button is attached to pin 0 and ground.

The completed project:
Testing the Button:


Monday, December 16, 2013

Bluetooth Relay Switch Cost

Here is a list of the items I used to create my bluetooth relay switch:

The total cost of this project comes to about $70, but keep in mind that this is the bare minimum material to create a remote relay with Bluetooth .  I used a breadboard, so you would need to find a box to put it all together and make it nice and neat.  Also, I used batteries to power the ATtiny, Bluetooth, and Relay Switch.
Check out the videos!