Created
March 26, 2021 19:22
-
-
Save OneGneissGuy/aad5b6e66c0fd08f42b85935e870a01a to your computer and use it in GitHub Desktop.
script to try out ads1115 differential
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ads1115_differential.ino | |
// PURPOSE: read differential | |
// EDITED BY: JFS 03/26/21 | |
// AUTHOR: Rob.Tillaart | |
// VERSION: 0.1.1 | |
// test 1 | |
// +signal on AIN0, -signal on AIN1 | |
//EXAMPLE OUTPUT | |
// val_01: -16 LSB -0.125 mV -15.6 W/m2 | |
// val_01: 0 LSB 0.000 mV 0.0 W/m2 | |
// val_01: -16 LSB -0.125 mV -15.6 W/m2 | |
// val_01: -16 LSB -0.125 mV -15.6 W/m2 | |
// val_01: -16 LSB -0.125 mV -15.6 W/m2 | |
// val_01: -16 LSB -0.125 mV -15.6 W/m2 | |
// val_01: -32 LSB -0.250 mV -31.3 W/m2 | |
// val_01: 0 LSB 0.000 mV 0.0 W/m2 | |
// val_01: -32 LSB -0.250 mV -31.3 W/m2 | |
#include <SPI.h> | |
#include <ADS1X15.h> | |
#define ADS1115_addr 0x48 | |
ADS1115 ADS(ADS1115_addr); | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println(__FILE__); | |
Serial.print("ADS1X15_LIB_VERSION: "); | |
Serial.println(ADS1X15_LIB_VERSION); | |
ADS.begin(); | |
ADS.setGain(16); | |
} | |
void loop() | |
{ | |
int16_t val_01 = ADS.readADC_Differential_0_1(); // +DIFF signal on CHAN1, -DIFF signal on CHAN2 | |
float millivolts_01 = ADS.toVoltage(val_01) * 1000; | |
float netradGain = 8.0; // uV/W/m2 | |
float netradsf = 1000 / netradGain; // mV to W/m2 | |
float wm2 = millivolts_01 * netradsf; | |
Serial.print("val_01: "); | |
Serial.print(val_01); | |
Serial.print(" LSB\t"); | |
Serial.print(millivolts_01, 3); | |
Serial.print(" mV\t"); | |
Serial.print(wm2, 1); | |
Serial.print(" W/m2\t"); | |
Serial.println(); | |
delay(1000); | |
} | |
// -- END OF FILE -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment