BlackBerry, BlackBerry OS 7.1 mobile phone through the Bluetooth serial port to read Arduino Bluetooth transmission of temperature and humidity information

Source: Internet
Author: User
Tags uuid

Target: BlackBerry mobile phone via Bluetooth serial read Arduino Bluetooth transmission of temperature and humidity information

Hardware: Arduino motherboard + DHT11 temperature and humidity sensor + Bluetooth module, development tools C language

Mobile: BlackBerry 9360 Mobile, OS 7.1, development tools Java

Mobile: BlackBerry Alpha Mobile, OS 10.0.xxx, development tools BlackBerry NDK

Communication: Mobile and Arduino via Bluetooth connection




BlackBerry 9360 on the top of the display: Humidity 41, temperature 11 (ha ... .....) )


Arduino Code reference here Http://playground.arduino.cc/Main/DHTLib

The code is as follows:

 
//   FILE:  dht_test.pde
//PURPOSE:DHT Library test sketch for Arduino
//

#include <dht.h >

DHT DHT;

#define Dht11_pin 8
#define DHT22_PIN 5

void Setup ()
{
  serial.begin (9600);
  Serial.println ("DHT TEST program");
  Serial.print ("LIBRARY VERSION:");
  Serial.println (dht_lib_version);
  Serial.println ();
  Serial.println ("type,\tstatus,\thumidity (%), \ttemperature (C)");
}

void Loop ()
{
  //READ DATA
  int chk;
 
  READ DATA
  serial.print ("DHT11, T");
  CHK = Dht.read11 (dht11_pin);
  Switch (CHK)
  {case
    DHTLIB_OK:  
		serial.print ("ok,\t"); 
		break;
    Case Dhtlib_error_checksum: 
		serial.print ("CHECKSUM error,\t"); 
		break;
    Case Dhtlib_error_timeout: 
		serial.print ("Time Out error,\t"); 
		break;
    Default: 
		serial.print ("Unknown error,\t"); 
		break;
 Displat DATA
  serial.print (dht.humidity,1);
  Serial.print (", T");
  Serial.println (dht.temperature,1);

  Delay (1000);
}
//end of FILE
//



BlackBerry OS 7.1

The BlackBerry Java API encapsulates serial communication, so it's convenient to use.

Development Tools EJDE Import sample program Bluetoothserialportdemo, modify the code to receive Bluetooth data and display in the text box.

                        Read in the contents and get the event lock for this
                        //application So we can update the info field.
                    	Util.log ("Read bluetooth data ...");
                    	int i = 0;
                    	while (true) {
                    		i++;
                            String cmd = "";
                            byte B;
                            while (((b = _din.readbyte ()) > 0) && ((char) b!= ((char) 0x0a)) {
                            	cmd = cmd + (char) b;
                            } 
                            
                            Util.log ("Received" + cmd);
                            _infofield.settext (i + ":" + cmd);
                        }
                      

Note:

In Arduino, Serial.println () came out of the data is 0x0d, 0x0a. In Java, I only detect carriage return character (char) 0x0a as a separator for a single piece of data

BlackBerry OS 10

The BlackBerry NDK C + + API encapsulates the Bluetooth SPP API and is slightly more complex (similar to the Android API) when connecting Bluetooth devices, the Bt_spp_open () method requires the service Uuid,mac address of the other.

Download BlackBerry Bluetooth example code bluetoothsppchat, import into NDK, build, run.

Note the definition of the UUID in which:

#define SPP_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB"

//! [7]
void Chatmanager::connecttosppservice ()
{
    m_chathistory.clear ();

    const int FD = Bt_spp_open (M_remoteaddress.toascii (). Data (), (char *) Spp_service_uuid, false);

    if (FD >= 0) {
        updatechatwindow ("SPP client\n\n");

        Setsppclient (FD);
    } else {
        ShowDialog ("Spp_open fail", "errno =" + Qstring::number (errno));
    }
//! [7]
BB 10 operating effect as shown



Reference:

Bluetooth Serial service UUID ' {00001101-0000-1000-8000-00805F9B34FB} '

Https://bluetooth.org/Technical/AssignedNumbers/service_discovery.htm
http://www.douban.com/group/topic/20009323/

Http://www.cnblogs.com/lyout/archive/2011/04/11/2012175.html


BlackBerry NDK Bluetooth API
Http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bluetooth/topic/manual/btspp.h_functions_overview.html


BlackBerry NDK Bluetooth Example (Bluetooth SPP Chat Example) description
Http://blackberry.github.com/Cascades-Samples/bluetoothsppchat.html


BlackBerry NDK example code (including Bluetooth) download
https://github.com/blackberry/Cascades-Samples/

Android phone and Arduino Bluetooth communication example Data transfer between Android and Arduino via Bluetooth
http://english.cxem.net/arduino/arduino5.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.