简体   繁体   English

通过蓝牙将树莓派2的字符串变量发送到android应用

[英]send string variable from raspberry pi 2 to android app over bluetooth

I am developing an android app using android studio to receive string(results) from raspberry pi after image processing code . 我正在开发一个使用android studio的android应用程序,以在图像处理代码之后从raspberry pi接收字符串(结果)。

I am using python 2.7.3, opencv 3.1, numpy 1.8. 我正在使用python 2.7.3,opencv 3.1,numpy 1.8。 bluetooth chip RN42XVP connected to the raspberry pi 2 蓝牙芯片RN42XVP连接到树莓派2

I read this question Receiving data from raspberry pi in android via bluetooth 我读了这个问题通过蓝牙从android的raspberry pi接收数据

I tried it but it gave too many errors and undefined variable! 我试过了,但是它给出了太多的错误和未定义的变量! anyway I think it is not specifically what am searching for. 无论如何,我认为这并不是要寻找的东西。

what i need is simply to send the content of string from a python code on raspberry pi to android application. 我需要的只是将树莓派上的python代码中的字符串内容发送到android应用程序。

when a button clicked in android app it will receive and display the content 在Android应用中单击按钮时,它将接收并显示内容

The following is the general approach: read the manual 以下是一般方法:阅读手册

  1. Read the data sheet, it has all the information on how to connect and talk to the device. 阅读数据手册,其中包含有关如何连接和与设备进行通话的所有信息。 You need to figure out the following: 您需要确定以下内容:

    • How do you want to connect to the device (the product page mentions UART or USB). 您想如何连接到设备(产品页面提到UART或USB)。
    • depending on your choice you figure out what hardware this module needs in order to run (Capacitors, Voltage supply, etc.). 根据您的选择,您可以确定要运行该模块所需的硬件(电容器,电源等)。
  2. After that you connect the device to USB- or UART-capable pins on your Raspberry Pi. 之后,将设备连接到Raspberry Pi上具有USB或UART功能的引脚。

  3. Then you want to open a device file descriptor on you raspberry pi, which talks to those pins. 然后,您想在树莓派上打开一个设备文件描述符,该描述符与这些引脚进行通信。 (Normally a open(file, "w") should be sufficient). (通常open(file, "w")就足够了)。 (If you are not sure, refer to the Raspberry Pi documentation or google it.) (如果不确定,请参考Raspberry Pi文档或对其进行谷歌搜索。)

  4. Everything you write into this file descriptor gets sent to the wireless module. 您写入此文件描述符的所有内容都会发送到无线模块。

  5. Figure out how to communicate with the module (what commands you need to send, how to set it up, etc.). 弄清楚如何与模块通信(您需要发送什么命令,如何设置它,等等)。

  6. Write your python code. 编写您的python代码。

After Googling it, it seems, that this is a very popular module and has already been used with Arduinos, maybe you can find a tutorial on how to connect it, I'm pretty sure that there also are some libraries already written, which spares you the hassle of writing everything yourself. 谷歌搜索之后,这似乎是一个非常流行的模块,并且已经与Arduinos一起使用,也许您可​​以找到有关如何连接它的教程,我敢肯定,已经编写了一些库,这些库您自己编写所有内容的麻烦。

The following link describes how to connect the module with an Arduino, but it should be easy to do the same with your Raspberry Pi: http://dduino.blogspot.co.at/2012/03/arduino-rn-42-bluetooth-module.html 以下链接描述了如何将模块与Arduino连接,但是使用Raspberry Pi进行连接应该很容易: http : //dduino.blogspot.co.at/2012/03/arduino-rn-42-bluetooth -module.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM