BlackBerry 10 , BlackBerry OS 7.1 手机通过蓝牙串口读取Arduino 蓝牙传过来的温度 湿度信息
2013-01-12 18:18
495 查看
目标:BlackBerry手机通过蓝牙串口读取Arduino 蓝牙传过来的温度 湿度信息
硬件:Arduino主板 + DHT11温湿度传感器 + 蓝牙模块,开发工具C语言
手机:BlackBerry 9360手机,OS 7.1,开发工具Java
手机:BlackBerry 10 Alpha手机,OS 10.0.xxx,开发工具BlackBerry 10 NDK
通讯:手机和Arduino通过蓝牙连接
BlackBerry 9360手机上面的显示:湿度41,温度11(哈冷啊。。。。。。。。。。。。。。。。)
Arduino代码参考这里 http://playground.arduino.cc/Main/DHTLib
代码如下:
//
// 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
BlackBerry Java API封装了串口通讯,所以用起来就很方便了。
开发工具eJDE中导入sample程序BluetoothSerialPortDemo ,修改代码接收蓝牙数据并显示在文本框中。
// 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);
}
注:
Arduino中,Serial.println() 出来的数据是0x0d, 0x0a。在Java中,我只检测回车字符 (char)0x0a作为一条数据的分隔符即可
BlackBerry OS 10
BlackBerry NDK C/C++ API封装了蓝牙SPP API,用起来稍微复杂一点(和Android API类似),连接蓝牙设备的时候,bt_spp_open()方法需要对方的服务UUID,mac地址。
下载BlackBerry 蓝牙例子代码bluetoothsppchat,导入到NDK中,build,运行即可。
注意其中的UUID的定义:
#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运行效果如图
参考:
蓝牙串口服务 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 10 NDK Bluetooth API http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bluetooth/topic/manual/btspp.h_functions_overview.html
BlackBerry 10 NDK蓝牙例子(Bluetooth SPP Chat Example)说明 http://blackberry.github.com/Cascades-Samples/bluetoothsppchat.html
BlackBerry 10 NDK例子代码(包括蓝牙)下载 https://github.com/blackberry/Cascades-Samples/
安卓手机和Arduino蓝牙通讯例子 Data transfer between Android and Arduino via Bluetooth http://english.cxem.net/arduino/arduino5.php
硬件:Arduino主板 + DHT11温湿度传感器 + 蓝牙模块,开发工具C语言
手机:BlackBerry 9360手机,OS 7.1,开发工具Java
手机:BlackBerry 10 Alpha手机,OS 10.0.xxx,开发工具BlackBerry 10 NDK
通讯:手机和Arduino通过蓝牙连接
BlackBerry 9360手机上面的显示:湿度41,温度11(哈冷啊。。。。。。。。。。。。。。。。)
Arduino代码参考这里 http://playground.arduino.cc/Main/DHTLib
代码如下:
//
// 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
BlackBerry Java API封装了串口通讯,所以用起来就很方便了。
开发工具eJDE中导入sample程序BluetoothSerialPortDemo ,修改代码接收蓝牙数据并显示在文本框中。
// 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);
}
注:
Arduino中,Serial.println() 出来的数据是0x0d, 0x0a。在Java中,我只检测回车字符 (char)0x0a作为一条数据的分隔符即可
BlackBerry OS 10
BlackBerry NDK C/C++ API封装了蓝牙SPP API,用起来稍微复杂一点(和Android API类似),连接蓝牙设备的时候,bt_spp_open()方法需要对方的服务UUID,mac地址。
下载BlackBerry 蓝牙例子代码bluetoothsppchat,导入到NDK中,build,运行即可。
注意其中的UUID的定义:
#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运行效果如图
参考:
蓝牙串口服务 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 10 NDK Bluetooth API http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bluetooth/topic/manual/btspp.h_functions_overview.html
BlackBerry 10 NDK蓝牙例子(Bluetooth SPP Chat Example)说明 http://blackberry.github.com/Cascades-Samples/bluetoothsppchat.html
BlackBerry 10 NDK例子代码(包括蓝牙)下载 https://github.com/blackberry/Cascades-Samples/
安卓手机和Arduino蓝牙通讯例子 Data transfer between Android and Arduino via Bluetooth http://english.cxem.net/arduino/arduino5.php
相关文章推荐
- 用Android手机通过蓝牙模块HC-06连接Arduino串口输出
- Uart2Socket:将PC的串口信息通过WiFi网络传输至安卓Android手机上
- 通过JAVA读取串口信息
- android手机通过串口蓝牙透传模块与AVR单片机通信实例。。。蓝牙服务程序案例
- 手机通过蓝牙串口与arduino通信
- 手机通过蓝牙串口与arduino通信
- CC2530 ADC实验1(读取片内温度并通过串口显示)
- 读取串口过来的GPS信息并分析其中内容
- Arduino - 改装车库门,增设手机蓝牙控制功能
- 电脑通过手机蓝牙无线上网
- 通过JAVA读取串口值
- 通过JAVA读取串口值(原创)
- 10_Android中通过HttpUrlConnection访问网络,Handler和多线程使用,读取网络html代码并显示在界面上,ScrollView组件的使用
- 使用的BlackBerry® Tablet OS SDK for Adobe® AIR®开发应用(四)
- Java如何通过URL调用远程接口并读取返回信息?
- Winloader 从手机读取信息时出错的解决办法
- 注册表的信息读取--获取系统串口数
- 读取手机硬件信息
- JavaScript 通过plus读取android手机短信内容
- 利用Contacts Provider读取手机联系人信息