android and arduino controlling a 4 wheel robot

Hello guys

I started to play with connecting arduino adk and android and succeed in a couple of examples with leds
assuming that the android apk works perfect, the arduino code should run Motor1 and Motor2 forward if the android phone is connected, but it doesn’t :slight_smile: any suggestions? I checked this example but it does not work to compile…

#include <Wire.h>             
#include <Max3421e.h>          
#include <Usb.h>               
#include <CapSense.h>
#include <AndroidAccessory.h>
#include <Servo.h> 

AndroidAccessory acc("4wheel",           
		     "4wheel_ADK",                	
		     "Demo of 4wheel ADK", 		
		     "1.0",                    		
		     "http://www.android.com", 		
		     "0000000012345678");

int E1 = 6;  //Motor 1 PWM control
int M1 = 7;  //Motor 1 Direction control 
int E2 = 5;  //Motor 2 PWM control 
int M2 = 4;  //Motor 2 Direction contro 

void setup();	// Run the initial setup on the board
void loop();	// Loop and check for IO 

void Motor1(int pwm, boolean reverse)
  {
    Serial.print("\r\n Motor1 RAN");
    analogWrite(E1,pwm);
      if(reverse) { digitalWrite(M1,HIGH); } 
      else { digitalWrite(M1,LOW); } }
void Motor2(int pwm, boolean reverse)
  { 
    Serial.print("\r\n Motor2 RAN");
    analogWrite(E2, pwm);
      if(reverse) { digitalWrite(M2,HIGH); }
      else { digitalWrite(M2,LOW); }
      }

void setup()
{
	Serial.begin(115200);
	Serial.print("\r\nStart - Setup ran");
        int i; 
        for(i=5;i<=8;i++)
        pinMode(i, OUTPUT);
	Serial.print("\r\nStart - accessory power on");
}
void loop()  
	byte err;
	byte idle;
	static byte count = 0;
	byte msg[3];
        long touchcount;

	if (acc.isConnected()) {			    			
		Serial.print("\r\nStart - accessory connected");  	                  
		int i;
                    int x,delay_en;
                    Motor1(250,true);
                    Motor2(250,true);
	}  else {
                    Motor1(0,true);
                    Motor2(0,true);
                    Serial.print("\r\nStart - accessory not connected");
}
delay(10);
}

You've told us what it doesn't do, but there's a lot of debug printing in there, so why not tell us what it does do?

it prints on COM :

Motor1 Start - Setup ran Start - accessory power on Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN Start - accessory not connected Motor1 RAN Motor2 RAN

Just use ArduinoCommander (https://market.android.com/details?id=name.antonsmirnov.android.arduinocommander) and StandardFirmata sketch