Сегодня наткнулся на проект Arduino+Android:
www.amarino-toolkit.net.
Состоит из приложения
Amarino для Android и библиотеки
MeetAndroid, которую надо подключать к скетчу в Arduino. Пока предполагается, что связь будет устанавливаться с ArduinoBT или с обычным Arduino через bluetooth-шилд, поэтому сами понимаете, насколько сужается диапазон применения проекта.
Общий смысл -
унификация взаимодействия с подключаемыми к Arduino схемами. В приложении Amarino надо задать события и получаемые от скетча сообщения. В самом скетче надо унаследоваться от класса
MeetAndroid ( в свою очередь, он унаследован от класса
Print и немного расширяет его функции, работая через
Serial ). Дальше пишите callback-функцию опроса устройства и регистрируете ее в экземпляре MeetAndroid. Это дает возможность Amarino асинхронно
дергатьопрашивать через Arduino схему и получать данные (в основном, числа). Например:
#include <meetandroid.h>
// you can define your own error function to catch messages
// where not fuction has been attached for
MeetAndroid meetAndroid(error);
void error(uint8_t flag, uint8_t values){
Serial.print("ERROR: ");
Serial.print(flag);
}
int onboardLed = 13;
void setup()
{
// use the baud rate your bluetooth module is configured to
// not all baud rates are working well, i.e. ATMEGA168 works best with 57600
Serial.begin(57600);
// register callback functions, which will be called when an associated event occurs.
// - the first parameter is the name of your function (see below)
// - match the second parameter ('A', 'B', 'a', etc...) with the flag on your Android application
meetAndroid.registerFunction(compass, 'F');
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop()
{
meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
/*
* This method is called constantly.
* Compass events are sent several times a second.
*
* note: flag is in this case 'F' and numOfValues is 1
* since compass event sends exactly one single int value for heading
*/
void compass(byte flag, byte numOfValues)
{
// we use getInt(), since we know only data between 0 and 360 will be sent
int heading = meetAndroid.getInt();
flushLed(heading); // silly, you should have better ideas
}
void flushLed(int time)
{
digitalWrite(onboardLed, LOW);
delay(time);
digitalWrite(onboardLed, HIGH);
}
Здесь определяется функция
compass, которая получает от Android целое число и зажигает светодиод L на соответствующее ему число миллисекунд.
Можно также отправлять
непрерывные потоки данных - видимо, для построения графиков.
Проект находится в зачаточном состоянии,
поддерживает 1.5 и 1.6 версии платформы Android, а вот 2.0 - нет, но она на подходе. Все исходники, естественно, доступны. Думаю, порадует фанов Arduino и Android - я пока что гуглофоном не обзавелся, увы :( А пока - пожелаю ему всяческих успехов!