raspberry pi

介绍 (Introduction)

When building portable sensors we often want to calibrate and double-check their readings before allowing them to log data remotely. Whilst developing these we can easily SSH into them and write any results to screen. However what happens when we are in a very remote part of the world, with no laptop, wifi or signal?

在制造便携式传感器时,我们经常要校准并仔细检查它们的读数,然后再允许它们远程记录数据。 在开发这些程序时,我们可以轻松地将它们通过SSH SSH并将任何结果写入屏幕。 但是,当我们身处世界的一个偏远地区而没有笔记本电脑,WiFi或信号时,会发生什么呢?

Within this tutorial, we look at exploiting the Bluetooth capabilities of a Raspberry Pi Zero (without WiFi) to transmit the initial set of results to a handheld device of our choosing. In our case, it will be through the use of a mobile phone or android tablet, such that we can compare the sensor and GPS readings.

在本教程中,我们将研究如何利用Raspberry Pi Zero(没有WiFi)的蓝牙功能将初始结果集传输到我们选择的手持设备。 在我们的案例中,将通过使用手机或android平板电脑来进行,以便我们可以比较传感器和GPS读数。

安装与设定 (Installation and Setup)

Before we start there are a couple of changes required for the Bluetooth to work. These are outlined below.

在我们开始之前,需要进行一些更改才能使蓝牙工作。 这些概述如下。

配置设备蓝牙 (Configuring the device Bluetooth)

We begin by changing the configuration of the installed Bluetooth library:

我们首先更改已安装的蓝牙库的配置:

sudo nano /etc/systemd/system/dbus-org.bluez.service

Here we locate the line starting ExecStart , and replace it with the following:

在这里,我们找到以ExecStart开头的行,并将其替换为以下内容:

ExecStart=/usr/lib/bluetooth/bluetoothd --compat --noplugin=sapExecStartPost=/usr/bin/sdptool add SP

Having added the ‘compatibility’ flag, we now have to restart the Bluetooth service on the Pi:

添加了“ compatibility”标志后,我们现在必须在Pi上重新启动蓝牙服务:

sudo systemctl daemon-reload;sudo systemctl restart bluetooth.service;

配对我们的显示器设备 (Pairing our monitor device)

To prevent issues with pairing Bluetooth devices whilst out in the field, it is always a good idea to pre-pair devices — saving their configuration.

为了防止在野外与蓝牙设备配对时出现问题,对设备进行预配对始终是一个好主意-保存其配置。

To do this we use bluetoothctl following the process described in the link below:

为此,我们按照以下链接中所述的过程使用bluetoothctl

  1. Locate our host MAC address找到我们的主机MAC地址
hcitool scan

This gives results in the format:

这样得出的结果格式如下:

Scanning ...XX:XX:XX:XX:XX:XX device1XX:XX:XX:XX:XX:XX device2

2. select the device we want and copy its address.

2.选择我们想要的设备并复制其地址。

3. execute the following:

3.执行以下操作:

sudo bluetoothctl

4. In the Bluetooth console run the following 3 commands (substituting your copied address):

4.在蓝牙控制台中,运行以下3个命令(替换您的复制地址):

discoverable on# thenpair XX:XX:XX:XX:XX:XX# and trust XX:XX:XX:XX:XX:XX# where XX corresponds to the address copied from above

When pairing you may be asked to confirm a pin on both devices. trust saves the device address to the trusted list.

配对时,可能会要求您确认两个设备上的引脚。 trust将设备地址保存到可信列表中。

To make a PI discoverable on boot, you can have a look at the code here:

要使PI在启动时可被发现,可以在此处查看代码:

在启动时启用通讯 (Enabling communication on startup)

Finally, we wish to tell the device to watch for incoming Bluetooth connections when it boots. To do this we can add the following file to /etc/rc.local (before the exit command).

最后,我们希望告诉设备在启动时要监视传入的蓝牙连接。 为此,我们可以将以下文件添加到/etc/rc.local (在exit命令之前)。

sudo rfcomm watch hci0 &

Take care to include the ampersand at the end, as otherwise, it will stall the device bootup process. Also if you are reading another device over serial, e.g. a GPS receiver, you may want to use rfcomm1 instead of hci0 (rfcomm0).

请小心在末尾包含&符,否则,它将使设备启动过程停顿。 同样,如果您正在通过串行方式读取其他设备(例如GPS接收器),则可能要使用rfcomm1而不是hci0 (rfcomm0)

从另一台设备连接到蓝牙串行 (Connecting to the Bluetooth serial from another device)

Depending on what device you are using, the method to read from a serial monitor varies. On an android device, you may take the node/javascript approach (this should work on all operating systems!). For the purpose of this demo, I will describe a method using python to check things are working on a MacBook Pro.

根据所用设备的不同,从串行监视器读取数据的方法也有所不同。 在android设备上,您可以采用node / javascript方法(这在所有操作系统上均适用!)。 出于本演示的目的,我将描述一种使用python检查MacBook Pro上是否工作正常的方法。

确定端口名称 (Determining the port name)

If you have a terminal, the simplest way to do this is to type

如果您有终端,执行此操作的最简单方法是键入

ls /dev/tty.

and hit the tab (autocomplete) button.

并点击标签(自动填充)按钮。

Presuming you have not changed this, this should be your device hostname followed by SerialPort. The default serial port path for a freshly installed raspberry pi should be

假设您尚未更改,则应为设备hostname后跟SerialPort。 新安装的树莓派的默认串行端口路径应为

/dev/tty.raspberrypi-SerialPort

读取收到的数据 (Reading data received)

To read any data received, we can use the python serial library coupled with the following code snippet.

要读取接收到的任何数据,我们可以将python serial库与以下代码段结合使用。

import serialser = serial.Serial('/dev/tty.raspberrypi-SerialPort', timeout=1, baudrate=115000)serial.flushInput();serial.flushOutput()

while True:    out = serial.readline().decode()    if out!='' : print (out)

Note that this is an infinite loop that keeps printing anything it receives. To cancel it when the message ‘exit’ is received we can use:

请注意,这是一个无限循环,不断打印收到的任何内容。 要在收到“退出”消息时取消它,我们可以使用:

if out == 'exit': break

从传感器发送数据 (Sending data from the sensor)

从外壳 (From the shell)

When testing the simplest way to send data is to echo it to /dev/rgcomm0 from the raspberry pi shell. This allows us to manually test communication over the port before writing anything more complicated.

测试发送数据的最简单方法是从/dev/rgcomm0 pi shell将其回显到/dev/rgcomm0 。 这使我们能够在编写更复杂的内容之前手动测试通过端口的通信。

echo "hello!" > /dev/rfcomm0

从python脚本 (From a python script)

If reading data from the raspberry pi and pre-processing it, chances are we will be using python to do the heavy lifting. From here we can treat the rfcomm0 channel as a file and write to it as follows:

如果从树莓派读取数据并对其进行预处理,则很有可能我们将使用python进行繁重的工作。 在这里,我们可以将rfcomm0通道视为一个文件,并按如下所示对其进行写入:

with open(‘/dev/rfcomm0’,’w’,1) as f:     f.write(‘hello from python!’)

结论 (Conclusions)

If we want to quickly check that our sensors are behaving whilst out in the field, we can make use of the Bluetooth capabilities of the Raspberry Pi. This is done by creating a Bluetooth serial port and sending data over it. Such methods are particularly useful if we do not wish to carry bulky laptops, or where a WiFi network is occupied or unavailable.

如果我们想在野外快速检查传感器的运行状况,可以使用Raspberry Pi的蓝牙功能。 这是通过创建蓝牙串行端口并通过其发送数据来完成的。 如果我们不希望携带笨重的笔记本电脑,或者在WiFi网络被占用或不可用的情况下,这种方法特别有用。

More complex tasks such as sending commands to the Raspberry Pi, or even SSHing into it over Bluetooth are also possible but are beyond the scope of this tutorial.

也可以执行更复杂的任务,例如将命令发送到Raspberry Pi,甚至通过蓝牙SSH到Raspberry Pi,但这不在本教程的范围之内。

翻译自: https://towardsdatascience.com/sending-data-from-a-raspberry-pi-sensor-unit-over-serial-bluetooth-f9063f3447af

raspberry pi


http://www.taodudu.cc/news/show-863390.html

相关文章:

  • 问答机器人接口python_设计用于机器学习工程的Python接口
  • k均值算法 二分k均值算法_如何获得K均值算法面试问题
  • 支持向量机概念图解_支持向量机:基本概念
  • 如何设置Jupiter Notebook服务器并从任何地方访问它(Windows 10)
  • 无监督学习 k-means_监督学习-它意味着什么?
  • logistic 回归_具有Logistic回归的优秀初学者项目
  • 脉冲多普勒雷达_是人类还是动物? 多普勒脉冲雷达和神经网络的目标分类
  • pandas内置绘图_使用Pandas内置功能探索数据集
  • sim卡rfm_信用卡客户的RFM集群
  • 需求分析与建模最佳实践_社交媒体和主题建模:如何在实践中分析帖子
  • 机器学习 数据模型_使用PyCaret将机器学习模型运送到数据—第二部分
  • 大数据平台蓝图_数据科学面试蓝图
  • 算法竞赛训练指南代码仓库_数据仓库综合指南
  • 深度学习 图像分类_深度学习时代您应该阅读的10篇文章了解图像分类
  • 蝙蝠侠遥控器pcb_通过蝙蝠侠从Circle到ML:第一部分
  • cnn卷积神经网络_5分钟内卷积神经网络(CNN)
  • 基于树的模型的机器学习
  • 数据分析模型和工具_数据分析师工具包:模型
  • 图像梯度增强_使用梯度增强机在R中进行分类
  • 机器学习 文本分类 代码_无需担心机器学习-如何在少于10行代码中对文本进行分类
  • lr模型和dnn模型_建立ML或DNN模型的技巧
  • 数量和质量评价模型_数量对于语言模型可以具有自己的质量
  • mlflow_使用MLflow跟踪进行超参数调整
  • 聊天产生器
  • 深度学习领域专业词汇_深度学习时代的人文领域专业知识
  • 图像分类
  • CSDN-Markdown基本语法
  • python3(一)数字Number
  • python3(二)Numpy
  • python3(三)Matplotlib

raspberry pi_通过串行蓝牙从Raspberry Pi传感器单元发送数据相关推荐

  1. 【51单片机】串行通信,采用中断,串行口方式3,甲机发送,乙机接收:接收数据通过七段数码管显示。

    实验要求:甲.乙双机通过串行口进行连接,采用中断方式,编写串行口方式3下的甲.乙双机发送与接收程序. 甲机发送:发送数据存放在数组TRA[16]里面. 乙机接收:接收数据通过一个七段数码管进行显示.晶 ...

  2. raspberry pi_您应该选择哪种Raspberry Pi?

    raspberry pi 这是有关Raspberry Pi入门的14天系列文章中的第一篇. 尽管本系列文章的对象是从未使用过Raspberry Pi或Linux或编程的人,但绝对有一些经验丰富的读者可 ...

  3. raspberry pi_尝试8个有趣的Raspberry Pi项目

    raspberry pi 对于我们中的许多人来说,2016年过去了,我们还没有完成新年的所有决议,也没有将所有事情标记在" 2016年待办事项"列表中. 今年我没有足够的时间来玩R ...

  4. 【SRIO】3、RapidIO串行物理层的包传输过程

    目录 一.引言 二.串行物理层的PCS层与PMA层 2.1 PCS层的功能 2.2 PMA层的功能 2.3 术语定义 2.3 8B/10B传输码 2.4 字符和码组记号 2.5 运行不一致(Runni ...

  5. 【SRIO】2、RapidIO串行物理层的包与控制符号

    目录 一.RapidIO串行物理层背景介绍 二.RapidIO串行物理层的包格式 2.1 串行物理层包格式与并行物理层包格式的区别 2.2 RapidIO串行物理层包格式 2.3 RapidIO串行物 ...

  6. 基于FPGA的通用8251串行异步收发器(6600+字)

    1.简介与仿真结论 随着集成电路技术的发展,电子设计自动化(EDA)逐渐成为重要的设计手段,已经广泛应用于模拟与数字电路系统等许多领域.电子设计自动化是一种实现电子系统或电子产品自动化设计的技术,它与 ...

  7. 51单片机串行口的使用与串行通信

    51单片机串行口的使用与串行通信 串行通信: 俩个概念: RS232接口标准: 串行口的使用: 串行口的结构: 串行口相关寄存器: 串行口的工作方式: 方式0:同步移位寄存器方式 利用方式0扩展并行I ...

  8. 串行并行 同步异步通信

    终端与其他设备(例如其他终端.计算机和外部设备)通过数据传输进行通信.数据传输可以通过两种方式进行:并行通信和串行通信. 1.串行通信 是指使用一条数据线,将数据一位一位地依次传输,每一位数据占据一个 ...

  9. 通信协议-GMSL(千兆多媒体串行链路)

    首先,了解一下什么是GMSL GMSL(Gigabit Multimedia Serial Links),中文名称为千兆多媒体串行链路,是Maxim公司推出的一种高速串行接口,适用于音频,视频和控制信 ...

最新文章

  1. idea自动捕获_Smilefie:如何通过检测微笑来自动捕获自拍
  2. 前百度首席科学家吴恩达携手富士康,要用人工智能升级制造业
  3. DOS之BAT批处理文件语法3(转)
  4. hdu1914 稳定婚姻问题
  5. 时间同步失败_跨系统历史数据同步脚本实战
  6. Protobuf序列化的原理-总结
  7. 谈谈一些有趣的CSS题目(十五)-- 谈谈 CSS 关键字 initial、inherit 和 unset
  8. 时区 java 巴黎,关于时区:Java没有有关所有IANA时区的信息
  9. php 解压zip到目录下,php 解压zip压缩包内容到指定目录的实例
  10. 谷歌浏览器开发调式工具文档
  11. Mysql大量插入随机数据方法--存储过程
  12. AOL架构原则.优秀API设计.Yeoman工具
  13. 拓端tecdat|R语言使用倾向评分提高RCT(随机对照试验)的效率
  14. 现代语音信号处理之语谱图(spectrogram)
  15. java基础练习题及答案_java基础测试题含答案.docx
  16. html表白代码大全可复制,浪漫的html表白特效网页制作源
  17. 地壳中元素含量排名记忆口诀_地壳含量_地壳中元素含量排名口诀
  18. php引用字体,thinkphp引入字体文件时候被当做模块求解决问题
  19. 关于Excel自动换行,不会在西文单词中间换行的问题
  20. html5页面打不开原因,部分网页打不开是什么原因,详细教您网页打不开怎么解决...

热门文章

  1. 如何使用ABBYY FineReader 12将JPEG文件转换成Word文档
  2. Redis的几个认识误区
  3. javascript的装饰者模式(七)
  4. 利用反射自动封装成实体对象
  5. 2011年2月--2011年7月数据库性能优化过程
  6. 【收集】6410 开发板(Real6410/TE6410/OK6410/mini6410/micro6410/FL6410)wince问题
  7. 工作流引擎的五大接口
  8. 计算机课程职业素质考核,中职计算机课程中多元化考核的探索与实践
  9. 腾讯云linux数据盘格式化,腾讯云服务器Centos挂载数据盘的方法
  10. php编程对联,形容程序员的对联大全