I've been trying to use this serial for android library now, but I can't make it work. I'm trying to run this little program in android:
// MouseLib.ino
#include "tracker.h"
PositionTracker tracker(6,5);
void setup() {
Serial.begin(115200);
tracker.init();
}
void loop() {
Serial.println("?");
delay(20);
}
Where the tracker is as follows:
#include "Arduino.h"
#include "ps2.h"
#include "tracker.h"
PositionTracker::PositionTracker(int _clkPin, int _dPin){
// x = y = ldX = ldY = lX = lY = 0;
clkPin = _clkPin;
dPin = _dPin;
sensor = new PS2(_clkPin, _dPin);
}
void PositionTracker::init(){
sensor->write(0xff); // reset
sensor->read(); // ack byte
sensor->read(); // blank */
sensor->read(); // blank */
sensor->write(0xf0); // remote mode
sensor->read(); // ack
delayMicroseconds(100);
}
The code works fine when I plug Arduino to pc, but when i plug it in an Android device it just doesn't work. If I comment the "tracker.init()" line, it works fine for Android. If I use the example from ps2 library, it works fine as well. Oh, and I'm using the sample app for the serial library on a Moto G. Any ideas?
Links for the libraries:
- USB Serial for Android: https://code.google.com/p/usb-serial-for-android/
- ps2.h(mouse communication): http://playground.arduino.cc/ComponentLib/Ps2mouse
EDIT
Right after posting this, I've found the issue: I was looking at the wrong website for the library. The answer was posted on their wiki already.
From the library's wiki (can't post the link, as I'm low on reputation):
Some Arduinos use the DTR line to determine serial channel readiness. In your Android code, call
setDTR(true);