已屏蔽 原因:{{ notice.reason }}已屏蔽
{{notice.noticeContent}}
~~空空如也
V2.0版本
<code class="lang-text">/*
arduino到bmp085
 SDA--A4
 SCL--A5
 GND--GND
 VIN--3.3V(切记是3.3V,不是5V或者VIN,切记!!!)
  
 arduino--SD(TF)模块
 5V--D7
 CS--D4
 MOSI--D11
 SCK--D13
 MISO--D12
 GND--GND
  
 arduino
 错误指示灯--D10
 运行指示灯--D9
  
 arduino--MOS模块
 GND--GND
 D8--SIG
  
 不反对用于利润小于所有成本(包括一小时20的正常焊工的工资)的20%及以下的商业活动
 转载请注明来源为 bbs.kechuang.org
 KC—h13
 */
#include <sd.h>
#include <wire.h>
 
#define BMP085_ADDRESS 0x77  // I2C address of BMP085
 
const unsigned char OSS = 0;  // Oversampling Setting
const int chipSelect = 4;
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
 
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
 
short temperature;
long pressure;
 
void setup()
{
  pinMode(7,OUTPUT);
  digitalWrite(7,HIGH);
  pinMode(8,OUTPUT);
  digitalWrite(8,LOW);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  Serial.begin(9600);
  Wire.begin();
  bmp085Calibration();
  Serial.print("Initializing SD card...");  //串口输出数据Initializing SD card...
  Serial.print("temperature     pressure"); 
 
 
  if (!SD.begin(chipSelect)) {  //如果从CS口与SD卡通信失败,串口输出信息Card failed, or not present
    Serial.println("Card failed, or not present");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
    return;
  }
  digitalWrite(10,LOW);
  digitalWrite(9,HIGH);
  Serial.println("card initialized.");  //与SD卡通信成功,串口输出信息card initialized.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);  
  if (dataFile) {
    dataFile.println("temperature     pressure");
 
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
  dataFile.close();
}
 
void loop()
{
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  int aa = temperature / 10;
  Serial.print(aa, DEC);
  Serial.print("     ");
 
  Serial.print(pressure, DEC);
 
  Serial.println();
  File dataFile = SD.open("datalog.txt", FILE_WRITE);  
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print(aa,DEC);
 
 
    dataFile.print("     ");
    dataFile.print(pressure, DEC);
 
    dataFile.println();
    Serial.println("datalog.txt has printed");// 串口输出datalog.txt has printed
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
 
 
  delay(40);
  int h = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  int bb = temperature / 10;
  Serial.print(bb, DEC);
  Serial.print("     ");
 
  Serial.print(pressure, DEC);
 
  Serial.println();
 
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print(bb,DEC);
 
 
    dataFile.print("     ");
    dataFile.print(pressure, DEC);
 
    dataFile.println();
 
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
 
 
  delay(40);
  int i = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  int cc = temperature / 10;
  Serial.print(cc, DEC);
  Serial.print("     ");
 
  Serial.print(pressure, DEC);
 
  Serial.println();
 
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print(cc,DEC);
 
 
    dataFile.print("     ");
    dataFile.print(pressure, DEC);
 
    dataFile.println();
 
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
 
 
  delay(40);
  int j = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  int dd = temperature / 10;
  Serial.print(dd, DEC);
  Serial.print("     ");
 
  Serial.print(pressure, DEC);
 
  Serial.println();
 
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print(dd,DEC);
 
 
    dataFile.print("     ");
    dataFile.print(pressure, DEC);
 
    dataFile.println();
 
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
 
 
  delay(40);
  int k = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  int ee = temperature / 10;
  Serial.print(ee, DEC);
  Serial.print("     ");
 
  Serial.print(pressure, DEC);
 
  Serial.println();
 
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print(ee,DEC);
 
 
    dataFile.print("     ");
    dataFile.print(pressure, DEC);
 
    dataFile.println();
 
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    Serial.println("error opening datalog.txt");
    digitalWrite(10,HIGH);
    digitalWrite(9,LOW);
  } 
  dataFile.close();
  Serial.println("saved");//串口输出saved
  delay(40);
  int l = pressure;
  if((h<i) && (i<j) (j<k) (k<l) (l>h + 50)){
    digitalWrite(8,HIGH);
    File dataFile = SD.open("datalog.txt", FILE_WRITE);  
    if (dataFile) {
      dataFile.println("OPENED");
 
    }  
    // 如果无法打开文件,串口输出错误信息error opening datalog.txt
    else {
      Serial.println("error opening datalog.txt");
      digitalWrite(10,HIGH);
      digitalWrite(9,LOW);
    } 
  }
}
 
// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
  ac1 = bmp085ReadInt(0xAA);
  ac2 = bmp085ReadInt(0xAC);
  ac3 = bmp085ReadInt(0xAE);
  ac4 = bmp085ReadInt(0xB0);
  ac5 = bmp085ReadInt(0xB2);
  ac6 = bmp085ReadInt(0xB4);
  b1 = bmp085ReadInt(0xB6);
  b2 = bmp085ReadInt(0xB8);
  mb = bmp085ReadInt(0xBA);
  mc = bmp085ReadInt(0xBC);
  md = bmp085ReadInt(0xBE);
}
 
// Calculate temperature given ut.
// Value returned will be in units of 0.1 deg C
short bmp085GetTemperature(unsigned int ut)
{
  long x1, x2;
 
  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
  x2 = ((long)mc << 11)/(x1 + md);
  b5 = x1 + x2;
 
  return ((b5 + 8)>>4); 
}
 
// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up)
{
  long x1, x2, x3, b3, b6, p;
  unsigned long b4, b7;
 
  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<<oss) + 2)>>2;
 
  // Calculate B4
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
 
  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1) b4;   else     p="(b7/b4)<<1;"   x1="(p">>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
  p += (x1 + x2 + 3791)>>4;
 
  return p;
}
 
// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
  unsigned char data;
 
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
 
  Wire.requestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available())
    
 
  return Wire.read();
}
 
// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
  unsigned char msb, lsb;
 
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
 
  Wire.requestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2)        msb="Wire.read();"   lsb="Wire.read();"   return (int) msb<<8 | lsb; } read the uncompensated temperature value unsigned int bmp085readut() {   unsigned ut;    write 0x2e into register 0xf4 this requests a reading   wire.begintransmission(bmp085_address);   wire.write(0xf4);   wire.write(0x2e);   wire.endtransmission(); wait at least 4.5ms   delay(5); two bytes from registers 0xf6 and 0xf7   ut="bmp085ReadInt(0xF6);" pressure long bmp085readup() char msb, lsb, xlsb; up="0;" 0x34+(oss<<6) request w oversampling setting   wire.write(0x34 + (oss<<6)); for conversion, delay time dependent on oss   delay(2 (3<<oss)); (msb), (lsb), 0xf8 (xlsb)   wire.write(0xf6);   wire.requestfrom(bmp085_address, 3); data to become available   while(wire.available() < 3)   xlsb="Wire.read();"   up="(((unsigned" long) msb << 16) ((unsigned lsb 8) (unsigned xlsb)>> (8-OSS);
 
  return up;
}</2)></1)></oss)></i)></wire.h></sd.h></code>
文号 / 813881

名片发私信
学术分 1
总主题 41 帖总回复 1854 楼拥有证书:学者 笔友
注册于 2014-09-20 09:27最后登录 2022-09-14 22:14
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:河南

个人简介

暂未填写
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

插入资源
全部
图片
视频
音频
附件
全部
未使用
已使用
正在上传
空空如也~
上传中..{{f.progress}}%
处理中..
上传失败,点击重试
等待中...
{{f.name}}
空空如也~
(视频){{r.oname}}
{{selectedResourcesId.indexOf(r.rid) + 1}}
处理中..
处理失败
插入表情
我的表情
共享表情
Emoji
上传
注意事项
最大尺寸100px,超过会被压缩。为保证效果,建议上传前自行处理。
建议上传自己DIY的表情,严禁上传侵权内容。
点击重试等待上传{{s.progress}}%处理中...已上传,正在处理中
空空如也~
处理中...
处理失败
加载中...
草稿箱
加载中...
此处只插入正文,如果要使用草稿中的其余内容,请点击继续创作。
{{fromNow(d.toc)}}
{{getDraftInfo(d)}}
标题:{{d.t}}
内容:{{d.c}}
继续创作
删除插入插入
插入公式
评论控制
加载中...
文号:{{pid}}
加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}
ID: {{user.uid}}