Pages: [1]   Go Down
Author Topic: Flag not registered  (Read 1260 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! all, first of all i want to apologize to my previous post and im new to this arduino stuff. So excuse me for, i may not be able to explain my problem clearly. im using arduino mega 2560, BlueSMiRF Gold, Galaxy mini (2.3.4), installed amarino 1.0 and the amarino plugin bundle.

the code below is to send an integer from arduino to the phone using Bluetooth by linking the program to use the amarino library. But when i press the send button it receives `Flag not registered`. I want to send integer 1 whenever the send button is pressed.
Please good sir, im at my wits end.

can anyone check my code and point me where in the code is wrong and what i should do to make it work.

Over here is the code for the android phone
Code:

package com.android.bluetoothtry;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import at.abraxas.amarino.Amarino;
import at.abraxas.amarino.AmarinoIntent;

public class MainActivity extends Activity implements OnClickListener {

private static final String DEVICE_ADDRESS = "00:06:66:08:16:AD";
private static final char ARDUINO_FLAG = 'a';

private Button _buttonConnect;
private Button _buttonSend;
private Button _buttonDisconnect;

private BroadcastReceiver _arduinoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int type = intent.getIntExtra(AmarinoIntent.EXTRA_DATA_TYPE, -1);

if(type == AmarinoIntent.STRING_EXTRA) {
String value = intent.getStringExtra(AmarinoIntent.EXTRA_DATA);
Toast.makeText(MainActivity.this, value, Toast.LENGTH_SHORT).show();
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

registerReceiver(_arduinoReceiver, new IntentFilter(AmarinoIntent.ACTION_RECEIVED));

/*
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String address = intent.getStringExtra(AmarinoIntent.EXTRA_DEVICE_ADDRESS);

Toast.makeText(MainActivity.this, "Device Connected " + address, Toast.LENGTH_SHORT).show();
}
}, new IntentFilter(AmarinoIntent.ACTION_CONNECTED));
*/

_buttonConnect = (Button) findViewById(R.id.buttonConnect);
_buttonSend = (Button) findViewById(R.id.buttonSend);
_buttonDisconnect = (Button) findViewById(R.id.buttonDisconnect);

_buttonConnect.setOnClickListener(this);
_buttonSend.setOnClickListener(this);
_buttonDisconnect.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonConnect:
connect();
break;
case R.id.buttonSend:
send();
break;
case R.id.buttonDisconnect:
disconnect();
break;
default:
break;
}
}

private void disconnect() {
Amarino.disconnect(this, DEVICE_ADDRESS);
}

private void send() {
int data = 1;
Amarino.sendDataToArduino(this, DEVICE_ADDRESS, ARDUINO_FLAG, data);
}

private void connect() {
Amarino.connect(this, DEVICE_ADDRESS);
}
}



And over here is the code for arduino
Code:
#include <MeetAndroid.h>

MeetAndroid meetAndroid;

int ledPin = 13;

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode (8, INPUT);
 
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
 
  meetAndroid.registerFunction(show, 'A');
}

void show(byte flag, byte numOfValues) {
  delay(500);
}

void loop() {
  meetAndroid.receive();
  if (digitalRead (8) == 1) {
    digitalWrite (ledPin, HIGH);
    delay (2000);
    digitalWrite (ledPin, LOW);
    meetAndroid.send ("1");
  }
}

 

Please help good sir..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (digitalRead (8) == 1) {
Tell me about how pin 8 is wired.

(And please, cut the "sir" crap)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can you scarp that. it was supposed to be connected to a switch.

now the code looks like this.
Code:
void loop() {
  meetAndroid.receive();
 // if (digitalRead (8) == 1) {
 //   digitalWrite (ledPin, HIGH);
 //  delay (2000);
//    digitalWrite (ledPin, LOW);
    meetAndroid.send ("1");
 // }
}


now it can send 1 but it just keeps sending 1. without pressing the send button...
can you teach me what should i do? because of the deadline cant think straight right now.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
now it can send 1 but it just keeps sending 1. without pressing the send button...
That's because the code is in a function called "loop()".
If you want it just once, put all the code in "setup()" and leave "loop()" blank.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i did but it will not send so i tried putting it in my show function
 and it just keeps sending 1 without pressing the send button. can you help
Code:
#include <MeetAndroid.h>

MeetAndroid meetAndroid;

int ledPin = 13;

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode (8, INPUT);
 
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
 
  meetAndroid.registerFunction(show, 'A');
   
}

void show(byte flag, byte numOfValues) {
  delay(500);
 
 
  meetAndroid.send ("1");
}

void loop() {
  meetAndroid.receive();
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and it just keeps sending 1 without pressing the send button.
What send button are you talking about?

What is attached to pin 8?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i remove the function in pin 8. it was supposed to be attach to switch.. the send button i was talking about is the GUI in android
Logged

Pages: [1]   Go Up
Jump to: