Monday, July 8, 2013

I am doing a crummy job...

I am not keeping up with this, I am not documenting what works and what doesn't, and I just ignore all the readers.

Sorry

I'll be very humble in this post. Lots has changed. I bought a new desktop computer. This thing seems really good. It has two USB ports in the front of it, so I think that will help with things. Certainly the arduino plugs in nicely. I have the tablet, and a new phone. They are both Samsung Android devices. This is good, they both share nicely, so I can probably have some success.

Looking back, and trying to get things where I was, well, I am not having any luck.  I reinstalled the Arduino IDE, and looking back at my notes, I guess I missed some setups. The IDE won't let me talk to the board. The driver says successfully installed, but everytime I plug in, I get uh-ah sound from windows. This is Windows7, and I am following the instructions on the Arduino install page.

It seems the Arduino page isn't up to snuff. I went right to the FTDI page for the instructions on how to install the Windows 7 x64 device drivers (I don't think the 64 bit Intel drivers are included with Arduino at this time).  Yes, the instructions appear to make you do the same update driver twice, but yes you need to!

Even wanting to go back to where I was, I don't find any of my software, although it is probably on my old computer. How could you have duplicated, or improved my work? I need to do better than that. I am trying to be more open, and I hope you can understand.

This time the board is a Mega128, and the board is on Com3.  I was able to test this by trying the "Burn Bootloader" option in the tools menu of the IDE and watching the Rx/Tx LEDs blink.

I may go back in grab all the files off that old computer, and then try again, or I may start from scratch?

There seems to be a new Arduino to Android project on Hackaday again. It is using bluetooth, so I will give it a go.

I'll try to keep motivated, and put up code this time.

The Bluetooth device is called linvor 00:11:04:15:10:87, and the login is 1234.  I believe the bluetooth shield is still on 9600 baud.  I keep getting the error:

   avrdude: stk500_getsync(): not in sync: resp=0x00

with the shields on. With the shields off, it works fine. Maybe I need to turn off the bluetooth shield while I am uploading code? There is a switch, one side labeled "to board" the other labeled "to ft232". I can upload the code, with the switch on the "to ft232" side, and get no errors. I can also get serial data from the board to my phone using the serial monitor, without changing the switch. I don't receive anything from the phone though.

This is the code that is included from the Arduino to Android project


/*
 PROJECT: Andruino 0.1 Alpha
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: July1, 2013
 FILE: Andruino.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_ARDUINO 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("Andruino 0.1 Alpha by TechBitar (2013).");
  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

  // 1) GET TEXT COMMAND FROM ANDRUINO
  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 ANDRUINO
  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 ANDRUINO
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ANDRUINO
  if (ard_command == CMD_READ_ARDUINO) { 
    // 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 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    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
  } 
}






To do more testing, I probably need to add some LED's or something.

That is all for tonight, it is getting late.




tom

No comments:

Post a Comment