Show Posts
Pages: [1]
1  Using Arduino / General Electronics / When Android meet Arduino, what would happen? on: June 28, 2011, 04:09:16 am
There are something I want to say sorry.
1. I posted this topic on other page, then I find that it maybe in a wrong place, so I copy it to here. When I back to delete the original post, a reply was there in that few minutes, so I had no authority to remove the original topic. You can click the following link to see it. http://arduino.cc/forum/index.php/topic,65160.msg476148.html#msg476148
2. My English is really poor, because English is not our mother language. Hope it will be better in the future by our hard working.
3. Thanks the two friends below, your any kindly suggestions are greatly appreciated.

2  Using Arduino / Project Guidance / When Android meet Arduino, what would happen? on: June 28, 2011, 04:07:16 am
Google officially announced a new project called the Android Open Accessory toolkit. It allows people to connect an open source hardware interfaces like Arduino with Android system.
To make the communication between Android and Arduino easy, we would like show you a new way that Android interact with Arduino and other similar boards by Bluetooth and our APP.
I think many people will be interested in it, so I am glad to share with you. You can click the following link to see the whole process. You will like it. http://www.elecfreaks.com/829.html
3  Using Arduino / General Electronics / Communication between Android and Arduino with Bluetooth on: June 19, 2011, 10:03:03 am
We keep working on ADK(Android Open Accessory Development Kit) for weeks, and try to assemble some bata prototype and make a library for the communication between Android and Arduino with bluetooth.
To make the communication between Android and Arduino easy, we would like show you a new way that android interact with Arduino and other similar boards. Bluetooth for example.
Step one: Make a APP to Android which could communicate with other devices by bluetooth.
Step two: Android APP connect to Arduino by Bluetooth Bee.
For step one(Part1), we have just made a little APP for Android, achieve simple bluetooth connection with Android.

This APP allows Android connect to each other by bluetooth, so you need at least two Android devices for this demo. Here we used two Android phones which are SAMSUNG I7680 and Lenovo O3. Then, there should be a complete development environment like Eclipse on your PC. You can find many of them in the Internet.
I guess you all get ready, let’s see more details.

All of the Bluetooth APIs are available in the Android bluetooth package. Here is a summary of the classes you will need to create as below.
    BluetoothAdapter: Represents the local Bluetooth adapter (Bluetooth radio)
    BluetoothDevice: Represents a remote Bluetooth device, query information such as its name, address, class, and bonding state.
    BluetoothSocket: Represents the interface for a Bluetooth socket (similar to a TCP Socket).
    BluetoothServerSocket: Represents an open server socket that listens for incoming requests (similar to a TCP ServerSocket).
    BluetoothClass: Describes the general characteristics and capabilities of a Bluetooth device.[/list]

    Bluetooth Permissions
    In order to use Bluetooth features in your application, you need to declare at least one of two Bluetooth permissions: BLUETOOTH and BLUETOOTH_ADMIN.
    Declare the Bluetooth permission(s) in your application’s AndroidManifest.xml as below.

    Code:
    <manifest ... >
      <uses-permission android:name="android.permission.BLUETOOTH" />
      <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
      ...
    </manifest>

    Oh, Is it a little boring in front of this? OK, let us see some code, really start from here.
    In order to connect by bluetooth, there should be four steps as below:

       
      Setting Up Bluetooth
          Finding Device
          Connecting Device
          Managing Device(server/client)
    [/b]

    Setting Up Bluetooth

    We made the APP include six java files. For the Bata, we only need to use Activity01, DiscoveryActivity, ClientSocketActivity and ServerSocketActivity.
    Before your application can communicate with Bluetooth, you should verify Bluetooth is supported on the device and make sure that it is enabled. If Bluetooth is not supported, you should gracefully disable any Bluetooth features. If Bluetooth is supported, but disabled, you are able to request the user enable Bluetooth without leaving your application.
    So, at Activity01 we get five buttons, as below:

    Select “Open BT” button make the device’s own Bluetooth adapter (the Bluetooth radio) working. There is one Bluetooth adapter for the entire system, and your application can interact with it when it is open.

    Code:
    private BluetoothAdapter _bluetooth = BluetoothAdapter.getDefaultAdapter()

    There are two ways to enable bluetooth:

    Code:
        //Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        //startActivityForResult(enabler, REQUEST_ENABLE);

        //enable
        _bluetooth.enable();

    The frist way, create a new Intent as “Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)”, a dialog box will appear and request user permission to enable Bluetooth. Select “Yes” and the system will enable Bluetooth and focus will return to your application once the process completes (or fails). “Yes” returns RESULT_OK and “No” returns RESULT_CANCELED.

    The other way is force enable Bluetooth instead of dialog, we used this way here.
    Next, you need to ensure that Bluetooth is enabled and allowed other devices could discover it. Add the below code, and a dialog box will appear also, you should click “Yes”.

    Code:
    Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

        startActivityForResult(enabler, REQUEST_DISCOVERABLE);

    OK, Setting up device is completed. The code of this step as below:

    Code:
    ackage com.yarin.android.Examples_08_09;



    import android.app.Activity;

    import android.bluetooth.BluetoothAdapter;

    import android.content.Intent;

    import android.os.Bundle;

    import android.view.View;



    public class Activity01 extends Activity

    {

      /* Get Default Adapter */

      private BluetoothAdapter  _bluetooth        = BluetoothAdapter.getDefaultAdapter();



      /* request BT enable */

      private static final int  REQUEST_ENABLE      = 0x1;

      /* request BT discover */

      private static final int  REQUEST_DISCOVERABLE  = 0x2;



      /** Called when the activity is first created. */

      @Override

      public void onCreate(Bundle savedInstanceState)

      {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

      }



      /* Enable BT */

      public void onEnableButtonClicked(View view)

      {

        //Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

        //startActivityForResult(enabler, REQUEST_ENABLE);



        //enable

        _bluetooth.enable();



        Intent enabler = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

        startActivityForResult(enabler, REQUEST_DISCOVERABLE);

      }



      /* Close BT */

      public void onDisableButtonClicked(View view)

      {

        _bluetooth.disable();

      }



      /* Start search */

      public void onStartDiscoveryButtonClicked(View view)

      {

        Intent enabler = new Intent(this, DiscoveryActivity.class);

        startActivity(enabler);

      }



      /* Client */

      public void onOpenClientSocketButtonClicked(View view)

      {



        Intent enabler = new Intent(this, ClientSocketActivity.class);

        startActivity(enabler);

      }



      /* Server */

      public void onOpenServerSocketButtonClicked(View view)

      {



        Intent enabler = new Intent(this, ServerSocketActivity.class);

        startActivity(enabler);

      }



    }

    It's too long to post the whole article here. You can see the following three steps(Finding Device, Connecting Device, Managing Device(server/client))and download the full code in the original post here: Android + BlueTooth.
    4  Using Arduino / Programming Questions / Re: Arduino BT with Android on: June 19, 2011, 05:19:26 am
    Here is a post about the similar project you said. But there is only the part1. It may make progress in the soon future. You can see the part1 first for reference.
    http://www.elecfreaks.com/677.html

    5  Using Arduino / Project Guidance / Re: Arduino- bluetooth - Android - Html/php on: June 19, 2011, 05:08:18 am
    This post may help you something.
    http://www.elecfreaks.com/677.html
    6  Using Arduino / Project Guidance / nRF24L01 with Arduinio’s SPI Library on: June 11, 2011, 09:08:52 am
    I have reveived some mails for asking if we will provide the nRF24L01′s hardware SPI demo or library, which we just provide the softwore SPI way before ( http://arduino.cc/forum/index.php/topic,61720.msg446229.html#msg446229 ). So we modified the code used SPI library which you can import from Arduinos standard library.
    More information about the nRF24L01′s hardware SPI is here. http://www.elecfreaks.com/480.html

    Thanks and Regards,
    Leo
    7  Using Arduino / Project Guidance / 2.4G Wireless RF Module Demo for Arduino on: May 20, 2011, 04:41:44 am
    From: nRF24L01 Module Demo for Arduino | ElecFreaks

    For this you need two Arduino boards and two RF modules, one to transmit and the other to receive.

    The nRF24L01 module is worked at 1.9-3.6V voltage level, if you use standard Arduino board, you should use the Arduino board’s 3.3V pin(VDD3V3) to provide power for the nRF24L01 module. Please note, not use 5V pin(VDD5V) to provide power, which may destroy it.

    The Demo pins to Arduino as below:
    GND–GND, VCC–3.3V, CS–D8, CSN–D9, SCK–D10, MOSI–D11, MISO–D12, IRQ–D13


    Download the code below into the TX Arduino (transmit) — This code will drive the nRF24L01 module to send out data form 0×00 to 0xFF .

    Note, between the write TX_FIFO and clear RX_DR or TX_DS or MAX_RT interrupt flag, would better not serial print anything, which maybe case ACK failed.

    Code:
    void setup()
    {
      SPI_DIR = ( CE + SCK + CSN + MOSI);
      SPI_DIR &=~ ( IRQ + MISO);
      //  attachInterrupt(1, _ISR, LOW);// interrupt enable
      Serial.begin(9600);
      init_io();                        // Initialize IO port
      unsigned char status=SPI_Read(STATUS);
      Serial.print("status = ");
      Serial.println(status,HEX);      // read the mode’s status register, the default value should be ‘E’
      Serial.println("*******************TX_Mode Start****************************");
      TX_Mode();                       // set TX mode
    }
    void loop()
    {
      int k = 0;
      for(;;)
      {
        for(int i=0; i<32; i++)
            tx_buf[i] = k++;
        unsigned char status = SPI_Read(STATUS);           // read register STATUS's value
        if(status&TX_DS)                                        // if receive data ready (TX_DS) interrupt
        {
          SPI_RW_Reg(FLUSH_TX,0);
          SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);    // write playload to TX_FIFO
        }
        if(status&MAX_RT)                           // this is retransmit than  SETUP_RETR
        {
          SPI_RW_Reg(FLUSH_TX,0);
          SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);     // disable standy-mode
        }
        SPI_RW_Reg(WRITE_REG+STATUS,status);  // clear RX_DR or TX_DS or MAX_RT interrupt flag
        delay(1000);
      }
    }

    Download the code below into the RX Arduino (receive) – This code will drive the nFR24L01 module to receive the data that transmit form the TX module and print it to serial port.

    Note, clear RX_FIFO must bellow Read_FIFO

    Code:
    void setup()
    {
      SPI_DIR = ( CE + SCK + CSN + MOSI);
      SPI_DIR &=~ ( IRQ + MISO);
      //  attachInterrupt(1, _ISR, LOW); // interrupt enable
      Serial.begin(9600);
      init_io();                        // Initialize IO port
      unsigned char status=SPI_Read(STATUS);
      Serial.print("status = ");
      Serial.println(status,HEX);  // read the mode’s status register, the default value should be ‘E’
      Serial.println("*****************RX_Mode start******************************R");
      RX_Mode();                        // set RX mode
    }
    void loop()
    {
      for(;;)
      {
        unsigned char status = SPI_Read(STATUS);                // read register STATUS's value
        if(status&RX_DR)                                        // if receive data ready (TX_DS) interrupt
        {
          SPI_Read_Buf(RD_RX_PLOAD, rx_buf, TX_PLOAD_WIDTH);    // read playload to rx_buf
          SPI_RW_Reg(FLUSH_RX,0);                               // clear RX_FIFO
          for(int i=0; i<32; i++)
          {
              Serial.print(" ");
              Serial.print(rx_buf[i],HEX);                      // print rx_buf
          }
          Serial.println(" ");
        }
        SPI_RW_Reg(WRITE_REG+STATUS,status);  // clear RX_DR or TX_DS or MAX_RT interrupt flag
        delay(1000);
      }
    }

    Now power on both Arduino , and connect the RX one to PC via USB. Open the IDE serial port monitor , change the baud rate to 9600 bps , and you can see the data that received.

    More informations about RF module: nRF24L01 Module Demo for Arduino | ElecFreaks
    Pages: [1]