When I call <Adafruit_ADS1115 object>.begin(); my program running on arduino hangs. Any direction or advice?

I'm trying to read a voltage with an ADS1115 adc, and the <Adafruit_ADS1X15.h> library.
I based my code off this tutorial:

I put a comment in the code where the programs hang.

#include <ACAN2515.h>
#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;
const float multiplier = .1875;

static const byte MCP2515_CS  = 10 ; // CS input of MCP2515 (adapt to your design) 
static const byte MCP2515_INT =  3 ; // INT output of MCP2515 (adapt to your design)

ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;                   ///KS - The CAN driver object
void interuptServiceRoutine(){ can.isr();}

static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; //KS - Sets Clock Frequency Variable to pass into configuration object
static const uint32_t CAN_BAUDRATE = 500UL * 1000UL;  //KS - Sets the baudrate variable that will be passed into settings object constructor

CANMessage frame;

void setup() {  
  Serial.begin(9600);
  Serial.println("A");
  
  //setup the frame
  frame.id = 0xCC;
  Serial.println("B");

  frame.len = 2;

  //Start SPI
  SPI.begin();
  Serial.println("C");
  ads.begin();               ///<-------------------------------    it stalls here

  Serial.println("boop");
  //Configure ACAN2515
  ACAN2515Settings settings (QUARTZ_FREQUENCY, CAN_BAUDRATE) ; //KS - CAN bit rate 125 kb/s  and creating the configuration object
  const uint16_t errorCode = can.begin (settings, interuptServiceRoutine);                     ///KS - Just Configuring the Driver
  if(errorCode) { Serial.print ("Configuration error 0x") ; Serial.println (errorCode, HEX) ; } else Serial.println("CAN Transmitter Driver Configured");
}

void loop() {
  int16_t adc0=ads.readADC_SingleEnded(0);
  Serial.println(adc0*multiplier);

  int16_t a=adc0;
  int16_t b=adc0<<8;
  frame.data[0]=b>>8;
  frame.data[1]=a>>8;
  //can.tryToSend(frame);
}

Also, did I format my code right? It said to put multiple line code in between '''s.

Please reread the forum rules and edit your post, inserting the code in the code tags.

And about the code - I don't see the line in the code what you mentioned in message title

So you include Wire, but dont use Wire, however use SPI but do not include SPI? hmmm

Use back tics instead. Or in the post editor, use the "</>" code tag button.

1 Like

I'm guessing the Adafruit library uses them?

How does the post look now?

Make sure the ADX1115 works with the examples provided by the library, before trying or modifying someone else's code.

1 Like

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