BMP280 arduino调试

2024-03-16 22:44
文章标签 调试 arduino bmp280

本文主要是介绍BMP280 arduino调试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

终于成功了。

#include <SPI.h>
//定义数据类型
#define s32_t long signed int
#define u32_t long unsigned int
#define u16_t unsigned short
#define s16_t signed short
// 定义从设备选择引脚
const int chipSelectPin = 10;
//=============定义BMP280寄存器===========///
unsigned int  temp_xlsb;  
unsigned int  temp_lsb;
unsigned int  temp_msb;
unsigned int  press_xlsb;
unsigned int  press_lsb;
unsigned int  press_msb;
u16_t dig_t1_lsb;
u16_t dig_t1_msb;
s16_t dig_t2_lsb;
s16_t dig_t2_msb;
s16_t dig_t3_lsb;
s16_t dig_t3_msb;
u32_t dig_t1;
s32_t dig_t2;
s32_t dig_t3;
s32_t temp;
s32_t temp_comp;
u16_t bmp_status;
byte  addr_temp_xlsb = 0xFC;  
byte  addr_temp_lsb = 0xFB;
byte  addr_temp_msb = 0xFA;
byte  addr_press_xlsb = 0xF9;
byte  addr_press_lsb = 0xF8;
byte  addr_press_msb = 0xF7;
byte  addr_dig_t1_lsb = 0x88;
byte  addr_dig_t1_msb = 0x89;
byte  addr_dig_t2_lsb = 0x8A;
byte  addr_dig_t2_msb = 0x8B;
byte  addr_dig_t3_lsb = 0x8C;
byte  addr_dig_t3_msb = 0x8D;
byte  addr_status = 0xF3;
byte  addr_ctrl = 0xF4;
byte  addr_timestandby = 0xF5;
byte  addr_id = 0xd0;
s32_t t_fine;
void setup() {// 初始化串口通信Serial.begin(115200);// 配置从设备选择引脚pinMode(chipSelectPin, OUTPUT);// 初始化 SPISPI.begin();SPI.setClockDivider(SPI_CLOCK_DIV8);  // 设置时钟分频,可根据需要调整//===============获得BMP280参数==================//dig_t1_lsb = readRegister(addr_dig_t1_lsb,1);dig_t1_msb = readRegister(addr_dig_t1_msb,1);dig_t2_lsb = readRegister(addr_dig_t2_lsb,1);dig_t2_msb = readRegister(addr_dig_t2_msb,1);dig_t3_lsb = readRegister(addr_dig_t3_lsb,1);dig_t3_msb = readRegister(addr_dig_t3_msb,1);bmp_status = readRegister(addr_status,1);dig_t1 = ((u32_t)dig_t1_msb << 8) | dig_t1_lsb;dig_t2 = ((s32_t)dig_t2_msb << 8) | dig_t2_lsb;dig_t3 = ((s32_t)dig_t3_msb << 8) | dig_t3_lsb;//===============获取BMP280器件ID==================//byte device_id = readRegister(addr_id,1);Serial.print("device_id = ");Serial.println(device_id, HEX);   
//===============设置TIME_STANDBY采样时间==================//byte timestandby = readRegister(addr_timestandby,0x01);Serial.print("timestandby = ");Serial.println(timestandby, HEX); timestandby=timestandby |  (0x001 << 5) ;writeRegister(addr_timestandby,timestandby);
//===============设置BMP280为连续模式==================//byte ctrl_meas = readRegister(addr_ctrl,1);Serial.print("ctrl_meas = ");Serial.println(ctrl_meas, BIN);   writeRegister(addr_ctrl,0x03);//===============获得当前状态==================//ctrl_meas = readRegister(addr_ctrl,1);Serial.print("ctrl_meas = ");Serial.println(ctrl_meas, BIN);  //===============打印BMP280校准参数==================//Serial.print("dig_t1 = ");Serial.println(dig_t1, HEX);Serial.print("dig_t2 = ");Serial.println(dig_t2, HEX);Serial.print("dig_t3 = ");Serial.println(dig_t3, HEX);   Serial.print("bmp_status = ");Serial.println(bmp_status, BIN);  
}void loop() {
//  writeRegister(addr_ctrl,0x01);
//===============获得全部数据==================//temp_xlsb = readRegister(addr_temp_xlsb,1);temp_lsb = readRegister(addr_temp_lsb,1);temp_msb = readRegister(addr_temp_msb,1);press_xlsb = readRegister(addr_press_xlsb,1);press_lsb = readRegister(addr_press_lsb,1);press_msb = readRegister(addr_press_msb,1);Serial.println(addr_temp_xlsb, HEX);Serial.println(addr_temp_lsb, HEX);Serial.println(addr_temp_msb, HEX);
//================计算温度值==================//  temp = (u32_t)temp_msb << 12 | (u32_t)temp_lsb << 4 | (u32_t)temp_xlsb >> 4;temp_comp = bmp280_compensate(temp);float temp_comp_float = temp_comp/100.00;
//================串口打印温度值==================//  Serial.print("Composate Temprature is: ");Serial.println(temp_comp, DEC);Serial.print(temp_comp_float);Serial.println("℃");// 延时等待delay(2000);
}
unsigned int readRegister(byte thisRegister, int bytesToRead) {byte inByte = 0;           // incoming byte from the SPIunsigned int result = 0;   // result to returnbyte dataToSend = thisRegister;digitalWrite(chipSelectPin, LOW);// send the device the register you want to read:SPI.transfer(dataToSend);// send a value of 0 to read the first byte returned:result = SPI.transfer(0x00);// decrement the number of bytes left to read:bytesToRead--;// if you still have another byte to read:if (bytesToRead > 0) {// shift the first byte left, then get the second byte:result = result << 8;inByte = SPI.transfer(0x00);// combine the byte you just got with the previous one:result = result | inByte;// decrement the number of bytes left to read:bytesToRead--;}// take the chip select high to de-select:digitalWrite(chipSelectPin, HIGH);// return the result:return (result);
}
void writeRegister(byte thisRegister, byte thisValue) {// take the chip select low to select the device:digitalWrite(chipSelectPin, LOW);SPI.transfer(thisRegister); //Send register locationSPI.transfer(thisValue);  //Send value to record into register// take the chip select high to de-select:digitalWrite(chipSelectPin, HIGH);
}s32_t bmp280_compensate(s32_t adc_t)
{s32_t var1,var2,t;var1 = ((((adc_t>>3) - ((s32_t)dig_t1<<1))) * ((s32_t)dig_t2)) >>11;var2 = (((((adc_t>>4) - ((s32_t)dig_t1)) * ((adc_t>>4) - ((s32_t)dig_t1)))>>12) * ((s32_t)dig_t3)) >>14;t_fine = var1 + var2;t = (t_fine *5 +128) >>8;return t;
}

这篇关于BMP280 arduino调试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/816965

相关文章

ASIO网络调试助手之一:简介

多年前,写过几篇《Boost.Asio C++网络编程》的学习文章,一直没机会实践。最近项目中用到了Asio,于是抽空写了个网络调试助手。 开发环境: Win10 Qt5.12.6 + Asio(standalone) + spdlog 支持协议: UDP + TCP Client + TCP Server 独立的Asio(http://www.think-async.com)只包含了头文件,不依

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

vscode中文乱码问题,注释,终端,调试乱码一劳永逸版

忘记咋回事突然出现了乱码问题,很多方法都试了,注释乱码解决了,终端又乱码,调试窗口也乱码,最后经过本人不懈努力,终于全部解决了,现在分享给大家我的方法。 乱码的原因是各个地方用的编码格式不统一,所以把他们设成统一的utf8. 1.电脑的编码格式 开始-设置-时间和语言-语言和区域 管理语言设置-更改系统区域设置-勾选Bata版:使用utf8-确定-然后按指示重启 2.vscode

arduino ide安装详细步骤

​ 大家好,我是程序员小羊! 前言: Arduino IDE 是一个专为编程 Arduino 微控制器设计的集成开发环境,使用起来非常方便。下面将介绍如何在不同平台上安装 Arduino IDE 的详细步骤,包括 Windows、Mac 和 Linux 系统。 一、在 Windows 上安装 Arduino IDE 1. 下载 Arduino IDE 打开 Arduino 官网

起点中文网防止网页调试的代码展示

起点中文网对爬虫非常敏感。如图,想在页面启用调试后会显示“已在调试程序中暂停”。 选择停用断点并继续运行后会造成cpu占用率升高电脑卡顿。 经简单分析网站使用了js代码用于防止调试并在强制继续运行后造成电脑卡顿,代码如下: function A(A, B) {if (null != B && "undefined" != typeof Symbol && B[Symbol.hasInstan

php 7之PhpStorm + Nginx + Xdebug运行调试

操作环境: windows PHP 7.1.10 PhpStorm-2017.2.4 Xdebug 2.5.4 Xdebug helper 1.6.1 nginx-1.12.2 注意查看端口占用情况 netstat -ano //查看所以端口netstat -aon|findstr "80" //查看指定端口占用情况 比如80端口查询情况 TCP 0.0.0.0:8

【2025】基于Python的空气质量综合分析系统的设计与实现(源码+文档+调试+答疑)

博主介绍:     ✌我是阿龙,一名专注于Java技术领域的程序员,全网拥有10W+粉丝。作为CSDN特邀作者、博客专家、新星计划导师,我在计算机毕业设计开发方面积累了丰富的经验。同时,我也是掘金、华为云、阿里云、InfoQ等平台的优质作者。通过长期分享和实战指导,我致力于帮助更多学生完成毕业项目和技术提升。 技术范围:     我熟悉的技术领域涵盖SpringBoot、Vue、SSM、HLMT

VS Code 调试go程序的相关配置说明

用 VS code 调试Go程序需要在.vscode/launch.json文件中增加如下配置:  // launch.json{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information,