AM2321 Temperature and Humidity Sensor mbed library Example

Dependencies:   AM2321 mbed

Aosong Guangzhou Electronics の温湿度センサ「AM2321」の接続サンプルです。 AM2321は1-WireとI2Cの2種類のI/Fを持ちますが、このサンプルではI2Cで接続しています。

/media/uploads/tomozh/am2321_1.png /media/uploads/tomozh/p5061476.jpg /media/uploads/tomozh/140506_com6-9600baud_-_tera_term_vt_01.png

Import libraryAM2321

AM2321 Temperature and Humidity Sensor mbed library

Files at this revision

API Documentation at this revision

Comitter:
tomozh
Date:
Tue May 06 10:21:20 2014 +0000
Child:
1:deaae66ed978
Commit message:
1st release

Changed in this revision

AM2321.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AM2321.lib	Tue May 06 10:21:20 2014 +0000
@@ -0,0 +1,1 @@
+AM2321#d1c0dbf5e5a6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 06 10:21:20 2014 +0000
@@ -0,0 +1,56 @@
+/*
+    AM2321 Temperature and Humidity Sensor
+    mbed Sample code
+    
+    Copyright (c) 2014 tomozh <tomozh@gmail.com>
+    
+    This software is released under the MIT License.
+    http://opensource.org/licenses/mit-license.php
+
+    Last update : 2014/05/06
+*/
+
+#include "mbed.h"
+#include "AM2321.h"
+
+Serial pc(USBTX, USBRX);    // Tx, Rx
+AM2321 am2321(p28, p27);    // SDA, SCL
+DigitalOut led1(LED1);
+
+int main()
+{
+    uint16_t count = 0;
+   
+    while(1)
+    {
+        led1 = !led1;
+
+        if(am2321.poll())
+        {
+            pc.printf(
+                  ":%05u,%.1f,%.1f\n"
+                , count++
+                , am2321.getTemperature()
+                , am2321.getHumidity()
+            );
+        }
+
+        wait(0.5);
+    }
+    
+    /*
+        output
+        -----------------------
+        :01100,23.7,38.1
+        :01101,23.6,38.0
+        :01102,23.7,38.1
+        :01103,23.6,38.0
+        :01104,23.7,38.0
+        :01105,23.7,38.1
+        :01106,23.6,38.0
+        :01107,23.7,38.0
+        :01108,23.7,38.0
+        :01109,23.6,38.0
+        :01110,23.7,38.0
+    */  
+}