Tell me what you want, What you really, really want.

Moderator: Mmiscool

User avatar
By Barnabybear
#64130 Hi, sorry it’s not in ESP Basic but the process, locations and values should save you some time when writing your own. Not pretty – the first attempt at communicating, but it works.

On a side note: Does anyone know if you can chainge the gain on the fly between reads of different inputs without doing any dammage? I want to read the state of charging/discharging of two batteries. The voltage can be any scale, but the current is measured as voltage across a low value shunt and is likley to be quite small. I could do with reading 4V FSD on two pins and 0.512V FSD on the other two.
EDIT: It looks like you can without doing any dammage: http://e2e.ti.com/support/data_converte ... 3/t/378122

Code: Select all/* An exapmle of an ESP8266 reading an ADS1115 without a library.
   4 single ended reads, single shot mode, 4.096V full scale deflection.
   See data sheet for config settings and other functions. */
   
#include <Wire.h>

int config_MSB; //var for config read.
int config_LSB; //var for config read.
short val_AIN0; //var for AIN0 read.
short val_AIN1; //var for AIN1 read.
short val_AIN2; //var for AIN2 read.
short val_AIN3; //var for AIN3 read.
const float scale_factor = 4.096 / 32768; //4.096 = full scale voltage.
const int convert_delay = 100; // delay for ADS1115 to do ADC convertion.

void setup() {
  Serial.begin(115200); //start Serial.
  Wire.begin(4, 5); //start Wire and set SDA - SCL.

  // Write config settings. //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //write move pointer to config register.
  Wire.write(B11000011); //write MSB of config.
  Wire.write(B10000011); //write LSB of config.
  Wire.endTransmission(); //write end.

  // Read config settings. //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //write move pointer to config register.
  Wire.endTransmission(); //write end.

  Wire.requestFrom(0x48, 2); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  config_MSB = Wire.read(); // store config byte.
  config_LSB = Wire.read(); // store config byte.
  Serial.println();
  Serial.print(config_MSB, BIN); // print config byte.
  Serial.print(" ");
  Serial.print(config_LSB, BIN); // print config byte.
  Serial.println();

}

void loop() {
  Serial.print("Readings");

  // Read AIN0 - convert - print - single shot mode //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //write move pointer to config register.
  Wire.write(B11000011); //write MSB of config, bits [14:12] set for AIN0 single ended.
  Wire.write(B10000011); //write LSB of config.
  Wire.endTransmission(); //write end.

  delay(convert_delay); // delay for ADS1115 to do ADC convertion.

  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000000); //write move pointer to conversion register.
  Wire.endTransmission(); //write end.

  Wire.requestFrom(0x48, 2); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  val_AIN0 = Wire.read() << 8 | Wire.read(); //store read as 16 bit value.
  Serial.println();
  Serial.print("AIN0 = ");
  Serial.print(val_AIN0 * scale_factor, DEC); //scale & print read value.

  // Read AIN1 - convert - print - single shot mode //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //move pointer to config register.
  Wire.write(B11010011); //write MSB of config, bits [14:12] set for AIN1 single ended.
  Wire.write(B10000011); //write LSB of config.
  Wire.endTransmission(); //write end.

  delay(convert_delay); // delay for ADS1115 to do ADC convertion.

  Wire.beginTransmission(0x48); //start comms with board 0x48.
  Wire.write(B00000000); //write move pointer to conversion register.
  Wire.endTransmission(); //write end.

  Wire.requestFrom(0x48, 2); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  val_AIN1 = Wire.read() << 8 | Wire.read(); //store read as 16 bit value.
  Serial.println();
  Serial.print("AIN1 = ");
  Serial.print(val_AIN1 * scale_factor, DEC); //scale & print read value

  // Read AIN2 - convert - print - single shot mode //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //write move pointer to config register.
  Wire.write(B11100011); //write MSB of config, bits [14:12] set for AIN2 single ended.
  Wire.write(B10000011); //write LSB of config.
  Wire.endTransmission(); //write end.

  delay(convert_delay); // delay for ADS1115 to do ADC convertion.

  Wire.beginTransmission(0x48); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  Wire.write(B00000000); //move pointer to conversion register.
  Wire.endTransmission(); //write end.

  Wire.requestFrom(0x48, 2); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  val_AIN2 = Wire.read() << 8 | Wire.read(); //store read as 16 bit value.
  Serial.println();
  Serial.print("AIN2 = ");
  Serial.print(val_AIN2 * scale_factor, DEC); //scale & print read value

  // Read AIN3 - convert - print - single shot mode //
  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000001); //write move pointer to config register.
  Wire.write(B11110011); //write MSB of config, bits [14:12] set for AIN3 single ended.
  Wire.write(B10000011); //write LSB of config.
  Wire.endTransmission(); //write end.

  delay(convert_delay); // delay for ADS1115 to do ADC convertion.

  Wire.beginTransmission(0x48); //start write to board 0x48 (address pin -> Gnd).
  Wire.write(B00000000); //write move pointer to conversion register.
  Wire.endTransmission(); //write end.

  Wire.requestFrom(0x48, 2); //read request 2 bytes from board 0x48 (address pin -> Gnd).
  val_AIN3 = Wire.read() << 8 | Wire.read(); //store read as 16 bit value.
  Serial.println();
  Serial.print("AIN3 = ");
  Serial.print(val_AIN3 * scale_factor, DEC); //scale & print read value

  delay(20000); //delay between reads.
  Serial.println();
}
User avatar
By simon410
#66073
trackerj wrote:MCP3424 is another good option for a high res ADC. Cheaper, 18bit capabilities,etc, but slower than ADS1115. Depending on your project needs might fit. Have some around, can write an ESPBasic example for it if is for any interest.

If you wait for about a month or so you will find also the driver for ADS1115 in the ESPBasic section here:
http://www.esp8266-projects.com/search/label/ESPBasic


Hello , did you try the ADS1115?

Greetings, Simon
User avatar
By trackerj
#66154
simon410 wrote:
trackerj wrote:MCP3424 is another good option for a high res ADC. Cheaper, 18bit capabilities,etc, but slower than ADS1115. Depending on your project needs might fit. Have some around, can write an ESPBasic example for it if is for any interest.

If you wait for about a month or so you will find also the driver for ADS1115 in the ESPBasic section here:
http://www.esp8266-projects.com/search/label/ESPBasic


Hello , did you try the ADS1115?

Greetings, Simon


Yes, but did not had the chance to release/publish, been busy like hell last weeks.
I hope it will happen until the end of the month or start Jun.

Happy breadboarding,
TJ.