自制树莓派PICO RP2040开发板+例程(I2C读取LM75和AHT20 温度数据)

1.原理图

在这里插入图片描述

2.PCB

晶振的焊盘有点大,怕和外壳短路,找了个东西垫高了下
来自嘉立创免费打样PCB
在这里插入图片描述

3.焊接完成

这颗QFN封装芯片比较考验焊接功底,手残的不建议自己弄。
在这里插入图片描述

4.代码实现

参考https://pico.org.cn/

1.main.py

from machine import Pin ,I2C
from utime import sleep
import utime
import lm75a
import ahtx0i=machine.unique_id()#获取芯片ID
led = Pin(25, Pin.OUT) 
print("你好。。。" , i)
KEY2 = Pin(16, Pin.IN, Pin.PULL_UP)
KEY2.irq(lambda pin: external_interrupt(),Pin.IRQ_FALLING)#按键中断i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000)
#根据已有挂载i2c设备增减i2c.scan()[] 我挂载了3个就打印3个,否则报错
print("所有I2C Address : ", hex(i2c.scan()[0]).upper(),hex(i2c.scan()[1]).upper(),hex(i2c.scan()[2]).upper()) # Display device addresssensor_LM75 = lm75a.LM75A(i2c)
sensor_AHT20 = ahtx0.AHT20(i2c)def external_interrupt():led.toggle()print('按键中断',led.value())print("AHT20实时温度: %0.2f C" % sensor_AHT20.temperature)print("AHT20实时湿度: %0.2f %%" % sensor_AHT20.relative_humidity)if __name__ == '__main__':while True:led.value(1)# led off  utime.sleep_ms(1000)led.value(0)# led onutime.sleep_ms(1000)print("LM75实时温度检测:%0.2f C" % sensor_LM75.temp())#print("AHT20实时温度: %0.2f C" % sensor_AHT20.temperature)#print("AHT20实时湿度: %0.2f %%" % sensor_AHT20.relative_humidity)

2. AHTX0.PY

# The MIT License (MIT)
#
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
# Copyright (c) 2020 Andreas Bühl
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
MicroPython driver for the AHT10 and AHT20 Humidity and Temperature Sensor
Author(s): Andreas Bühl, Kattni Rembor
"""import utime
from micropython import constclass AHT10:"""Interface library for AHT10/AHT20 temperature+humidity sensors"""AHTX0_I2CADDR_DEFAULT = const(0x38)  # Default I2C addressAHTX0_CMD_INITIALIZE = 0xE1  # Initialization commandAHTX0_CMD_TRIGGER = const(0xAC)  # Trigger reading commandAHTX0_CMD_SOFTRESET = const(0xBA)  # Soft reset commandAHTX0_STATUS_BUSY = const(0x80)  # Status bit for busyAHTX0_STATUS_CALIBRATED = const(0x08)  # Status bit for calibrateddef __init__(self, i2c, address=AHTX0_I2CADDR_DEFAULT):utime.sleep_ms(20)  # 20ms delay to wake upself._i2c = i2cself._address = addressself._buf = bytearray(6)self.reset()if not self.initialize():raise RuntimeError("Could not initialize")self._temp = Noneself._humidity = Nonedef reset(self):"""Perform a soft-reset of the AHT"""self._buf[0] = self.AHTX0_CMD_SOFTRESETself._i2c.writeto(self._address, self._buf[0:1])utime.sleep_ms(20)  # 20ms delay to wake updef initialize(self):"""Ask the sensor to self-initialize. Returns True on success, False otherwise"""self._buf[0] = self.AHTX0_CMD_INITIALIZEself._buf[1] = 0x08self._buf[2] = 0x00self._i2c.writeto(self._address, self._buf[0:3])self._wait_for_idle()if not self.status & self.AHTX0_STATUS_CALIBRATED:return Falsereturn True@propertydef status(self):"""The status byte initially returned from the sensor, see datasheet for details"""self._read_to_buffer()return self._buf[0]@propertydef relative_humidity(self):"""The measured relative humidity in percent."""self._perform_measurement()self._humidity = ((self._buf[1] << 12) | (self._buf[2] << 4) | (self._buf[3] >> 4))self._humidity = (self._humidity * 100) / 0x100000return self._humidity@propertydef temperature(self):"""The measured temperature in degrees Celcius."""self._perform_measurement()self._temp = ((self._buf[3] & 0xF) << 16) | (self._buf[4] << 8) | self._buf[5]self._temp = ((self._temp * 200.0) / 0x100000) - 50return self._tempdef _read_to_buffer(self):"""Read sensor data to buffer"""self._i2c.readfrom_into(self._address, self._buf)def _trigger_measurement(self):"""Internal function for triggering the AHT to read temp/humidity"""self._buf[0] = self.AHTX0_CMD_TRIGGERself._buf[1] = 0x33self._buf[2] = 0x00self._i2c.writeto(self._address, self._buf[0:3])def _wait_for_idle(self):"""Wait until sensor can receive a new command"""while self.status & self.AHTX0_STATUS_BUSY:utime.sleep_ms(5)def _perform_measurement(self):"""Trigger measurement and write result to buffer"""self._trigger_measurement()self._wait_for_idle()self._read_to_buffer()class AHT20(AHT10):AHTX0_CMD_INITIALIZE = 0xBE  # Calibration command

3.LM75A.PY

"""
MicroPython LM75A Digital Temperature Sensor
https://github.com/mcauser/micropython-lm75a
MIT License
Copyright (c) 2019 Mike Causer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""__version__ = '0.0.3'# registers
_LM75A_TEMP  = const(0x00) # Temperature register (r) 16-bit
_LM75A_CONF  = const(0x01) # Configuration register (r/w) 8-bit, default: enabled, comparator, os active low, single fault
_LM75A_THYST = const(0x02) # Hysteresis register (r/w) 16-bit, default: 75°C
_LM75A_TOS   = const(0x03) # Overtemperature shutdown register (r/w) 16-bit, default: 80°Cclass LM75A:def __init__(self, i2c, address=0x49):self._i2c = i2cself._address = address # 0x48-0x4Fself._config = 0x00self._buf1 = bytearray(1)self._buf2 = bytearray(2)self.check()self.config()def check(self):if self._i2c.scan().count(self._address) == 0:raise OSError('LM75A not found at I2C address {:#x}'.format(self._address))def config(self, shutdown=None, os_mode=None, os_polarity=None, os_fault_queue=None):if shutdown is not None:self._config = (self._config & ~1) | (shutdown & 1)if os_mode is not None:self._config = (self._config & ~2) | ((os_mode << 1) & 2)if os_polarity is not None:self._config = (self._config & ~4) | ((os_polarity << 2) & 4)if os_fault_queue is not None:self._config = (self._config & ~24) | ((os_fault_queue << 3) & 24)self._buf1[0] = self._configself._i2c.writeto_mem(self._address, _LM75A_CONF, self._buf1)def temp(self):self._i2c.readfrom_mem_into(self._address, _LM75A_TEMP, self._buf2)val = (self._buf2[0] << 3) | (self._buf2[1] >> 5)return self._twos_comp(val, 11) * 0.125def tos(self, temp):self._temp_to_9bit_reg(temp)self._i2c.writeto_mem(self._address, _LM75A_TOS, self._buf2)def thyst(self, temp):self._temp_to_9bit_reg(temp)self._i2c.writeto_mem(self._address, _LM75A_THYST, self._buf2)def _twos_comp(self, val, bits):mask = 2 ** (bits - 1)return -(val & mask) + (val & ~mask)def _rev_twos_comp(self, val, bits):return val & ((1 << bits) -1)def _temp_to_9bit_reg(self, temp):val = self._rev_twos_comp(int(temp / 0.5), 9)self._buf2[0] = val >> 1self._buf2[1] = val << 7

5.Thonne IDE

将代码保存到pico里
在这里插入图片描述

在这里插入图片描述

6.注意事项

WIN7 下需要额外装CDC驱动,不想找驱动的的可以复制下面另存为xxx.inf文件 然后进设备管理器里更新。

; Windows 2000, XP, Vista, 7 and 8 (x32 and x64) setup file for Atmel CDC Devices
; Copyright (c) 2000-2013 ATMEL, Inc.[Version] 
Signature   = "$Windows NT$" 
Class       = Ports 
ClassGuid   = {4D36E978-E325-11CE-BFC1-08002BE10318} Provider    = %Manufacturer% 
LayoutFile  = layout.inf 
CatalogFile = atmel_devices_cdc.cat
DriverVer   = 01/08/2013,6.0.0.0 ;----------------------------------------------------------
; Targets
;----------------------------------------------------------
[Manufacturer] 
%Manufacturer%=DeviceList, NTAMD64, NTIA64, NT [DeviceList] 
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00[DeviceList.NTAMD64]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00 [DeviceList.NTIA64]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00 [DeviceList.NT]
%PI_CDC_PICO%=DriverInstall, USB\VID_2E8A&PID_0005&MI_00;----------------------------------------------------------
; Windows 2000, XP, Vista, Windows 7, Windows 8 - 32bit
;----------------------------------------------------------
[Reader_Install.NTx86] [DestinationDirs] 
DefaultDestDir=12 
DriverInstall.NT.Copy=12 [DriverInstall.NT] 
include=mdmcpq.inf
CopyFiles=DriverInstall.NT.Copy 
AddReg=DriverInstall.NT.AddReg [DriverInstall.NT.Copy] 
usbser.sys [DriverInstall.NT.AddReg]
HKR,,DevLoader,,*ntkern 
HKR,,NTMPDriver,,usbser.sys 
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" [DriverInstall.NT.Services] 
AddService = usbser, 0x00000002, DriverService.NT [DriverService.NT] 
DisplayName = %Serial.SvcDesc% 
ServiceType = 1 ; SERVICE_KERNEL_DRIVER 
StartType = 3 ; SERVICE_DEMAND_START 
ErrorControl = 1 ; SERVICE_ERROR_NORMAL 
ServiceBinary = %12%\usbser.sys 
LoadOrderGroup = Base ;----------------------------------------------------------
; Windows XP, Vista, Windows 7, Windows 8 - 64bit
;----------------------------------------------------------[DriverInstall.NTamd64]
include=mdmcpq.inf
CopyFiles=DriverCopyFiles.NTamd64
AddReg=DriverInstall.NTamd64.AddReg[DriverCopyFiles.NTamd64]
usbser.sys,,,0x20[DriverInstall.NTamd64.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"[DriverInstall.NTamd64.Services]
AddService=usbser, 0x00000002, DriverService.NTamd64[DriverService.NTamd64]
DisplayName=%Serial.SvcDesc%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\usbser.sys;----------------------------------------------------------
; String
;----------------------------------------------------------[Strings] 
Manufacturer = "ATMEL, Inc." 
PI_CDC_PICO = "Pi Pico Serial Port" Serial.SvcDesc = "Pi Pico Serial Driver"

7.参考

1.https://pico.org.cn 树莓派pico 中文站
2.https://awesome-micropython.com/ Awesome MicroPython库
3.https://www.runoob.com/python/python-tutorial.html Python基础教程
4.https://docs.singtown.com/micropython/zh/latest/pyboard/library/index.html MicroPython教程

8.放角落吃灰

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/30840.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

chatgpt赋能python:Python的GUI界面开发

Python的GUI界面开发 Python是目前非常流行的编程语言之一&#xff0c;其优雅的语法和强大的库使其在各个领域得到广泛应用。在GUI界面开发方面&#xff0c;Python也表现出了巨大的潜力。本文将介绍Python的GUI开发框架以及相关的工具和技术。 介绍 Python有多个GUI框架可供…

LangGPT —— 让人人都能编写高质量 Prompt

要用好现有大模型的能力严重依赖高质量 prompt&#xff0c; 然而编写高质量 prompt 在现阶段还是个手艺活&#xff0c;太依赖个人经验。 虽然也有许多个人自发分享的 prompt 方法、框架&#xff0c;以及吴恩达老师的 prompt 教程&#xff0c;但是现有 Prompt 创建方法还是有各…

如何让网页显示友好的错误信息页面

大多数用户看到”该页无法显示",”服务器内部错误"等默认错误提示信息会立马关闭浏览器窗口&#xff0c;我们为什么不能自定义一下呢?让用户从错误信息中得到真正的帮助? 错误信息的页面应该做到以下几点&#xff1a; 1.给普通访客友好提示。告诉他们这是怎么了&…

Anthropic 推出 “更理性的 Claude”,正面硬刚 ChatGPT

Anthropic 是一家由前 OpenAI 团队成员创立的初创公司&#xff0c;最近它推出了一款名为 Claude 的 AI 聊天机器人&#xff0c;将其作为 ChatGPT 的竞争对手。 与 ChatGPT 类似&#xff0c;Claude 能够执行各种基于文字对话的任务&#xff0c;如文档搜索、摘要、写作、编码&…

Xavier agx使用指南汇总

xavier系统架构讲解&#xff1a; Xaiver是arm64平台&#xff0c;与x86平台pc机构完全不通用的 Xavier接口 介绍&#xff1a; https://blog.csdn.net/enlaihe/article/details/119751074?utm_mediumdistribute.pc_relevant.none-task-blog-2~default~baidujs_utm_term~defaul…

不用魔法,快速、手摸手上线Midjourney!【附源码】【示例】

首先来一波感谢&#xff1a; 感谢laf提供赞助&#xff0c;目前可以免费使用Midjourney进行开发和测试。 感谢白夜、米开朗基杨sealos.io的耐心解答&#xff0c;让我对laf有了更多的使用与了解。 什么是laf&#xff1f;来了解下。 文末有【示例】 开始 废话不多说&#xff0c;…

国外大神竟用 ChatGPT 成功打造了一个「虚拟空间传送」系统!

相信大家小时候躺在床上&#xff0c;都曾设想过这么一个场景&#xff1a; 当你闭上眼睛时&#xff0c;感觉身心十分安宁&#xff0c;物理世界慢慢淡出&#xff0c;身体也随着变得飘逸&#xff0c;一切仿佛只剩下呼吸声和心跳声。 一阵微风拂过&#xff0c;你缓缓睁开双眼&#…

国外大神用 ChatGPT 成功打造一个「虚拟空间传送」系统!

公众号关注 “GitHubDaily” 设为 “星标”&#xff0c;每天带你逛 GitHub&#xff01; 相信大家小时候躺在床上&#xff0c;都曾设想过这么一个场景&#xff1a; 当你闭上眼睛时&#xff0c;感觉身心十分安宁&#xff0c;物理世界慢慢淡出&#xff0c;身体也随着变得飘逸&…

基于认知神经科学的大模型【2023智源大会会议总结】

1. ChatGPT不能做什么? 刘嘉|清华大学脑与智能实验室首席研究员 1.1 演讲内容 图1.1 Sam Altman的签名 图1.2 大模型模仿理性部分、忽略感性部分 图1.3 未来可以为AI加入身体 图1.4 未来为AI赋予社交 图1.5 AGI的演化 1.2 总结 演讲目标&#xff1a;ChatGPT具有很多功…

用数据带你回顾乔丹的职业生涯

乔丹是联盟上下公认的历史第一人&#xff0c;芝加哥公牛在他带领下几乎统治了上世纪90年代NBA整整10年&#xff0c;包括分别在91-93赛季和96-98赛季拿下的两次三连冠&#xff0c;要知道&#xff0c;NBA72年历史上一共只出现过4次三连冠&#xff0c;而乔帮主一人便承包一半。下面…

NBA著名球星介绍

NBA著名球星介绍 迈克尔乔丹 毋庸置疑的篮球之神&#xff0c;六次总冠军&#xff0c;五次常规赛MVP&#xff0c;14次入选全明星他所取得的荣誉是其他任何NBA球员都无法比拟的&#xff0c;甚至从某种程度上说&#xff0c;乔丹代表这篮球这项运动&#xff0c;代表着在这项运动里所…

球星测试软件,2KOL球星测评丨篮球之神,迈克尔.乔丹(96版)

迈克尔.乔丹(96版) 迈克尔乔丹在在1984年NBA选秀中于第1轮第3位被芝加哥公牛队选中。(他的前面两位分别是哈基姆奥拉朱旺和萨姆鲍伊) 91-93赛季&#xff0c;乔丹连续2次荣膺常规赛MVP和3次总决赛FMVP &#xff0c;并率领芝加哥公牛队首夺3连冠。 93年10月6日因父亲被害而宣布退…

论“詹姆斯*哈登”到底是不是球队毒瘤

从林书豪和哈登的合作&#xff0c;到魔登的短暂快乐&#xff0c;再到保罗和安东尼以及威少&#xff0c;哈登漫长的火箭生涯里留下的遗憾可能要比成功多的多&#xff0c;他没有让火箭真正的成为顶级的冲冠球队&#xff0c;或许在那么一瞬间或者某个赛季&#xff0c;曾几何时有人…

NBA球星logo

科比退役信上的新logo镇楼。 该logo已被用于科比的公司&#xff0c;并非个人logo。 1.特雷西麦克格雷迪 由T-Mac中的T和M&#xff0c;以及1号和一个篮筐组成 2.文斯卡特 当年卡特作为耐克shox系列代言人&#xff0c;这个由VC和15组成的log&#xff0c;在每一双shox系列篮球鞋…

数据分析职位需求分析报告-数据来源于Boss直聘网站

数据分析职位需求分析报告-数据来源于Boss直聘网站 1.背景2.目的3.数据说明4.具体内容4.1 学历分析4.2 工作地点分析4.3 经验分析4.4 技能分析4.5 公司规模分析4.6 工资分析 5.结论 1.背景 目前&#xff0c;越来越多的人涌入到数据分析领域的相关工作中。然而&#xff0c;数据分…

招聘革命者:五岁BOSS直聘的慢与快

随着90后、95后成为职场主力军&#xff0c;招聘到了一个爆发的新时代拐点时刻。可以说&#xff0c;年轻人直接和老板谈工作&#xff0c;是眼下“互联网人力资源”最火的话题。 这其中&#xff0c;革命者BOSS直聘成为这一新模式的代表&#xff0c;并在日渐打破原来的招聘格局。…

AP资产 | 量化多岗位招聘(全职+实习)

量化投资与机器学习微信公众号&#xff0c;是业内垂直于量化投资、对冲基金、Fintech、人工智能、大数据等领域的主流自媒体。公众号拥有来自公募、私募、券商、期货、银行、保险、高校等行业30W关注者。 公司介绍 AP资产是一家由数个传统行业家族自有资金发起&#xff0c;逐步…

图数据库 Nebula Graph 在 Boss 直聘的应用

本文首发于 Nebula Graph 官方博客&#xff1a;https://nebula-graph.com.cn/posts/nebula-graph-risk-control-boss-zhipin/ 摘要&#xff1a;在本文中&#xff0c;BOSS 直聘大数据开发工程师主要分享一些他们内部的技术指标和选型&#xff0c;以及很多小伙伴感兴趣的 Dgraph …

Python的boss直聘职位信息数据分析系统

本项目主要利用python技术爬取BOSS直聘网站上的岗位信息&#xff0c;进行对比分析UI设计师与产品经理两个职位的趋势。爬取字段&#xff1a;工作地点&#xff0c;薪资范围&#xff0c;学历要求&#xff0c;工作经验&#xff0c;公司性质等。 模拟登陆BOSS直聘网站&#xff0c;爬…

在线招聘江湖:BOSS直聘向左 猎聘向右

在线招聘行业的“老大之争”还在持续。 作为国内最早互联网化和最早盈利的行业之一&#xff0c;在线招聘行业历经几十年发展&#xff0c;已经跑出了一批具有代表性的玩家。比如瞄准中高端招聘市场的猎聘、凭借营销打法出圈的BOSS直聘&#xff0c;老牌招聘网站前程无忧、智联招…