/*
* LM35DZ Temperature sensor using PCF8591/MCP3002
*
http://henrysbench.capnfatz.com/henrys-bench/arduino-voltage-measurements/pcf8591-adda-converter-arduino-tutorial-1-a-simple-analog-measurement/
*
* MPC3002
LM35ZD WeMos
*
VCC
---- 3.3V
*
CLK
---- D5(SCK)
*
Dout
---- D6(MISO)
*
Din
---- D7(MOSI)
*
CS
---- D8(CS)
* CH0 --- OUT
*
VCC ---- 3.3V
*
GND ---- GND
*
* PCF8591
LM35ZD WeMos
*
VCC
---- 3.3V
*
SCL
---- D1(SCL)
*
SDA
---- D2(SDA)
*
A0
---- GND
*
A1
---- GND
*
A2
---- GND
*
VSS
---- GND
*
VDD
---- 3.3V
*
Vref
---- 3.3V
* AINT0 --- OUT
*
VCC ---- 3.3V
*
GND ---- GND
*/
#include <MCP3002.h>
#include <SPI.h>
#include "Wire.h"
#define PCF8591 (0x48) // I2C bus address
#define AIn0 0x00
#define RefV 3.28
MCP3002 adc(15); // CS=15
int RawValue0 = 0;
float Voltage = 0.0;
float temp_c = 0; // 摂氏値( ℃ )
void setup()
{
Wire.begin(4,5); // sda=4, scl=5
adc.begin();
Serial.begin(9600);
}
void loop()
{
Wire.beginTransmission(PCF8591); // Start your
PCF8591
Wire.write(AIn0); // Tell it to make an Analog
Measurement
Wire.endTransmission(); //
Wire.requestFrom(PCF8591, 2); // Get the Measured
Data
RawValue0=Wire.read(); // PCF8591 (Dummy)
RawValue0=Wire.read(); // PCF8591
Voltage = (RawValue0 * RefV )/ 255.0;
temp_c = Voltage * 100;
// Serial.print("Raw ADC Value = ");
// Serial.print(RawValue0);
// Serial.print(" Voltage[PCF8591] = ");
// Serial.print(Voltage);
Serial.print(" temp_c[PCF8591] = ");
Serial.print(temp_c);
RawValue0=adc.analogRead(0); // MCP3002
Voltage = (RawValue0 * RefV )/ 1023.0;
temp_c = Voltage * 100;
// Serial.print(" Voltage[MCP3002] = ");
// Serial.print(Voltage);
Serial.print(" temp_c[MCP3002] = ");
Serial.println(temp_c);
delay(500);
}
|