码迷,mamicode.com
首页 > 其他好文 > 详细

Arduino Nano 读取ADS1100实例

时间:2015-03-18 10:18:31      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:

利用Arduino Nano的wire库可以很方便对ADS1100进行设置和读取转换后的数据。

/*
*  Arduino reads ADS1100  I2C 16bit diff ADC
*/  

/* 
    SDA  ==>  analog 4  PC4
    SCL  ==>  analog 5  PC5

    set register:  STBY   0  0    SC    DR1  DR0 PGA1  PGA0
          default   1     0  0    0      1    1    0     0      0x8C
          i want    1     0  0    0      1    1    0     0
                    ign   0  0   con      8SPS      GAIN 1
    STBY, only for single mode to start conversion
    SC    1= single , 0=continuous 
    DR1:0    datarate 00 = 128sps, 12 bit      -2048 to  2047
                      01 =  32sps, 14          -8192 to  9191
                      10 =  16sps, 15         -16384 to 16383
                      11 =   8sps, 16         -32768 to 32767  
    PGA1:0  Gain      00 = *1, 01 = *2, 10 = *4, 11 = *8  
*/

#include <Wire.h>

//  AD0 1001 000 r/w      AD1 1001 001 r/w ; r=1. w=0     
#define AD0 B1001000         // ADS1100 地址0x48
#define options B10001100 // 0x8C-- 8SPS,16位精度,1倍放大 uint8_t reg = 0; int16_t result = 0; void setup() { Serial.begin(9600); Wire.begin(); Wire.beginTransmission(AD0); Wire.write(options); Wire.endTransmission(); } void loop() { Wire.beginTransmission(AD0); Wire.requestFrom(AD0, 3); // 返回 3个 bytes
      while(Wire.available()) {      
        result = Wire.read();     
        result = result << 8;
        result +=  Wire.read();
        reg = Wire.read();
        Serial.print(result, DEC); 
        Serial.println("\t");
        Serial.print((3300.00 * result)/ 0x7FFF, 2);//ADS1100接3.3V电源,如果接5V要将3300.00改为5000.00
        Serial.println(" mV");     
  }
  Wire.endTransmission();
  delay(100);
}

 

Arduino Nano 读取ADS1100实例

标签:

原文地址:http://www.cnblogs.com/qiufeng2014/p/4346255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!