ADS1115

Adding the necessary code for ADS1115 requires three steps:

  • Setup

  • Run

  • Functions

Setup

The setup is done in 2_Board.ino and 10_TableAndAnalog.nino. First off is 2_Board.ino; set up your I2C channels, then scroll down to this section:

//16-BIT ADC ADS1115
#define USING_ADS1115 0
#define ADS1115_I2C_NUMBER 0
#define ADS1115_CHIPS 1
uint8_t ADS1115_chipAddress [] = {0x48};

#define ADS1115_ALERT 0

#if (ADS1115_ALERT == 1)
uint8_t ADS1115_alertPins [] = {99};
#endif

USING_ADS1115 is to disable/enable support for this IC. Set it to 1 to enable.

ADS1115_I2C_NUMBER lets to chose between I2C channel 0 or 1 on a RP2040 board. If you're not using a RP2040 board, just leave this at 0.

ADS1115_CHIPS is a count of how many ADS1115 ICs you've got in your project. Maximum 4.

ADS1115_chipAddress is an array where you put in the I2C addresses of the ICs you're using. Note that this will also number your ADS1115 ICs. The first one you list will be ADS1115 #1, the next one ADS1115 #2, etc.

ADS1115_ALERT allows you to enable using the ALERT/RDY pin to let everyone know a measurement has been done. Using this requires a dedicated digital pin, and makes your code run faster. More on this here.

ADS1115_alertPins is an array where you list the pin numbers of the pins used for ALERT/RDY. If you're not using ALERT/RDY pins, just leave this as it is.

To set up two ADS1115 with adress 0x48 and 0x49, with the first of them using pin 10 for ALERT/RDY and the second using pin 16, we'll write it like this:

//16-BIT ADC ADS1115
#define USING_ADS1115 1
#define ADS1115_I2C_NUMBER 0
#define ADS1115_CHIPS 2
uint8_t ADS1115_chipAddress [] = {0x48,0x49};

#define ADS1115_ALERT 1

#if (ADS1115_ALERT == 1)
uint8_t ADS1115_alertPins [] = {10,16};
#endif

Next is setting up your analog channels in 10_TableAndAnalog.ino.

Run

You'll need to get the processor to read your ADS1115 and store the values. This is done with a simple function that you place in 30_Switches.ino together with all your button functions. I recommend placing them at the very top, before anything else.

ADS1115Run()

The function wants to know a couple of things:

  • chipNumber: Which number is this ADS1115. See ADS1115_chipAddress above.

  • channelCount: How many channels are you using? Enabling only 1 channel will give you readings on A0. If you want only A3, you'll have to enable all 4 channels. The ADS1115 will read one channel at the time, so the more channels you use the lower the refresh rate will be.

  • rate: How many samples per second it should take. How fast you want it to go. 0 is slowest (only 8 updates per second), 7 is fastest (860 updates per second). Slowing it down will make it a bit more accurate, but your inputs will start to get delayed. Only 5-7 will be relevant for joystick controllers in my opinion.

  • gain: How amplified the signal is. Or, actually, what voltage the signal is compared to (reference voltage). No voltage input to the ADC should be higher than the reference voltage. Rule of thumb is that if you get a value less than half of the maximum value from the ADC (less than 16 383), you might try to amp up the gain one step. Then reevaluate.

Now, we'll set up the two ADS1115 in the example at the top of the page. We're using 3/4 channels on both, we'll be using Gain setting 1 and Rate setting 7 for both:

  //--------------------------------------
  //---------SWITCHES START HERE----------
  //--------------------------------------
  
  ADS1115Run(1,3,7,1);
  ADS1115Run(2,3,7,1);
  
  
  //--------------------------------------
  //---------SWITCHES END HERE------------
  //--------------------------------------

	Joystick.setZAxis(rotaryField - 32767);
	Joystick.setYAxis(buttonField - 32767);

	Joystick.sendState();

} //LOOP ENDS HERE

#if (BOARDTYPE == 2)
  void loop()
  {
	#if (LED1COUNT + LED2COUNT + LED3COUNT + LED4COUNT > 0)
		processCommands();
	#endif
  #if(USING_CB1 == 1)
  CB1Oversampling();
  #endif
  }
#endif

Functions

As you've read here, we now have our two ADS1115 on analog channels 1-8. Our 3 inputs on ADS1115#1 are on analog channels 1-3, and the 3 inputs on ADS1115#2 are on analog channels 5-7. Analog channels 4 and 8 are not is use, but are reserved for the 4th input on the two ADCs.

So, lets use our ADS1115's to set up a pair of dual clutches, a bite point potentiometer and 3 rotary switches (look up these functions in the switch library for more info):

  //--------------------------------------
  //---------SWITCHES START HERE----------
  //--------------------------------------
  
  ADS1115Run(1,3,7,1);
  ADS1115Run(2,3,7,1);
  
  dualClutch(1,3430,19830,2,3780,19790,false);
  
  bitePot(3,25560,10);
  
  rotaryAnalogSimple(5,0,2133,4290,6210,8390,10600,12866,15020,17105,19220,21320,23500,false);
  rotaryAnalogSimple(6,0,2133,4290,6210,8390,10600,12866,15020,17105,19220,21320,23500,false);
  rotaryAnalogSimple(7,0,2133,4290,6210,8390,10600,12866,15020,17105,19220,21320,23500,false);

  //--------------------------------------
  //---------SWITCHES END HERE------------
  //--------------------------------------

	Joystick.setZAxis(rotaryField - 32767);
	Joystick.setYAxis(buttonField - 32767);

	Joystick.sendState();

} //LOOP ENDS HERE

#if (BOARDTYPE == 2)
  void loop()
  {
	#if (LED1COUNT + LED2COUNT + LED3COUNT + LED4COUNT > 0)
		processCommands();
	#endif
  #if(USING_CB1 == 1)
  CB1Oversampling();
  #endif
  }
#endif

Last updated