/*
* Test Program for Analog Read
*
* MPC3002 Arduino
* VCC ---- 5V
* CLK ---- D13(SCK)
* Dout ---- D12(MISO)
* Din ---- D11(MOSI)
* CS ---- D10(SS)
*
* PCF8591 Arduino
* VCC ---- 5V
* SCL ---- SCL
* SDA ---- SDA
* A0 ---- GND
* A1 ---- GND
* A2 ---- GND
* VSS ---- GND
* VDD ---- 5V
* Vref ---- 5V
*/
#include <MCP3002.h>
#include <SPI.h>
#include "Wire.h"
MCP3002 adc(10);
#define A_inPin A0 // アナログ入力ピン番号
#define RefV 5.03
#define PCF8591 (0x48) // I2C bus address
#define AIn0 0x00
float RawValue; // アナログ入力値
float Voltage;
void setup() {
adc.begin();
Wire.begin();
Serial.begin(9600);
}
void loop() {
RawValue = analogRead( A_inPin ); // Analog Port
Voltage = ((RefV * RawValue) / 1023.0);
Serial.print("[A0 PORT]");
Serial.print(RawValue);
Serial.print("-");
Serial.print(Voltage);
Serial.print(" ");
RawValue=adc.analogRead(0); // MPC3002
Voltage = (RefV * RawValue)/ 1023.0;
Serial.print("[MPC3002]");
Serial.print(RawValue);
Serial.print("-");
Serial.print(Voltage);
Serial.print(" ");
Wire.beginTransmission(PCF8591); // Start your
PCF8591
Wire.write(AIn0); // Tell it to make an Analog
Measurement
Wire.endTransmission(); //
Wire.requestFrom(PCF8591, 1); // Get the Measured
Data
RawValue=Wire.read();
Voltage = (RefV * RawValue)/ 255.0;
Serial.print("[PCF8591]");
Serial.print(RawValue);
Serial.print("-");
Serial.print(Voltage);
Serial.println(" ");
delay(1000);
}
|