瀏覽代碼

First commit

First commit
casywang 11 年之前
當前提交
c048b76402
共有 8 個文件被更改,包括 729 次插入0 次删除
  1. 22 0
      .gitattributes
  2. 215 0
      .gitignore
  3. 247 0
      HP20x_dev/HP20x_dev.cpp
  4. 101 0
      HP20x_dev/HP20x_dev.h
  5. 66 0
      HP20x_dev/examples/HP20x_demo/HP20x_demo.ino
  6. 34 0
      HP20x_dev/keywords .txt
  7. 21 0
      License.txt
  8. 23 0
      README.md

+ 22 - 0
.gitattributes

@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs     diff=csharp
+*.sln    merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc	 diff=astextplain
+*.DOC	 diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot  diff=astextplain
+*.DOT  diff=astextplain
+*.pdf  diff=astextplain
+*.PDF	 diff=astextplain
+*.rtf	 diff=astextplain
+*.RTF	 diff=astextplain

+ 215 - 0
.gitignore

@@ -0,0 +1,215 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+#############
+## Windows detritus
+#############
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist/
+build/
+eggs/
+parts/
+var/
+sdist/
+develop-eggs/
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg

+ 247 - 0
HP20x_dev/HP20x_dev.cpp

@@ -0,0 +1,247 @@
+/*
+ * File name  : HP20x_dev.cpp
+ * Description: Driver for I2C PRECISION BAROMETER AND ALTIMETER [HP206C]
+ * Author     : Oliver Wang from Seeed studio
+ * Version    : V0.1
+ * Create Time: 2014/04
+ * Change Log :
+*/
+
+/****************************************************************************/
+/***        Include files                                                 ***/
+/****************************************************************************/
+#include "HP20x_dev.h"
+#include <Wire.h>
+#include <Arduino.h>
+
+/****************************************************************************/
+/***       Local Variable                                                 ***/
+/****************************************************************************/
+ HP20x_dev HP20x;
+
+
+/****************************************************************************/
+/***       Class member Functions                                         ***/
+/****************************************************************************/
+/*
+ **@ Function name: HP20x_dev
+ **@ Description: Constructor
+ **@ Input: none
+ **@ OutPut: none
+ **@ Retval: none
+*/
+HP20x_dev::HP20x_dev()
+{
+    OSR_CFG = HP20X_CONVERT_OSR1024;
+    OSR_ConvertTime = 25; 
+}
+
+/*
+ **@ Function name: begin
+ **@ Description: Initialize HP20x_dev
+ **@ Input: none
+ **@ OutPut: none
+ **@ Retval: none
+*/
+void HP20x_dev::begin()
+{
+  Wire.begin();
+  /* Reset HP20x_dev */
+  HP20x.HP20X_IIC_WriteCmd(HP20X_SOFT_RST);
+}
+
+/*
+ **@ Function name: isAvailable
+ **@ Description: Indicate whether it's available
+ **@ Input: none
+ **@ OutPut: none
+ **@ Retval: uchar 
+*/
+uchar HP20x_dev::isAvailable()
+{
+  uchar ret = HP20x.HP20X_IIC_ReadReg(REG_PARA);
+  return ret;
+}
+/*
+ **@ Function name: ReadTemperature
+ **@ Description: Read Temperature from HP20x_dev
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:
+*/
+long HP20x_dev::ReadTemperature(void)
+{
+    uchar Temp;
+    uchar Temp0;
+     
+	HP20X_IIC_WriteCmd(HP20X_WR_CONVERT_CMD|OSR_CFG);	//ADC convert
+ 
+    delay(OSR_ConvertTime);			                    //difference OSR_CFG will be difference OSR_ConvertTime
+    HP20X_IIC_WriteCmd(HP20X_READ_T);      
+    long Temperature = HP20X_IIC_ReadData();
+    return Temperature;		
+}
+
+/*
+ **@ Function name: ReadPressure
+ **@ Description: Read Pressure value
+ **@ Input:
+ **@ OutPut: 
+ **@ Retval: value
+*/
+ 
+long HP20x_dev::ReadPressure(void)
+{
+    HP20X_IIC_WriteCmd(HP20X_WR_CONVERT_CMD|OSR_CFG);
+    delay(OSR_ConvertTime);
+    HP20X_IIC_WriteCmd(HP20X_READ_P);
+    long Pressure = HP20X_IIC_ReadData();             
+    return Pressure;
+} 
+
+/*
+ **@ Function name: ReadAltitude
+ **@ Description: Read Pressure value
+ **@ Input:
+ **@ OutPut: 
+ **@ Retval: value
+*/
+long HP20x_dev::ReadAltitude(void)
+{
+    HP20X_IIC_WriteCmd(HP20X_READ_A);
+    long Altitude = HP20X_IIC_ReadData();   
+    return Altitude;		
+} 
+ 
+/*
+void ReadPressureAndTemperature(void)
+{
+        HP20X_IIC_WriteCmd(HP20X_WR_CONVERT_CMD|OSR_CFG);
+        Timer_Delayxms(OSR_ConvertTime*2);
+        HP20X_IIC_WriteCmd(HP20X_READ_PT);
+        
+        Temperature=HP20X_IIC_ReadData();
+       
+        Pressure=HP20X_IIC_ReadData3byte();       
+}
+
+void IIC_ReadAltitudeAndTemperature(void)
+{
+
+       HP20X_IIC_WriteCmd(HP20X_WR_CONVERT_CMD|OSR_CFG);
+       Timer_Delayxms(OSR_ConvertTime*2);
+       HP20X_IIC_WriteCmd(HP20X_READ_AT);
+        
+        Temperature=HP20X_IIC_ReadData();
+        IIC_ACK();
+        Altitude=HP20X_IIC_ReadData3byte();
+        IIC_NoAck();      
+        IIC_Stop();  
+                   
+}*/
+/****************************************************************************/
+/***       Local Functions                                                ***/
+/****************************************************************************/
+
+/*
+ **@ Function name: HP20X_IIC_WriteCmd
+ **@ Description:
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:
+*/
+void HP20x_dev::HP20X_IIC_WriteCmd(uchar uCmd)
+{		
+	/* Port to arduino */
+	Wire.beginTransmission(HP20X_I2C_DEV_ID);
+	Wire.write(uCmd);
+	Wire.endTransmission();
+}
+
+/*
+ **@ Function name: HP20X_IIC_ReadReg
+ **@ Description:
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:  
+*/
+uchar HP20x_dev::HP20X_IIC_ReadReg(uchar bReg)
+{
+    /* Port to arduino */
+    uchar Temp = 0;
+	
+	/* Send a register reading command */
+    HP20X_IIC_WriteCmd(bReg|HP20X_RD_REG_MODE);	
+	 
+	Wire.requestFrom(HP20X_I2C_DEV_ID, 1);	 
+	while(Wire.available())
+	{
+	    Temp = Wire.read();
+	}
+	 
+	return Temp;
+} 
+/*
+ **@ Function name: HP20X_IIC_WriteReg
+ **@ Description:
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:
+*/
+void HP20x_dev::HP20X_IIC_WriteReg(uchar bReg,uchar bData)
+{       
+	Wire.beginTransmission(HP20X_I2C_DEV_ID);
+	Wire.write(bReg|HP20X_WR_REG_MODE);
+	Wire.write(bData);
+	Wire.endTransmission();
+}
+
+
+/*
+ **@ Function name: HP20X_IIC_ReadData
+ **@ Description:
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:
+*/
+ulong HP20x_dev::HP20X_IIC_ReadData(void)
+{                        
+	/* Port to arduino */	 
+	ulong Temp = HP20X_IIC_ReadData3byte(); 
+	return Temp;
+}
+
+/*
+ **@ Function name: HP20X_IIC_ReadData3byte
+ **@ Description:
+ **@ Input:
+ **@ OutPut:
+ **@ Retval:
+*/
+ulong HP20x_dev::HP20X_IIC_ReadData3byte(void)
+{	
+	ulong TempData = 0;
+	ulong tmpArray[3]={0};
+	int cnt = 0;
+	
+	/* Require three bytes from slave */
+	Wire.requestFrom(HP20X_I2C_DEV_ID, 3);      
+
+    while(Wire.available())     // slave may send less than requested
+    { 
+      uchar c = Wire.read();    // receive a byte as character	  	  
+	  tmpArray[cnt] = (ulong)c;
+	  cnt++;
+	}
+	
+	/* MSB */
+	TempData = tmpArray[0]<<16 | tmpArray[1]<<8 | tmpArray[2];
+	if(TempData&0x800000)
+    {
+	    TempData|=0xff000000;
+	}
+	return TempData;
+} 
+
+
+/**************************************END OF FILE**************************************/

+ 101 - 0
HP20x_dev/HP20x_dev.h

@@ -0,0 +1,101 @@
+/*
+ * File name  : HP20x_dev.h
+ * Description: Driver for I2C PRECISION BAROMETER AND ALTIMETER [HP206C]
+ * Author     : Oliver Wang from Seeed studio
+ * Version    : V0.1
+ * Create Time: 2014/04
+ * Change Log :
+*/
+#ifndef _HP20X_DEV_H
+#define _HP20X_DEV_H
+/****************************************************************************/
+/***        Including Files                                               ***/
+/****************************************************************************/
+#include <Wire.h>
+#include <Arduino.h>
+/****************************************************************************/
+/***        Macro Definitions                                             ***/
+/****************************************************************************/
+typedef unsigned int    uint;
+typedef unsigned char   uchar;
+typedef unsigned long   ulong;
+
+#define HP20X_I2C_DEV_ID       (0xEC)>>1    //CSB PIN is VDD level(address is 0x76)
+#define HP20X_I2C_DEV_ID2      (0XEE)>>1    //CSB PIN is GND level(address is 0x77)
+#define HP20X_SOFT_RST         0x06
+#define HP20X_WR_CONVERT_CMD   0x40
+#define HP20X_CONVERT_OSR4096  0<<2
+#define HP20X_CONVERT_OSR2048  1<<2
+#define HP20X_CONVERT_OSR1024  2<<2
+#define HP20X_CONVERT_OSR512   3<<2
+#define HP20X_CONVERT_OSR256   4<<2
+#define HP20X_CONVERT_OSR128   5<<2
+
+#define HP20X_READ_P           0x30   //read_p command
+#define HP20X_READ_A           0x31   //read_a command
+#define HP20X_READ_T           0x32   //read_t command
+#define HP20X_READ_PT          0x10   //read_pt command
+#define HP20X_READ_AT          0x11   //read_at command
+#define HP20X_READ_CAL		   0X28	  //RE-CAL ANALOG
+
+#define HP20X_WR_REG_MODE      0xC0
+#define HP20X_RD_REG_MODE      0x80
+
+#define ERR_WR_DEVID_NACK       0x01    
+#define ERR_RD_DEVID_NACK       0x02    
+#define ERR_WR_REGADD_NACK      0x04   
+#define ERR_WR_REGCMD_NACK      0x08   
+#define ERR_WR_DATA_NACK        0x10     
+#define ERR_RD_DATA_MISMATCH    0x20 
+
+#define I2C_DID_WR_MASK         0xFE
+#define I2C_DID_RD_MASK         0x01
+
+#define T_WIN_EN                0X01
+#define PA_WIN_EN               0X02
+#define T_TRAV_EN               0X04
+#define PA_TRAV_EN              0X08
+#define PA_RDY_EN               0X20
+#define T_RDY_EN                0X10
+
+#define T_WIN_CFG               0X01
+#define PA_WIN_CFG              0X02
+#define PA_MODE_P               0X00
+#define PA_MODE_A               0X40
+
+#define T_TRAV_CFG              0X04
+
+#define OK_HP20X_DEV            0X80		//HP20x_dev successfully initialized
+#define REG_PARA                0X0F        //Status register
+
+/****************************************************************************/
+/***        Class Definitions                                             ***/
+/****************************************************************************/
+class HP20x_dev : public TwoWire
+{
+  /* Public variables and functions */
+  public:
+    uchar OSR_CFG;
+	uint  OSR_ConvertTime;
+    /* Constructor */
+    HP20x_dev();	
+	void begin();
+	uchar isAvailable();
+	
+	/* Read sensor data */
+	long ReadTemperature(void);
+	long ReadPressure(void);
+	long ReadAltitude(void);
+	
+  /* Private variables and functions */
+  private:
+    /* Write a command to HP20x */
+	void HP20X_IIC_WriteCmd(uchar uCmd);	
+	/* Read register value */
+	uchar HP20X_IIC_ReadReg(uchar bReg);	
+	void HP20X_IIC_WriteReg(uchar bReg,uchar bData);	 	
+	ulong HP20X_IIC_ReadData(void);
+	ulong HP20X_IIC_ReadData3byte(void);
+};
+extern HP20x_dev HP20x;
+#endif

+ 66 - 0
HP20x_dev/examples/HP20x_demo/HP20x_demo.ino

@@ -0,0 +1,66 @@
+/*
+ * Demo name   : HP20x_dev demo 
+ * Usage       : I2C PRECISION BAROMETER AND ALTIMETER [HP206C hopeRF] 
+ * Author      : Oliver Wang from Seeed Studio
+ * Version     : V0.1
+*/
+
+#include <HP20x_dev.h>
+#include "Arduino.h"
+#include "Wire.h" 
+
+unsigned char ret = 0;
+
+void setup()
+{  
+  Serial.begin(9600);        // start serial for output
+  
+  Serial.println("****HP20x_dev demo by seeed studio****\n");
+  
+  /* Power up,delay 150ms,until voltage is stable */
+  delay(150);
+  /* Reset HP20x_dev */
+  HP20x.begin();
+  delay(100);
+  
+  /* Determine HP20x_dev is available or not */
+  ret = HP20x.isAvailable();
+  if(OK_HP20X_DEV == ret)
+  {
+    Serial.println("HP20x_dev is available.\n");    
+  }
+  else
+  {
+    Serial.println("HP20x_dev isn't available.\n");
+  }
+  
+}
+ 
+
+void loop()
+{
+    char display[40];
+    if(OK_HP20X_DEV == ret)
+    {
+      long Temper = HP20x.ReadTemperature();
+	  Serial.println("Temper:");
+	  float t = Temper/100.0;
+	  Serial.print(t);
+	  Serial.println("\n");
+ 
+      long Pressure = HP20x.ReadPressure();
+	  Serial.println("Pressure:");
+	  t = Pressure/100.0;
+	  Serial.print(t);
+	  Serial.println("\n");
+	  
+	  long Altitude = HP20x.ReadAltitude();
+	  Serial.println("Altitude:");
+	  t = Altitude/100.0;
+	  Serial.print(t);
+	  Serial.println("\n");
+	  
+      delay(1000);
+    }
+}
+ 

+ 34 - 0
HP20x_dev/keywords .txt

@@ -0,0 +1,34 @@
+#######################################
+# Syntax Coloring Map HD20x_dev
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+HD20x_dev	KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+HP20X_IIC_WriteCmd	KEYWORD2
+HP20X_IIC_ReadReg	KEYWORD2
+ReadTemperature	        KEYWORD2
+ReadPressure            KEYWORD2
+ReadAltitude            KEYWORD2
+Hex_to_Dec              KEYWORD2
+HP20X_IIC_ReadData	KEYWORD2
+HP20X_IIC_ReadData3byte	KEYWORD2
+HP20X_IIC_WriteReg	KEYWORD2
+isAvailable           KEYWORD2
+begin               KEYWORD2 
+
+#######################################
+# Instances (KEYWORD2)
+#######################################
+HP20x KEYWORD2
+TwoWire KEYWORD2
+#######################################
+# Constants (LITERAL1)
+#######################################
+ 

+ 21 - 0
License.txt

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Seeed Technology Inc.
+
+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.

+ 23 - 0
README.md

@@ -0,0 +1,23 @@
+Grove_barometer HP20x
+------------
+  This is a driver for Grove_barometer HP20x(high accuracy and waterproof).
+  DataSheet of this sensor:(http://www.hoperf.cn/upload/sensor/HP206C_Datasheet_v1.1.pdf)
+### Usage
+    1.Git clone this resp to your arduino IDE's lib directory.
+	2.Open the demo "HP20x_dev"
+    
+----
+
+This software is written by Oliver Wang (long.wang@seeedstudio.com) for seeed studio<br>
+and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.<br>
+
+
+Seeed Studio is an open hardware facilitation company based in Shenzhen, China. <br>
+Benefiting from local manufacture power and convenient global logistic system, <br>
+we integrate resources to serve new era of innovation. Seeed also works with <br>
+global distributors and partners to push open hardware movement.<br>
+
+[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Seeed-Studio/mesh_bee/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
+
+[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Mesh_Bee)](https://github.com/igrigorik/ga-beacon)
+