I'm so new to ADK programming, any comment or suggestion is really appreciated.
What i want to do is to make Mega ADK (+Ethernet shield) can get IP address from DHCP server controlling by Android device in accessory mode.
So firstly i find relating sample source code that closest to my requirement, what i chose are;
DemoKit
DHCPChatServer
Each of them works very well when I try execute it individually but doesn't work when i integraged them together.
My problem is : "After AndroidAccessory "powerOn" is executed, getting IP via DHCP function will no longer work."
Here is some part of my code
void setup_ethernet(){
// start the Ethernet connection:
Serial.println("Trying to get an IP address using DHCP");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
// print your local IP address:
Serial.print("My IP address: ");
ip = Ethernet.localIP();
Serial.println(ip);
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 54321)) {
Serial.println("connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("\r\nStart");
init_leds();
init_relays();
init_buttons();
//init_joystick( 5 );
// autocalibrate OFF
touch_robot.set_CS_AutocaL_Millis(0xFFFFFFFF);
servos[0].attach(SERVO1);
servos[0].write(90);
servos[1].attach(SERVO2);
servos[1].write(90);
servos[2].attach(SERVO3);
servos[2].write(90);
b1 = digitalRead(BUTTON1);
b2 = digitalRead(BUTTON2);
b3 = digitalRead(BUTTON3);
b4 = digitalRead(JOY_SWITCH);
c = 0;
acc.powerOn();
//setup ethernet using DHCP
setup_ethernet();
}
void loop()
{
.....
}
Anyone has idea? how can i get rid of this problem?.
Thank you in advance for your help
One more thing, according to the source code above what i noticed is that after acc.powerOn() is executed,
Ethernet module that use spi interface becomes not working even i rewrite a program that used to work perfectly on it. (like arduino sample code - DHCPChatServer)
This is extremely weired. To resolve this issue i have to install Arduino IDE in other PC and write dummy program on it to clear memory then switch back and write my program again.
Ethernet shield and the ADK's USB Host use the same SPI pins;
50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS)
Not correct: The Ethernet Shield uses pin 10 for SS and not pin 53. The question is: does the DemoKit correctly set the SS line for the USB host interface?
For SS pin of USB host interface issue, it was programmatically set by Max3421e libarary,
which you may see it in /libraries/USB_Host_Shield/Max3421e_constants.h
That forum thread is about the Arduino Ethernet Shield. There the SCLK, MISO and MOSI signals are used only from the ICSP header in newer revisions to be compatible with UNO and MEGA2560. The SS is always on pin 10, the Ethernet library expects it there and only there. So connect your ethernet module's SS pin to pin 10 and it will probably work.
The MAX3421e uses the signal of pin 53 but it's internally connected.
ฺฺBy this change, i can use ethernet with no problem but......
when it comes to integrate with ADK USB Host, it will no longer work.
So i follow your suggestion by changing it back and also apply SS to pin 10 instead of 53 as below.