Thingy:53 is a compact nrf5340 based IoT development device from Nordic semiconductor with various kind of onboard sensors. In order to read external analog signals we can also use external ADC module "ADS1115 with PGA".
Here we will learn how to create a basic thingy:53 application to read the analog inputs using ADS1115 attached through expansion port.
Before moving forward to creating a new application, we need to know the nRF5340 GPIO pins/communication interface which will be used to communicate with ADS1115 module. On thingy:53 module there is an expansion connector to interface external modules. GPIO pins available at expansion connector P1 also have I2C communication functionality (for details consult nRF5340 datasheet).
We can also use the Debug board connected at current measurement and debugging interface of thingy:53 device because it also contains the same nRF5340 GPIO which are connected at expansion connector P1.
For the easy of connection, we will use the debug and current measurement board connected at card edge connector of thingy:53 device.
From thingy:53 schematic we can find out that expansion interface is connected at P0.05 and P0.04 GPIO of nRF5340 soc.
P0.05 and P0.04 shown in above image represent GPIO port 0 pin 5 and pin 4 respectively and these pins can be used for I2C interfacing with external sensors. These two GPIO pins are also capable of analog inputs but in case of more than two analog signals or to interface external sensor module, we cannot use these GPIO pins as analog input only.
We will not be able to find the configuration of above mentioned GPIO pins and the second I2C interface in default pin control file, available in nRF connect SDK (its full path along with file name is given below).
C:\ncs\v2.1.0\zephyr\boards\arm\thingy53_nrf5340\thingy53_nrf5340_common-pinctrl.dtsi
In above mentioned file we won't see any configuration for P0.04 and P0.05. Therefore we will create an overlay file for the configuration of these GPIO pins, second I2C interface and ADS1115 external ADC module.
Now knowing all the basic stuff about external ADC module interfacing, we can create a new application for our thingy53 and build its configuration file.
After creating a simple hello world application and selecting its build configuration we will change the k-config of our application as shown below, for easy debugging and console monitoring. Also enable the "SENSORDRIVERS" in k-config config menu. As we are using analog sensor therefore we need to enable fraction value printing in console by enabling the float for printf function as shown below;
After making the above mentioned changes in k-config, we need to create an overlay file for thingy:53 in order to enable and communicate with the ADS1115 external ADC module. After creating the new overlay file add the following code to configure the GPIO pins as I2C interface.
&pinctrl {
i2c2_default: i2c2_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 4)>,
<NRF_PSEL(TWIM_SCL, 0, 5)>;
};
};
i2c2_sleep: i2c2_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 4)>,
<NRF_PSEL(TWIM_SCL, 0, 5)>;
low-power-enable;
};
};
};
And also add the following line in overlay file to enable the second I2C interface along with ADS1115 module.
&i2c2 {
compatible = "nordic,nrf-twim";
status = "okay";
clock-frequency = <I2C_BITRATE_STANDARD>;
pinctrl-0 = <&i2c2_default>;
pinctrl-1 = <&i2c2_sleep>;
pinctrl-names = "default", "sleep";
ads1115: ads1115@48 {
compatible = "ti,ads1115";
#io-channel-cells = <1>;
reg = <0x48 >;
label = "ADS1115";
};
};
Now we can add the ads1115.c and adc1115.h files (attached below) in src directory of our current application of thingy:53. The library files of ADS1115 will not be added automatically to our make configuration. In order to achieve that we need to make some changes in the CMakeLists.txt file of our application. This configuration file can also be accessed from one the side panels.
Change the following line in it.
target_sources(app PRIVATE src/main.c)
as shown below after adding the ads1115.c and ads1115.h files in src directory.
target_sources(app PRIVATE src/main.c src/ads1115.c)
Now change the main.c code of hello_world application with the main.c code attached below. Then we can successfully build and flash it to thingy53 using external SEGGER J-Tag probe. When thingy53 firmware programming is finished, we can connect it through RTT interface, available under CONNECTED DEVICES panel, to read the ADS1115 external adc values.
Note:
1)main.c, ads1115.c, ads1115.h and overlay files are attached below.
2) thingy:53 pinout details link: here
3) thingy:53 debug and current measurements board pinout details link: here
Comments