Ads1115 on boron

I have used for awhile a 4-20ma board with the ads1115 on photons and electrons no issues. Trying to now move to a boron and things fall apart. I get numoris nrf52840.h errors. Also an error on the ‘bool ADS1115::setAddress(int)’ and ‘bool ADS1115::wireRead(int, int, int*, int)’.

Which library?
Have you checked the library sources whether there are conditional compiling directives that might not be fitting for the Boron?

BTW, when you get compile errors it’s typically best to quote them verbatim

I do not remember where I found the library. Somewhere here on the board a year or so ago.

../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/mdk/nrf52840.h:221:19: error: expected unqualified-id before numeric constant
   __IM  uint32_t  A0;                           /*!< (@ 0x00000000) Slope definition A0                                        */
                   ^
../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/mdk/nrf52840.h:222:19: error: expected unqualified-id before numeric constant
   __IM  uint32_t  A1;                           /*!< (@ 0x00000004) Slope definition A1                                        */
                   ^
../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/mdk/nrf52840.h:223:19: error: expected unqualified-id before numeric constant
   __IM  uint32_t  A2;                           /*!< (@ 0x00000008) Slope definition A2                                        */
                   ^

That goes on for awhile

ads1115h.cpp: In member function 'bool ADS1115::setAddress(int)':
ads1115h.cpp:7:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
ads1115h.cpp: In member function 'bool ADS1115::wireRead(int, int, int*, int)':
ads1115h.cpp:41:9: warning: unused variable 'buf' [-Wunused-variable]
     int buf[returnLen];
         ^
../build/module.mk:277: recipe for target '../build/target/user/platform-13-mads1115h.o' failed
make[2]: *** [../build/target/user/platform-13-mads1115h.o] Error 1

That is at the bottom.

here is the .h file

#include "spark_wiring_i2c.h"
#include "spark_wiring_constants.h"
#include "spark_wiring.h"
#include "spark_wiring_usbserial.h"

class ADS1115{
public:
    bool setAddress(int addressJumper);
    int readInput(int channel);
private:
    int address = 0x48;
    unsigned long timeout = 100;
    bool inFailureMode = false;
    bool wireWrite(int addr, int reg, uint16_t value, int len);
    bool wireRead(int addr, int reg, int* readBuff, int returnLen);
    int configReg = 0x01;
    int inRead[4][2] = {{0x84, 0x83}, {0x94, 0x83}, {0xA4, 0x83}, {0xB4, 0x83}};
    int readCommand[1] = {0x00};
    
    int localReadBuf[2];
    
    uint16_t readInputSingleEnded[4] = {49539, 53635, 57731, 61827};

};

and the cpp file

#include "ads1115h.h"

bool ADS1115::setAddress(int addressJumper){
    if(addressJumper == 1){
        address = address | 1;
    }
}

int ADS1115::readInput(int channel){
    // byte writeData[2] = {(byte)readInputSingleEnded[channel -1], (byte)(readInputSingleEnded[channel - 1]>>8)};
    if(!wireWrite(address, 0x01, readInputSingleEnded[channel -1], 2)){
        Serial.println("WireWrite failed");
    }
    delay(50);
    if(!wireRead(address, 0x00, localReadBuf, 2)){
        Serial.println("WireRead failed");
    }
    
    uint16_t raw_adc = (localReadBuf[0] << 8) | localReadBuf[1];

    return raw_adc;
}

bool ADS1115::wireWrite(int addr, int reg, uint16_t value, int len){
    if (!Wire.isEnabled()) {
        Wire.begin();
    }
    Wire.beginTransmission(addr);
    Wire.write((uint8_t)reg);
    Wire.write((uint8_t)(value>>8));
    Wire.write((uint8_t)(value & 0xFF));
    byte status = Wire.endTransmission();
    if(status == 0){
        return true;
    }else{
        return false;
    }
}

bool ADS1115::wireRead(int addr, int reg, int* readBuff, int returnLen){
    int buf[returnLen];
    if (!Wire.isEnabled()) {
        Wire.begin();
    }
    Wire.beginTransmission(addr);
    Wire.write(reg);
    byte status = Wire.endTransmission();
    if(status != 0){
        return false;
    }
    Wire.requestFrom(addr, returnLen);
    unsigned long startTime = millis();
    while(Wire.available() != returnLen && millis()<startTime+timeout);
    if(Wire.available() != returnLen){
        return false;
    }
    for(int i = 0; i < returnLen; i++){
        readBuff[i] = Wire.read();
        // Serial.printf("read: %i \n", readBuff[i]);
    }
    return true;
}

The two messages about setAddress() and wireRead() are mere warnings and won’t prevent the code to build - although the missing return statement is an indication of poor style and may potentially cause issues at runtime.

The more severe error messages probably come from the fact that this library fails to feature a #include <Particle.h> statement but features four individual includes that may not work correctly (or miss some prerequisites) for Gen3.

We typically advise not to include the individual headers but the overarching Particle.h which in turn will include the others as needed.

2 Likes

That fixed it. Thanks for your quick help.

1 Like

Hello! Can you post the code that your using?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.