当前位置:首页>编程日记>正文

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温

文本, 我会使用一个Elixir实现的模块函数去读取连接到树莓派的DS18B20温度传感器的温度数值.

文本假设你熟悉

  • 数字电路基础

  • Elixir编程基础

视频演示

  • https://v.qq.com/x/page/q0357...

原料

树莓派3, B型(图片省略, 下文有)

DS18B20传感器

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图01

4.7KΩ 电阻(一分钱一颗)

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图02

面包板(图片省略, 下文有)

公母头杜邦线

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图03

连接温度传感器

接线图

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图04

面包板内部连通图

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图05

面包板接线图

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图06

  • 黑色为地线

  • 红色为3.3V板供直流电源, 对应PIN1

  • 黄色为数据线

  • 电阻连接在红色和黄色线之间

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图07

树莓派主板接线

  • 左侧三根是连接到电脑的串口线, 用于控制台输入输出.

  • 右侧为DS18B20传感器的三个引脚

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图08

全体照

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图09

创建一个新的Elixir Nerves项目

mix nerves.new hello_celsius_sensor --target rpi3
cd hello_celsius_sensor
mix deps.get

启用线路协议支持

下面的过程和描述和覆盖启动分区中的文件相关

修改 config/config.exs, 包含如下内容:

use Mix.Config# 日志
config :logger, :console,level: :debug,format: "$date $time $metadata[$level] $message
",handle_sasl_reports: true,handle_otp_reports: true,utc_log: true# 覆盖
config :nerves, :firmware,rootfs_additions: "config/rootfs-additions"# 固件配置
config :nerves, :firmware,fwup_conf: "config/rpi/fwup.conf"

创建 rootfs-additions 目录

mkdir -p config/rootsfs-additions/etc
cd config/rootsfs-additions/etc
vi erlinit.config

添加如下内容:

# Additional configuration for erlinit# Turn on the debug prints
# -v# Specify the UART port that the shell should use.
#-c tty1
-c ttyS0# If more than one tty are available, always warn if the user is looking at
# the wrong one.
--warn-unused-tty# Use dtach to capture the iex session so that it can be redirected
# to the app's GUI
#-s "/usr/bin/dtach -N /tmp/iex_prompt"# Specify the user and group IDs for the Erlang VM
#--uid 100
#--gid 200# Uncomment to hang the board rather than rebooting when Erlang exits
# --hang-on-exit# Optionally run a program if the Erlang VM exits
#--run-on-exit /bin/sh# Enable UTF-8 filename handling in Erlang and custom inet configuration
-e LANG=en_US.UTF-8;LANGUAGE=en;ERL_INETRC=/etc/erl_inetrc# Mount the application partition
# See http://www.linuxfromscratch.org/lfs/view/6.3/chapter08/fstab.html about
# ignoring warning the Linux kernel warning about using UTF8 with vfat.
-m /dev/mmcblk0p3:/root:vfat::# Erlang release search path
-r /srv/erlang# Assign a unique hostname based on the board id
-d "/usr/bin/boardid -b rpi -n 4"
-n nerves-%.4s

注意-c 参数设置为 ttyS0 是为了能够通过开发电脑查看到树莓派的输出信息, 请参考使用 Elixir 开发嵌入式系统: 串口调试

cp deps/rpi3/nerves_system_rpi3/fwup.conf config

修改 file-resource config.txt 的位置, 其中 NERVES_APP 为当前项目的根目录.

file-resource config.txt {host-path = "${NERVES_APP}/config/rpi/config.txt"
}

复制 config.txt 文件.

cp deps/rpi3/nerves_system_rpi3/config.txt config/rpi

DS18B20 使用 Dallas 1-Wire protocol 协议. Nerves 提供了对 1-Wire 协议的支持, 只需要在 config.txt 配置文件激活这个参数即可.

使用 Elixir 开发嵌入式系统- 使用DS18B20传感器测量体温 配图10

代码库

  • https://github.com/developerw...

参考资料

  • Elixir Nerves for measuring temperature from a DS18B20 sensor on a Raspberry Pi

  • Raspberry Pi DS18B20 Temperature Sensor Tutorial


http://www.coolblog.cn/news/019c8c3e4cae39b1.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • Mac原生Terminal快速登录ssh
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • mysql commit 机制_1024MySQL事物提交机制
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • jquery 使用小技巧
  • 2019-9
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 科学计算工具NumPy(3):ndarray的元素处理
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • linux批量创建用户和密码
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • js常用阻止冒泡事件
  • 气泡图在开源监控工具中的应用效果
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • 【设计模式】 模式PK:策略模式VS状态模式
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • CSS小技巧——CSS滚动条美化
  • JS实现-页面数据无限加载
  • 阿里巴巴分布式服务框架 Dubbo
  • 最新DOS大全
  • Django View(视图系统)
  • 阿里大鱼.net core 发送短信
  • 程序员入错行怎么办?
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 《看透springmvc源码分析与实践》读书笔记一
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • Arm芯片的新革命在缓缓上演
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 行为模式之Template Method模式
  • 通过Spark进行ALS离线和Stream实时推荐