所有教程由网友发布,仅供参考,请谨慎采纳。科创不对教程的科学性、准确性、可靠性负责。
基于arduino的气压开伞教程
h13 2016-3-12喷气推进
先放成品图以及程序代码压压惊
-------------------------------------------------------------------------------------------------------


图片二次加工20130101_112301.jpg


一张75x50全拿下
下面的四个接口是点火电源和点火头接口
-----------------------------------------------------------------------------------------------------
图片二次加工20130101_112355.jpg




错误指示灯运行效果图(红色贴片,在背面)


-------------------------------------------------------------------------------------------------------
图片二次加工20130101_112408.jpg


四个点火用的接口
---------------------------------------------------------------------------------------------------




图片二次加工20130101_112310.jpg




图片二次加工20130101_112333.jpg



-----------------------------------------------------------------------------------------------------------------
代码(请使用1.0.1的下载器)


<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...
   
   
   
  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.
}
   
void loop()
{
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
  File dataFile = SD.open("datalog.txt", FILE_WRITE);  
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print("Temperature: ");
    dataFile.print(temperature, DEC);
    dataFile.println(" *0.1 deg C");
    dataFile.print("Pressure: ");
    dataFile.print(pressure, DEC);
    dataFile.println(" Pa");
    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());
  Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
   
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print("Temperature: ");
    dataFile.print(temperature, DEC);
    dataFile.println(" *0.1 deg C");
    dataFile.print("Pressure: ");
    dataFile.print(pressure, DEC);
    dataFile.println(" Pa");
    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 i = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
   
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print("Temperature: ");
    dataFile.print(temperature, DEC);
    dataFile.println(" *0.1 deg C");
    dataFile.print("Pressure: ");
    dataFile.print(pressure, DEC);
    dataFile.println(" Pa");
    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 j = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
   
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print("Temperature: ");
    dataFile.print(temperature, DEC);
    dataFile.println(" *0.1 deg C");
    dataFile.print("Pressure: ");
    dataFile.print(pressure, DEC);
    dataFile.println(" Pa");
    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 k = pressure;
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  Serial.print("Temperature: ");
  Serial.print(temperature, DEC);
  Serial.println(" *0.1 deg C");
  Serial.print("Pressure: ");
  Serial.print(pressure, DEC);
  Serial.println(" Pa");
  Serial.println();
   
  if (dataFile) {
    digitalWrite(10,LOW);
    digitalWrite(9,HIGH);
    dataFile.print("Temperature: ");
    dataFile.print(temperature, DEC);
    dataFile.println(" *0.1 deg C");
    dataFile.print("Pressure: ");
    dataFile.print(pressure, DEC);
    dataFile.println(" Pa");
    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);
  } 
  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);
  }
  }
   
  // 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>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
功能:
判断开伞
以10hz采集气压 温度(如果把delay(40)去掉,可以提到17hz,在这里,10hz已经够用,并且方便计时)
将气压 温度记录tf卡
----------------------------------------------------------------------------------------------------------------------------------
接线(代码中间有)



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(建议用绿色贴片)


------------------------------------------------------------------------------------------


原料采购
红色(贴片)LED x1(当然,没人会一个一个的卖)
绿色(贴片)LED x1
mos模块x1 或者IRF540N + 1000欧电阻+指示LED(最好指示灯上串个2k欧的电阻) 各一
TF模块x1
arduino(推荐arduino mini)x1
bmp180 x1


以上为必需品
--------------
以下可自由替换或者发挥


接线端子 2p  x2
xh2.54 2p(如果用万用板的话,就选2.54间距的)
万用版(推荐胶木单面的,大量购买,便宜的很,小量的话就用玻璃纤维的(单双面无所谓),结实)


------------------------------------------------------------------------------------------------


原理
利用气压计的测高功能,当高度下降时,判断开伞


---------------------------------------------------------------------------------------------------


应对防干扰的措施
连续5个气压值的增大,并且最后一个比第一个高50pa才能开伞
---------------------------------------------------------------------------------------------------

可靠性的争议
问:在火箭上升中,流体下强的影响?
答:一般不会的,这个开伞原理是在连续五个增大的气压值后开伞的
  流体压强造成的类似于抽真空的效果,并不会让他开伞,因为那时候气压时变小的
         除非他低高度高速时气压要小于高高度低速时的气压(这种是极其极端的情况,如果满足条件了,估计速度得超音速(超音速还是慢的),这个时候,         火箭最高高度肯定已经超过了气压计的量程,这种情况几乎不可能出现,至于是否会出现,需要计算才能得到)
----------------------------------------------------------------------------------------------------- 图片二次加工20130101_112301.jpg
图片二次加工20130101_112355.jpg
图片二次加工20130101_112408.jpg
图片二次加工20130101_112255.jpg
图片二次加工20130101_112310.jpg
图片二次加工20130101_112333.jpg

[修改于 6 年前 - 2016-03-12 18:57:09]

来自:火箭技术 / 喷气推进严肃内容:教程/课程
 
h13 作者
5年9个月前
1楼
如果你有更好的想法?
但却没有经验?
很简单


首先,从度娘那里要模块的教程
然后,和sd模块的源代码结合起来


我将以我这个航电来举例子


bmp180的教程
XXXXXXXXXXXXXXXXXXXXXXXXX/BLOG_ARTICLE_XXXXXXXXXXM


sd卡的教程
XXXXXXXXXXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXml
将里面的读取某个传感器的值改为教程里面已经弄好的值
然后合二为一


以上步骤建议用版本较低的下载器,不容易error




bmp180的调试代码
/*
  Get pressure and temperature from the BMP085.
  XXXXXXXXXint it out at 9600 baud to serial monitor.
*/
#include <Wire.h>
#define BMP085_ADDRESS 0x77  // I2C address of BMP085
const unsigned char OSS = 0;  // Oversampling Setting
// 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()
{
  XXXXXXXXXgin(9600);
  XXXXXXXgin();
  bmp085Calibration();
}
void loop()
{
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
XXXXXXXXXint("Temperature: ");
  XXXXXXXXXint(temperature, DEC);
  XXXXXXXXXintln(" *0.1 deg C");
  XXXXXXXXXint("Pressure: ");
  XXXXXXXXXint(pressure, DEC);                 这些是重点
  XXXXXXXXXintln(" Pa");
  XXXXXXXXXintln();
  delay(1000);
}
// 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;
  XXXXXXXginTransmission(BMP085_ADDRESS);
  XXXXXXXnd(address);
  Wire.endTransmission();
  XXXXXXXquestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available())
    
  
  return XXXXXXXceive();
}
// 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;
  XXXXXXXginTransmission(BMP085_ADDRESS);
  XXXXXXXnd(address);
  Wire.endTransmission();
  XXXXXXXquestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2)
    
  msb = XXXXXXXceive();
  lsb = XXXXXXXceive();
  return (int) msb<<8 | lsb;
}
// Read the uncompensated temperature value
unsigned int bmp085ReadUT()
{
  unsigned int ut;
  // Write 0x2E into Register 0xF4
  // This requests a temperature reading
  XXXXXXXginTransmission(BMP085_ADDRESS);
  XXXXXXXnd(0xF4);
  XXXXXXXnd(0x2E);
  Wire.endTransmission();
  // Wait at least 4.5ms
  delay(5);
  // Read two bytes from registers 0xF6 and 0xF7
  ut = bmp085ReadInt(0xF6);
  return ut;
}
// Read the uncompensated pressure value
unsigned long bmp085ReadUP()
{
  unsigned char msb, lsb, xlsb;
  unsigned long up = 0;
  // Write 0x34+(OSS<<6) into register 0xF4
  // Request a pressure reading w/ oversampling setting
  XXXXXXXginTransmission(BMP085_ADDRESS);
  XXXXXXXnd(0xF4);
  XXXXXXXnd(0x34 + (OSS<<6));
  Wire.endTransmission();
  // Wait for conversion, delay time dependent on OSS
  delay(2 + (3<<OSS));
  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  XXXXXXXginTransmission(BMP085_ADDRESS);
  XXXXXXXnd(0xF6);
  Wire.endTransmission();
  XXXXXXXquestFrom(BMP085_ADDRESS, 3);
  // Wait for data to become available
  while(Wire.available() < 3)
    
  msb = XXXXXXXceive();
  lsb = XXXXXXXceive();
  xlsb = XXXXXXXceive();
  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
  return up;
}









































































/*
此例子展示如果记录三个模拟引脚数值到SD卡,使用SD库。
          
电路部分
* 模拟引脚使用模拟口0,1,2大家可以根据情况接入模拟传感器,
   如果没有,也可以完成此实验,只不过数值是不停跳动的干扰源。
* SD卡与arduino控制板使用SPI总线连接
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
*/

#include <SD.h>

// CS引脚为pin4,这里也沿用官方默认设置
const int chipSelect = 4;  //设定CS接口

void setup()
{
  XXXXXXXXXgin(9600);  //设置串口通信波特率为9600
  XXXXXXXXXint("Initializing SD card...");  //串口输出数据Initializing SD card...
  pinMode(10, OUTPUT);


  if (!XXXXXgin(chipSelect)) {  //如果从CS口与SD卡通信失败,串口输出信息Card failed, or not present
    XXXXXXXXXintln("Card failed, or not present");                              在这个的后面,可以加入点亮指示灯的操作
    return;
  }
  XXXXXXXXXintln("card initialized.");  //与SD卡通信成功,串口输出信息card initialized.      如果在上面有指示灯点亮这个操作,这里要关掉
}

void loop()
{
  // 定义数组
  String dataString = "";

  // 读取三个传感器值,写入数组
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";
    }
  }
                                                                                                                     绿色部分要删去
  // 打开文件,注意在同一时间只能有一个文件被打开
  // 如果你要打开另一个文件,就需要先关闭前一个
  File dataFile = SD.open("datalog.txt", FILE_WRITE);  

  // 打开datalog.txt文件,读写状态,位置在文件末尾。
  if (dataFile) {
    XXXXXXXXXXXintln(dataString);    把 dataString 改为上面的那个中间的气压 温度等
    XXXXXXXXXXXose();      这个是保存步骤,很重要,一旦删去,就无法保存
    // 数组dataString输出到串口
   XXXXXXXXXintln(dataString);   绿色这部分可以删去
  }  
  // 如果无法打开文件,串口输出错误信息error opening datalog.txt
  else {
    XXXXXXXXXintln("error opening datalog.txt");
  }
}























然后将两个程序合二为一,loop组并入loop组 setup并入setup,注意,千万遗漏
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
2楼
如果说用的是nano,尽量别再加入其他指令了,运行几分钟,芯片就发热了
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
mark42
5年9个月前
3楼
可以!祝成功!
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
4楼
本程序在向sd卡输出的数据格式不是很完美,不利于统计,有待升级
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
5楼
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>
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
6楼
V2.0新功能
改变了数据格式,便于分析与统计
每次开机时自动输出个“temperature    pressure” 这样就可以分清到底是哪次的数据
开伞时自动输出“opened”
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
1703115
5年9个月前
7楼
支持楼主加油!
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
1703115
5年9个月前
8楼
问一句编程前是不是要先导入bmp180的数据库?
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
9楼
引用 1703115:
问一句编程前是不是要先导入bmp180的数据库?
应该不用
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
1703115
5年9个月前
10楼
谢了楼主,另外祝成功
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
LShang001
5年9个月前
11楼
引用 1703115:
问一句编程前是不是要先导入bmp180的数据库?
需要导入库文件
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
h13作者
5年9个月前
12楼
引用 liushang100:
需要导入库文件
中间似乎并没有用到气压计的库文件,上面的两个编程器自带的有
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论
1703115
5年8个月前
13楼
求lz发一个1.0.1版本的下载器,我在网上找不到[s::Q]
回复
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
所属分类
上级专业
同级专业
h13
学者 笔友
文章
40
回复
1844
学术分
1
2014/09/20注册,1 年前活动
暂无简介
%7B%22isDisplay%22%3Atrue%7D
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
插入资源
全部
图片
视频
音频
附件
全部
未使用
已使用
正在上传
空空如也~
上传中..{{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}}
继续创作
删除插入插入
{{forum.displayName}}
{{forum.countThreads}}
篇文章,
{{forum.countPosts}}
条回复
{{forum.description || "暂无简介"}}
ID: {{user.uid}}
学术分隐藏
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

支持的图片格式:jpg, jpeg, png
插入公式
分享回复:{{shareId}}
加载中...
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
加入关注取消关注
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
建议修改
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也