src:
http://forum.arduino.cc/index.php/topic,44030.0.html
http://playground.arduino.cc/Main/MsTimer2
notes:
------------
// Uptime counter
#include <MsTimer2.h>
volatile unsigned long _Uptime =0;
void updateuptime() {
_Uptime++;
}
unsigned long getUpTime()
{
unsigned long ret;
// optional: disable interrupts
cli();
ret = _Uptime;
// optional: enable interrupts
sei();
return ret;
}
void setup() {
MsTimer2::set(1000, updateuptime);
MsTimer2::start();
}
void loop() {
// call getUpTime here.
}
2014年4月14日 星期一
2014年4月10日 星期四
Android + Arduino Data Transfer via BT
src:
http://stackoverflow.com/questions/10327506/android-arduino-bluetooth-data-transfer
notes:
----
http://stackoverflow.com/questions/10327506/android-arduino-bluetooth-data-transfer
notes:
----
I can get my Android app to connect via Bluetooth to my Arduino. However no data can be transmitted between them. Below is my setup and code:
HTC Android v2.2, Bluetooth mate gold modem, Arduino Mega (ATmega1280)
Android Java code:
Arduino Code:
I've tried using 115200 and 9600 for the baud rates, and I've tried setting the bluetooth rx and tx pins as input/output and output/input. The Arduino is receiving serial data from the PC but can't send it to the Android (I can see this because of the flashLED() method).
The Android can't send any data at all to the Arduino. However they are both connected because the green light on the modem turns on and goes off and the red led flashes when I close the connection. The sendData() method doesn't throw an exception because otherwise showMessage("SEND FAILED"); would appear.
I also have this in my manifest .xml
Any help would be greatly appreciated!
Code taken from:
| |||||||||
|
Just solved the problem for anyone else who came across this page.
Seems that my Arduino doesn't like me using digital pins for serial communication, I use TX and RX instead with this code taken from http://jondontdoit.blogspot.com.au/2011/11/bluetooth-mate-tutorial.html, also seems that 9600 is a good baud instead of 115200.
| |||
| add comment |
I was getting the same thing. I went into 'Settings'->'Wireless and Networks'->'Bluetooth Settings' and paired the device. When I went back and re-ran my code, it connected, no exception. I put controls in my UI for displaying the paired devices, I'm going to see if I can code to manage pairing devices from my UI.
| ||||
| add comment |
I think it might be some fault in Bluetooth.. its better to re-install its drivers.. as the code given above looks correct.
| |||
| add comment |
I was able to get this to run only after replacing this section:
with this:
where I entered the address of my Bluetooth device. The original code finds the device and returns the correct address, but mmSocket.connect(); generates an exception "java.io.IOException: Service discovery failed"
Suggestions?
| |||||
For anyone who finds this page, but is stuck using a hardcoded mac address as above, set mac address to NULL, and insert this code into OnResume()
ALSO, don't forget to allow eclipse to include necessary libraries, and place your mac address into mac.txt on the root of the SD Card, then you can simply give users a text file with their mac address while still allowing the app to be downloaded from the market without customizing every instance.
|
訂閱:
文章 (Atom)