Showing posts with label app inventor. Show all posts
Showing posts with label app inventor. Show all posts

Thursday, August 13, 2015

Garage Project Update

I completed this a couple months ago. I just didn't get to posting it. Check out the other posting if you want to know what this is updating.  Of course, I updated the GUI, so it isn't just "Big Door", "Little Door" and made the app a little more robust. It remembers the last Bluetooth device, so pairing is a little more automatic. The change to the GUI allows users to click on the door they want open, and it opens. Someday, I may put in sensors so the GUI could show the current state of the doors (so when I go to bed, I can look, and know if I left any doors open). The app inventor project is at this link.



 I re-did the wiring in the garage as well. I used to have a spiderweb in the ceiling with droopy wires from the access door to the openers. Who ever installed the openers or the wiring must have run out of staples, and there were like 3 for the two openers. Now all the wiring goes through the attic, with the central wiring on a barrier strip.

The sketch I didn't change, but I noticed I didn't upload that either. I'll give that a go as well. The sketch isn't doing anything really complex. It is still based on ardudroid.


/*
 PROJECT: Garage 
 PROGRAMMER: T Brusehaver
 DATE: May 31, 2015
 FILE: garage.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("Garage By T. Brusehaver (2015)");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value
  
  Serial.print("Ard_command ");
  Serial.print(ard_command);
  Serial.print("  Pin=");
  Serial.print(pin_num);
  Serial.print("  Val=");
  Serial.println(pin_value);

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = "); 
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    //digitalWrite(8, pin_value);
    // add your code here 
    digitalWrite(8, HIGH);   // sets the LED on
    delay(1000);                  // waits for a second
    digitalWrite(8, LOW);    // sets the LED off
    break;
  case 7:
    pinMode(7, OUTPUT);
    //digitalWrite(7, pin_value);         
    // add your code here 
    digitalWrite(7, HIGH);   // sets the LED on
    delay(1000);                  // waits for a second
    digitalWrite(7, LOW);    // sets the LED off
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}

The relays are connected to the Arduino using an NPN transistor. One relay each on pins 7 and 8. The power supply is my old Motorola Razr charger (mini USB). The HC05 is connected using the TX and RX serial pins, so they need to be disconnected if connecting to the USB port to program the Arduino. Also Have a look at the Ardudriod page for the resistors and 3.3V connection. (Don't try 5V and don't forget the resistor on the RX pin). Remember the module is receiving on RX but sending to the TX pin.

There have been a few things I don't like about it, but overall it is serving it's purpose. Pairing basic HC05 modules with and Arduino isn't as quick or automatic as I'd like it to be. Of course, sometimes the signal is going through an aluminium door on the way to the module, so I can't blame anything but circumstances.

If you are thinking of trying this yourself, I recommend it. If nothing else, this is a good place to start.



Sunday, May 31, 2015

More Garage Stuff

I was once distracted by a silly garage project. Then I moved, and now I have another garage project. This one is similar to the Engine Monitor I keep promising to build. Heck this whole project is about me learning, and sharing those lessons so others may benefit from them.


I have a house with a 3 car garage. It isn't huge, there are two doors, one small, and one large. I know on the large side we can't put our two cars in, and open the car doors. There are still two doors, each with their own openers. The remote controls in the cars work great, but you need two, if you want to open both doors. Yes, I know they sell learning controls that will open both, but what about when you just want to open the door when not in the car? I have tools and such in the garage, and sometimes I need something, and the car may be in the garage.

I always have my phone in my pocket. Is there a way to have the phone talk to the opener? Not the stock openers, only a special opener. Well I have a bunch of Arduino stuff, and a phone that talks bluetooth, can they be connected? Well, sure they can. Again I experimented using the ArduDroid an Arduino Mega and a Bluetooth shield. Nothing to it, that all worked great. Then I moved on to a 6 pin HC-05 module and the mega, and that worked as well. The HC-05 isn't any bigger than a Arduino Nano, so I tried that. That worked as well.

Once I had all the Arduino hardware working, it was time to do something quick with the Android. The ArduDriod has an OK interface, but I wanted something that looked like it belong. I didn't want to do a full blown app, so I looked at my options. I ended up choosing App Inventor. It is probably as much work as writing an app, since I had a lot to learn, but I was able to learn the app inventor and as a result I have an app that will open and close the garage.


There are 3 buttons and a label. The buttons cause the relay corresponding to the door labeled to close for about a second. I have the project available if anyone would want it. It was done using app inventor 2. The protocol stillis the ArduDroid protocol, so I had a sketch I could start with.

If you want to try it, let me know, I'll share what I have.



Saturday, February 16, 2013

Open Pilot has the Answer

I found some videos from the open pilot group who have their code ported to the STM Discovery F3 board. There is a Quad Copter flying using one. There is a demo showing stuff on the screen. Progress is happening.

I was thinking, if I just use the existing open pilot stuff, then I only have to get the code working on the Android, so I only have to do half the work. Then I don't have to come up with a communication protocol either, since open pilot already has one. Hack a Day of course came to the rescue yesterday also. There is a link to using App Inventor to connect an Android to an Arduino. It seems to make everything easier.

I was thinking, I don't have an Android SDK on Linux, but I mostly use Linux for surfing and developing, it might be time to get it. Yesterday the Android Central podcast suggested getting the SDK has gotten even easier recently. I'll give it a shot and let you know. It is also supposed to be easier to develop on. The Linux ADT bundle is about 400MB zipped, not too bad. The instructions seem reasonable, unzip and run. Maybe when I get done with this post, I try it.

Looks like I'll have some experiences that I've been through be broadcast on Airplane Geeks podcast this week.  That will be fun, talking about my mentors, and opportunities I have given other folks. It was a little more challenging than I thought, trying to stay coherent reading the text. It might be something I'll look into in the future.