ads1115.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. //***************************************************************************
  2. // Si7021 module for ESP8266 with nodeMCU
  3. // fetchbot @github
  4. // MIT license, http://opensource.org/licenses/MIT
  5. //***************************************************************************
  6. #include "module.h"
  7. #include "lauxlib.h"
  8. #include "platform.h"
  9. #include "osapi.h"
  10. //***************************************************************************
  11. // I2C ADDRESS DEFINITON
  12. //***************************************************************************
  13. #define ADS1115_I2C_ADDR_GND (0x48)
  14. #define ADS1115_I2C_ADDR_VDD (0x49)
  15. #define ADS1115_I2C_ADDR_SDA (0x4A)
  16. #define ADS1115_I2C_ADDR_SCL (0x4B)
  17. //***************************************************************************
  18. // POINTER REGISTER
  19. //***************************************************************************
  20. #define ADS1115_POINTER_MASK (0x03)
  21. #define ADS1115_POINTER_CONVERSION (0x00)
  22. #define ADS1115_POINTER_CONFIG (0x01)
  23. #define ADS1115_POINTER_THRESH_LOW (0x02)
  24. #define ADS1115_POINTER_THRESH_HI (0x03)
  25. //***************************************************************************
  26. // CONFIG REGISTER
  27. //***************************************************************************
  28. #define ADS1115_OS_MASK (0x8000)
  29. #define ADS1115_OS_NON (0x0000)
  30. #define ADS1115_OS_SINGLE (0x8000) // Write: Set to start a single-conversion
  31. #define ADS1115_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress
  32. #define ADS1115_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion
  33. #define ADS1115_MUX_MASK (0x7000)
  34. #define ADS1115_MUX_DIFF_0_1 (0x0000) // Differential P = AIN0, N = AIN1 (default)
  35. #define ADS1115_MUX_DIFF_0_3 (0x1000) // Differential P = AIN0, N = AIN3
  36. #define ADS1115_MUX_DIFF_1_3 (0x2000) // Differential P = AIN1, N = AIN3
  37. #define ADS1115_MUX_DIFF_2_3 (0x3000) // Differential P = AIN2, N = AIN3
  38. #define ADS1115_MUX_SINGLE_0 (0x4000) // Single-ended AIN0
  39. #define ADS1115_MUX_SINGLE_1 (0x5000) // Single-ended AIN1
  40. #define ADS1115_MUX_SINGLE_2 (0x6000) // Single-ended AIN2
  41. #define ADS1115_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
  42. #define ADS1115_PGA_MASK (0x0E00)
  43. #define ADS1115_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
  44. #define ADS1115_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
  45. #define ADS1115_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
  46. #define ADS1115_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
  47. #define ADS1115_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
  48. #define ADS1115_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
  49. #define ADS1115_MODE_MASK (0x0100)
  50. #define ADS1115_MODE_CONTIN (0x0000) // Continuous conversion mode
  51. #define ADS1115_MODE_SINGLE (0x0100) // Power-down single-shot mode (default)
  52. #define ADS1115_DR_MASK (0x00E0)
  53. #define ADS1115_DR_8SPS (0x0000) // 8 samples per second
  54. #define ADS1115_DR_16SPS (0x0020) // 16 samples per second
  55. #define ADS1115_DR_32SPS (0x0040) // 32 samples per second
  56. #define ADS1115_DR_64SPS (0x0060) // 64 samples per second
  57. #define ADS1115_DR_128SPS (0x0080) // 128 samples per second (default)
  58. #define ADS1115_DR_250SPS (0x00A0) // 250 samples per second
  59. #define ADS1115_DR_475SPS (0x00C0) // 475 samples per second
  60. #define ADS1115_DR_860SPS (0x00E0) // 860 samples per second
  61. #define ADS1115_CMODE_MASK (0x0010)
  62. #define ADS1115_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default)
  63. #define ADS1115_CMODE_WINDOW (0x0010) // Window comparator
  64. #define ADS1115_CPOL_MASK (0x0008)
  65. #define ADS1115_CPOL_ACTVLOW (0x0000) // ALERT/RDY pin is low when active (default)
  66. #define ADS1115_CPOL_ACTVHI (0x0008) // ALERT/RDY pin is high when active
  67. #define ADS1115_CLAT_MASK (0x0004) // Determines if ALERT/RDY pin latches once asserted
  68. #define ADS1115_CLAT_NONLAT (0x0000) // Non-latching comparator (default)
  69. #define ADS1115_CLAT_LATCH (0x0004) // Latching comparator
  70. #define ADS1115_CQUE_MASK (0x0003)
  71. #define ADS1115_CQUE_1CONV (0x0000) // Assert ALERT/RDY after one conversions
  72. #define ADS1115_CQUE_2CONV (0x0001) // Assert ALERT/RDY after two conversions
  73. #define ADS1115_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions
  74. #define ADS1115_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default)
  75. //***************************************************************************
  76. static const uint8_t ads1115_i2c_id = 0;
  77. static const uint8_t general_i2c_addr = 0x00;
  78. static const uint8_t ads1115_i2c_reset = 0x06;
  79. static uint8_t ads1115_i2c_addr = ADS1115_I2C_ADDR_GND;
  80. static uint16_t ads1115_os = ADS1115_OS_SINGLE;
  81. static uint16_t ads1115_gain = ADS1115_PGA_6_144V;
  82. static uint16_t ads1115_samples = ADS1115_DR_128SPS;
  83. static uint16_t ads1115_channel = ADS1115_MUX_SINGLE_0;
  84. static uint16_t ads1115_comp = ADS1115_CQUE_NONE;
  85. static uint16_t ads1115_mode = ADS1115_MODE_SINGLE;
  86. static uint16_t ads1115_threshold_low = 0x8000;
  87. static uint16_t ads1115_threshold_hi = 0x7FFF;
  88. static uint16_t ads1115_config = 0x8583;
  89. static uint16_t ads1115_conversion = 0;
  90. static double ads1115_volt = 0;
  91. os_timer_t ads1115_timer; // timer for conversion delay
  92. int ads1115_timer_ref; // callback when readout is ready
  93. static int ads1115_lua_readoutdone(void);
  94. static uint8_t write_reg(uint8_t reg, uint16_t config) {
  95. platform_i2c_send_start(ads1115_i2c_id);
  96. platform_i2c_send_address(ads1115_i2c_id, ads1115_i2c_addr, PLATFORM_I2C_DIRECTION_TRANSMITTER);
  97. platform_i2c_send_byte(ads1115_i2c_id, reg);
  98. platform_i2c_send_byte(ads1115_i2c_id, (uint8_t)(config >> 8));
  99. platform_i2c_send_byte(ads1115_i2c_id, (uint8_t)(config & 0xFF));
  100. platform_i2c_send_stop(ads1115_i2c_id);
  101. }
  102. static uint16_t read_reg(uint8_t reg) {
  103. platform_i2c_send_start(ads1115_i2c_id);
  104. platform_i2c_send_address(ads1115_i2c_id, ads1115_i2c_addr, PLATFORM_I2C_DIRECTION_TRANSMITTER);
  105. platform_i2c_send_byte(ads1115_i2c_id, reg);
  106. platform_i2c_send_stop(ads1115_i2c_id);
  107. platform_i2c_send_start(ads1115_i2c_id);
  108. platform_i2c_send_address(ads1115_i2c_id, ads1115_i2c_addr, PLATFORM_I2C_DIRECTION_RECEIVER);
  109. uint16_t buf = (platform_i2c_recv_byte(ads1115_i2c_id, 1) << 8);
  110. buf += platform_i2c_recv_byte(ads1115_i2c_id, 0);
  111. platform_i2c_send_stop(ads1115_i2c_id);
  112. return buf;
  113. }
  114. // convert ADC value to voltage corresponding to PGA settings
  115. static double get_volt(uint16_t value) {
  116. double volt = 0;
  117. switch (ads1115_gain) {
  118. case (ADS1115_PGA_6_144V):
  119. volt = (int16_t)value * 0.1875;
  120. break;
  121. case (ADS1115_PGA_4_096V):
  122. volt = (int16_t)value * 0.125;
  123. break;
  124. case (ADS1115_PGA_2_048V):
  125. volt = (int16_t)value * 0.0625;
  126. break;
  127. case (ADS1115_PGA_1_024V):
  128. volt = (int16_t)value * 0.03125;
  129. break;
  130. case (ADS1115_PGA_0_512V):
  131. volt = (int16_t)value * 0.015625;
  132. break;
  133. case (ADS1115_PGA_0_256V):
  134. volt = (int16_t)value * 0.0078125;
  135. break;
  136. }
  137. return volt;
  138. }
  139. // convert threshold in volt to ADC value corresponding to PGA settings
  140. static uint8_t get_value(int16_t *volt) {
  141. switch (ads1115_gain) {
  142. case (ADS1115_PGA_6_144V):
  143. if ((*volt >= 6144) || (*volt < -6144) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  144. *volt = *volt / 0.1875;
  145. break;
  146. case (ADS1115_PGA_4_096V):
  147. if ((*volt >= 4096) || (*volt < -4096) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  148. *volt = *volt / 0.125;
  149. break;
  150. case (ADS1115_PGA_2_048V):
  151. if ((*volt >= 2048) || (*volt < -2048) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  152. *volt = *volt / 0.0625;
  153. break;
  154. case (ADS1115_PGA_1_024V):
  155. if ((*volt >= 1024) || (*volt < -1024) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  156. *volt = *volt / 0.03125;
  157. break;
  158. case (ADS1115_PGA_0_512V):
  159. if ((*volt >= 512) || (*volt < -512) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  160. *volt = *volt / 0.015625;
  161. break;
  162. case (ADS1115_PGA_0_256V):
  163. if ((*volt >= 256) || (*volt < -256) || ((*volt < 0) && (ads1115_channel >> 14))) return 1;
  164. *volt = *volt / 0.0078125;
  165. break;
  166. }
  167. return 0;
  168. }
  169. // Initializes ADC
  170. // Lua: ads11115.setup(ADDRESS)
  171. static int ads1115_lua_setup(lua_State *L) {
  172. // check variables
  173. if (!lua_isnumber(L, 1)) {
  174. return luaL_error(L, "wrong arg range");
  175. }
  176. ads1115_i2c_addr = luaL_checkinteger(L, 1);
  177. if (!((ads1115_i2c_addr == ADS1115_I2C_ADDR_GND) || (ads1115_i2c_addr == ADS1115_I2C_ADDR_VDD) || (ads1115_i2c_addr == ADS1115_I2C_ADDR_SDA) || (ads1115_i2c_addr == ADS1115_I2C_ADDR_SCL))) {
  178. return luaL_error(L, "Invalid argument: adddress");
  179. }
  180. platform_i2c_send_start(ads1115_i2c_id);
  181. platform_i2c_send_address(ads1115_i2c_id, general_i2c_addr, PLATFORM_I2C_DIRECTION_TRANSMITTER);
  182. platform_i2c_send_byte(ads1115_i2c_id, ads1115_i2c_reset);
  183. platform_i2c_send_stop(ads1115_i2c_id);
  184. // check for device on i2c bus
  185. if (read_reg(ADS1115_POINTER_CONFIG) != 0x8583) {
  186. return luaL_error(L, "found no device");
  187. }
  188. return 0;
  189. }
  190. // Change ADC settings
  191. // Lua: ads1115.setting(GAIN,SAMPLES,CHANNEL,MODE[,CONVERSION_RDY][,COMPARATOR,THRESHOLD_LOW,THRESHOLD_HI])
  192. static int ads1115_lua_setting(lua_State *L) {
  193. // check variables
  194. if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3) || !lua_isnumber(L, 4)) {
  195. return luaL_error(L, "wrong arg range");
  196. }
  197. ads1115_gain = luaL_checkinteger(L, 1);
  198. if (!((ads1115_gain == ADS1115_PGA_6_144V) || (ads1115_gain == ADS1115_PGA_4_096V) || (ads1115_gain == ADS1115_PGA_2_048V) || (ads1115_gain == ADS1115_PGA_1_024V) || (ads1115_gain == ADS1115_PGA_0_512V) || (ads1115_gain == ADS1115_PGA_0_256V))) {
  199. return luaL_error(L, "Invalid argument: gain");
  200. }
  201. ads1115_samples = luaL_checkinteger(L, 2);
  202. if (!((ads1115_samples == ADS1115_DR_8SPS) || (ads1115_samples == ADS1115_DR_16SPS) || (ads1115_samples == ADS1115_DR_32SPS) || (ads1115_samples == ADS1115_DR_64SPS) || (ads1115_samples == ADS1115_DR_128SPS) || (ads1115_samples == ADS1115_DR_250SPS) || (ads1115_samples == ADS1115_DR_475SPS) || (ads1115_samples == ADS1115_DR_860SPS))) {
  203. return luaL_error(L, "Invalid argument: samples");
  204. }
  205. ads1115_channel = luaL_checkinteger(L, 3);
  206. if (!((ads1115_channel == ADS1115_MUX_SINGLE_0) || (ads1115_channel == ADS1115_MUX_SINGLE_1) || (ads1115_channel == ADS1115_MUX_SINGLE_2) || (ads1115_channel == ADS1115_MUX_SINGLE_3) || (ads1115_channel == ADS1115_MUX_DIFF_0_1) || (ads1115_channel == ADS1115_MUX_DIFF_0_3) || (ads1115_channel == ADS1115_MUX_DIFF_1_3) || (ads1115_channel == ADS1115_MUX_DIFF_2_3))) {
  207. return luaL_error(L, "Invalid argument: channel");
  208. }
  209. ads1115_mode = luaL_checkinteger(L, 4);
  210. if (!((ads1115_mode == ADS1115_MODE_SINGLE) || (ads1115_mode == ADS1115_MODE_CONTIN))) {
  211. return luaL_error(L, "Invalid argument: mode");
  212. }
  213. if (ads1115_mode == ADS1115_MODE_SINGLE) {
  214. ads1115_os = ADS1115_OS_SINGLE;
  215. } else {
  216. ads1115_os = ADS1115_OS_NON;
  217. }
  218. ads1115_comp = ADS1115_CQUE_NONE;
  219. // Parse optional parameters
  220. if (lua_isnumber(L, 5) && !(lua_isnumber(L, 6) || lua_isnumber(L, 7))) {
  221. // conversion ready mode
  222. ads1115_comp = luaL_checkinteger(L, 5);
  223. if (!((ads1115_comp == ADS1115_CQUE_1CONV) || (ads1115_comp == ADS1115_CQUE_2CONV) || (ads1115_comp == ADS1115_CQUE_4CONV))) {
  224. return luaL_error(L, "Invalid argument: conversion ready mode");
  225. }
  226. ads1115_threshold_low = 0x7FFF;
  227. ads1115_threshold_hi = 0x8000;
  228. write_reg(ADS1115_POINTER_THRESH_LOW, ads1115_threshold_low);
  229. write_reg(ADS1115_POINTER_THRESH_HI, ads1115_threshold_hi);
  230. } else if (lua_isnumber(L, 5) && lua_isnumber(L, 6) && lua_isnumber(L, 7)) {
  231. // comparator mode
  232. ads1115_comp = luaL_checkinteger(L, 5);
  233. if (!((ads1115_comp == ADS1115_CQUE_1CONV) || (ads1115_comp == ADS1115_CQUE_2CONV) || (ads1115_comp == ADS1115_CQUE_4CONV))) {
  234. return luaL_error(L, "Invalid argument: comparator mode");
  235. }
  236. ads1115_threshold_low = luaL_checkinteger(L, 5);
  237. ads1115_threshold_hi = luaL_checkinteger(L, 6);
  238. if ((int16_t)ads1115_threshold_low > (int16_t)ads1115_threshold_hi) {
  239. return luaL_error(L, "Invalid argument: threshold_low > threshold_hi");
  240. }
  241. if (get_value(&ads1115_threshold_low)) {
  242. return luaL_error(L, "Invalid argument: threshold_low");
  243. }
  244. if (get_value(&ads1115_threshold_hi)) {
  245. return luaL_error(L, "Invalid argument: threshold_hi");
  246. }
  247. write_reg(ADS1115_POINTER_THRESH_LOW, ads1115_threshold_low);
  248. write_reg(ADS1115_POINTER_THRESH_HI, ads1115_threshold_hi);
  249. }
  250. ads1115_config = (ads1115_os | ads1115_channel | ads1115_gain | ads1115_mode | ads1115_samples | ADS1115_CMODE_TRAD | ADS1115_CPOL_ACTVLOW | ADS1115_CLAT_NONLAT | ads1115_comp);
  251. write_reg(ADS1115_POINTER_CONFIG, ads1115_config);
  252. return 0;
  253. }
  254. // Read the conversion register from the ADC
  255. // Lua: ads1115.startread(function(volt, voltdec, adc) print(volt,voltdec,adc) end)
  256. static int ads1115_lua_startread(lua_State *L) {
  257. if (((ads1115_comp == ADS1115_CQUE_1CONV) || (ads1115_comp == ADS1115_CQUE_2CONV) || (ads1115_comp == ADS1115_CQUE_4CONV)) && (ads1115_threshold_low == 0x7FFF) && (ads1115_threshold_hi == 0x8000)) {
  258. if (ads1115_mode == ADS1115_MODE_SINGLE) {
  259. write_reg(ADS1115_POINTER_CONFIG, ads1115_config);
  260. }
  261. return 0;
  262. } else {
  263. luaL_argcheck(L, (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION), 1, "Must be function");
  264. lua_pushvalue(L, 1);
  265. ads1115_timer_ref = luaL_ref(L, LUA_REGISTRYINDEX);
  266. if (ads1115_mode == ADS1115_MODE_SINGLE) {
  267. write_reg(ADS1115_POINTER_CONFIG, ads1115_config);
  268. }
  269. // Start a timer to wait until ADC conversion is done
  270. os_timer_disarm (&ads1115_timer);
  271. os_timer_setfn (&ads1115_timer, (os_timer_func_t *)ads1115_lua_readoutdone, NULL);
  272. switch (ads1115_samples) {
  273. case (ADS1115_DR_8SPS):
  274. os_timer_arm (&ads1115_timer, 150, 0);
  275. break;
  276. case (ADS1115_DR_16SPS):
  277. os_timer_arm (&ads1115_timer, 75, 0);
  278. break;
  279. case (ADS1115_DR_32SPS):
  280. os_timer_arm (&ads1115_timer, 35, 0);
  281. break;
  282. case (ADS1115_DR_64SPS):
  283. os_timer_arm (&ads1115_timer, 20, 0);
  284. break;
  285. case (ADS1115_DR_128SPS):
  286. os_timer_arm (&ads1115_timer, 10, 0);
  287. break;
  288. case (ADS1115_DR_250SPS):
  289. os_timer_arm (&ads1115_timer, 5, 0);
  290. break;
  291. case (ADS1115_DR_475SPS):
  292. os_timer_arm (&ads1115_timer, 3, 0);
  293. break;
  294. case (ADS1115_DR_860SPS):
  295. os_timer_arm (&ads1115_timer, 2, 0);
  296. break;
  297. }
  298. return 0;
  299. }
  300. }
  301. // adc conversion timer callback
  302. static int ads1115_lua_readoutdone(void) {
  303. ads1115_conversion = read_reg(ADS1115_POINTER_CONVERSION);
  304. ads1115_volt = get_volt(ads1115_conversion);
  305. int ads1115_voltdec = (int)((ads1115_volt - (int)ads1115_volt) * 1000);
  306. ads1115_voltdec = ads1115_voltdec>0?ads1115_voltdec:0-ads1115_voltdec;
  307. lua_State *L = lua_getstate();
  308. os_timer_disarm (&ads1115_timer);
  309. lua_rawgeti (L, LUA_REGISTRYINDEX, ads1115_timer_ref);
  310. luaL_unref (L, LUA_REGISTRYINDEX, ads1115_timer_ref);
  311. ads1115_timer_ref = LUA_NOREF;
  312. lua_pushnumber(L, ads1115_volt);
  313. lua_pushinteger(L, ads1115_voltdec);
  314. lua_pushinteger(L, ads1115_conversion);
  315. lua_call (L, 3, 0);
  316. }
  317. // Read the conversion register from the ADC
  318. // Lua: volt,voltdec,adc = ads1115.read()
  319. static int ads1115_lua_read(lua_State *L) {
  320. ads1115_conversion = read_reg(ADS1115_POINTER_CONVERSION);
  321. ads1115_volt = get_volt(ads1115_conversion);
  322. int ads1115_voltdec = (int)((ads1115_volt - (int)ads1115_volt) * 1000);
  323. ads1115_voltdec = ads1115_voltdec>0?ads1115_voltdec:0-ads1115_voltdec;
  324. lua_pushnumber(L, ads1115_volt);
  325. lua_pushinteger(L, ads1115_voltdec);
  326. lua_pushinteger(L, ads1115_conversion);
  327. return 3;
  328. }
  329. static const LUA_REG_TYPE ads1115_map[] = {
  330. { LSTRKEY( "setup" ), LFUNCVAL(ads1115_lua_setup) },
  331. { LSTRKEY( "setting" ), LFUNCVAL(ads1115_lua_setting) },
  332. { LSTRKEY( "startread" ), LFUNCVAL(ads1115_lua_startread) },
  333. { LSTRKEY( "read" ), LFUNCVAL(ads1115_lua_read) },
  334. { LSTRKEY( "ADDR_GND" ), LNUMVAL(ADS1115_I2C_ADDR_GND) },
  335. { LSTRKEY( "ADDR_VDD" ), LNUMVAL(ADS1115_I2C_ADDR_VDD) },
  336. { LSTRKEY( "ADDR_SDA" ), LNUMVAL(ADS1115_I2C_ADDR_SDA) },
  337. { LSTRKEY( "ADDR_SCL" ), LNUMVAL(ADS1115_I2C_ADDR_SCL) },
  338. { LSTRKEY( "SINGLE_SHOT" ), LNUMVAL(ADS1115_MODE_SINGLE) },
  339. { LSTRKEY( "CONTINUOUS" ), LNUMVAL(ADS1115_MODE_CONTIN) },
  340. { LSTRKEY( "DIFF_0_1" ), LNUMVAL(ADS1115_MUX_DIFF_0_1) },
  341. { LSTRKEY( "DIFF_0_3" ), LNUMVAL(ADS1115_MUX_DIFF_0_3) },
  342. { LSTRKEY( "DIFF_1_3" ), LNUMVAL(ADS1115_MUX_DIFF_1_3) },
  343. { LSTRKEY( "DIFF_2_3" ), LNUMVAL(ADS1115_MUX_DIFF_2_3) },
  344. { LSTRKEY( "SINGLE_0" ), LNUMVAL(ADS1115_MUX_SINGLE_0) },
  345. { LSTRKEY( "SINGLE_1" ), LNUMVAL(ADS1115_MUX_SINGLE_1) },
  346. { LSTRKEY( "SINGLE_2" ), LNUMVAL(ADS1115_MUX_SINGLE_2) },
  347. { LSTRKEY( "SINGLE_3" ), LNUMVAL(ADS1115_MUX_SINGLE_3) },
  348. { LSTRKEY( "GAIN_6_144V" ), LNUMVAL(ADS1115_PGA_6_144V) },
  349. { LSTRKEY( "GAIN_4_096V" ), LNUMVAL(ADS1115_PGA_4_096V) },
  350. { LSTRKEY( "GAIN_2_048V" ), LNUMVAL(ADS1115_PGA_2_048V) },
  351. { LSTRKEY( "GAIN_1_024V" ), LNUMVAL(ADS1115_PGA_1_024V) },
  352. { LSTRKEY( "GAIN_0_512V" ), LNUMVAL(ADS1115_PGA_0_512V) },
  353. { LSTRKEY( "GAIN_0_256V" ), LNUMVAL(ADS1115_PGA_0_256V) },
  354. { LSTRKEY( "DR_8SPS" ), LNUMVAL(ADS1115_DR_8SPS) },
  355. { LSTRKEY( "DR_16SPS" ), LNUMVAL(ADS1115_DR_16SPS) },
  356. { LSTRKEY( "DR_32SPS" ), LNUMVAL(ADS1115_DR_32SPS) },
  357. { LSTRKEY( "DR_64SPS" ), LNUMVAL(ADS1115_DR_64SPS) },
  358. { LSTRKEY( "DR_128SPS" ), LNUMVAL(ADS1115_DR_128SPS) },
  359. { LSTRKEY( "DR_250SPS" ), LNUMVAL(ADS1115_DR_250SPS) },
  360. { LSTRKEY( "DR_475SPS" ), LNUMVAL(ADS1115_DR_475SPS) },
  361. { LSTRKEY( "DR_860SPS" ), LNUMVAL(ADS1115_DR_860SPS) },
  362. { LSTRKEY( "CONV_RDY_1" ), LNUMVAL(ADS1115_CQUE_1CONV) },
  363. { LSTRKEY( "CONV_RDY_2" ), LNUMVAL(ADS1115_CQUE_2CONV) },
  364. { LSTRKEY( "CONV_RDY_4" ), LNUMVAL(ADS1115_CQUE_4CONV) },
  365. { LSTRKEY( "COMP_1CONV" ), LNUMVAL(ADS1115_CQUE_1CONV) },
  366. { LSTRKEY( "COMP_2CONV" ), LNUMVAL(ADS1115_CQUE_2CONV) },
  367. { LSTRKEY( "COMP_4CONV" ), LNUMVAL(ADS1115_CQUE_4CONV) },
  368. { LNILKEY, LNILVAL }
  369. };
  370. NODEMCU_MODULE(ADS1115, "ads1115", ads1115_map, NULL);