While implementing SensorGraph example from Amarino Toolkit, the onRecieve method from ArduinoReciever class does not get called. It seems like the BT device works properly, so I'm guessing there's a problem in arduino code. I am using Galaxy S1 device for the SensorGraph app example,and HR-SC04 proximity sensor(tested and working) to get distance.
BT->Logic Lever Converter->Arduino
RXD->LV3->HV3->Tx
TXD->LV4->HV4->Rx
GND->GND
VCC-> 3.3v
private static final String DEVICE_ADDRESS = "20:14:05:05:24:49"; //HC-06 device number
private GraphView mGraph;
private TextView mValueTV;
private ArduinoReceiver arduinoReceiver = new ArduinoReceiver();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get handles to Views defined in our layout file
mGraph = (GraphView)findViewById(R.id.graph);
mValueTV = (TextView) findViewById(R.id.value);
mGraph.setMaxValue(1024);
}
@Override
protected void onStart() {
super.onStart();
// in order to receive broadcasted intents we need to register our receiver
registerReceiver(arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));
// this is how you tell Amarino to connect to a specific BT device from within your own code
Amarino.connect(this, DEVICE_ADDRESS);
}
#include <MeetAndroid.h>
#define echoPin 12
#define trigPin 13
/*
Sends sensor data to Android
(needs SensorGraph and Amarino app installed and running on Android)
*/
MeetAndroid meetAndroid;
long duration, distance;
void setup() {
Serial.begin (57600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
meetAndroid.receive();
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
meetAndroid.send(analogRead(distance));
Serial.print(distance);
Serial.println(" cm");
delay(100);
}
I would appreciate if you could find where the problem lies. Thanks in advance!