DS1115 A/D Converter sample code
microrobotics |
PRO |
05/06/23 11:48:42 AM UTC |
0 ⭐ |
4225 👁️ |
Never ⏰ |
[a/d, analog to digital, DS1115]
#include <Wire.h>
const int DS1115_Address = 0x48; // I2C address of DS1115
float voltageValue = 0.0;
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
int rawValue;
Wire.beginTransmission(DS1115_Address);
Wire.write(0x00); // address of conversion register
Wire.endTransmission();
delay(10); // conversion time for DS1115
Wire.requestFrom(DS1115_Address, 2);
if (Wire.available() == 2) {
rawValue = Wire.read() << 8 | Wire.read();
voltageValue = rawValue * 5.0 / 32768.0; // 5V reference voltage, 16-bit resolution
Serial.print("Voltage: ");
Serial.print(voltageValue);
Serial.println("V");
}
delay(1000);
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎