periph 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +61 -12
  2. package/examples/accelerometer/adxl345/complete.js +52 -0
  3. package/examples/accelerometer/adxl345/demo.js +34 -0
  4. package/examples/accelerometer/adxl345/minimal.js +18 -0
  5. package/examples/accelerometer/adxl362/complete.js +57 -0
  6. package/examples/accelerometer/adxl362/demo.js +51 -0
  7. package/examples/accelerometer/adxl362/minimal.js +21 -0
  8. package/examples/adc_dac/ad7705/complete.js +32 -0
  9. package/examples/adc_dac/ad7705/demo.js +42 -0
  10. package/examples/adc_dac/ad7705/minimal.js +16 -0
  11. package/examples/adc_dac/ad7706/complete.js +35 -0
  12. package/examples/adc_dac/ad7706/demo.js +44 -0
  13. package/examples/adc_dac/ad7706/minimal.js +16 -0
  14. package/examples/adc_dac/hx710a/complete.js +45 -0
  15. package/examples/adc_dac/hx710a/demo.js +52 -0
  16. package/examples/adc_dac/hx710a/minimal.js +16 -0
  17. package/examples/adc_dac/hx710b/complete.js +45 -0
  18. package/examples/adc_dac/hx710b/demo.js +64 -0
  19. package/examples/adc_dac/hx710b/minimal.js +16 -0
  20. package/examples/adc_dac/hx711/complete.js +7 -7
  21. package/examples/adc_dac/hx711/demo.js +6 -6
  22. package/examples/adc_dac/hx711/minimal.js +7 -7
  23. package/examples/adc_dac/mcp4725/complete.js +19 -17
  24. package/examples/adc_dac/mcp4725/demo.js +5 -5
  25. package/examples/adc_dac/mcp4725/minimal.js +8 -6
  26. package/examples/adc_dac/mcp4728/complete.js +24 -22
  27. package/examples/adc_dac/mcp4728/demo.js +22 -22
  28. package/examples/adc_dac/mcp4728/minimal.js +8 -6
  29. package/examples/adc_dac/pcf8591/complete.js +41 -0
  30. package/examples/adc_dac/pcf8591/demo.js +39 -0
  31. package/examples/adc_dac/pcf8591/minimal.js +19 -0
  32. package/examples/comms/mcp2515/complete.js +75 -0
  33. package/examples/comms/mcp2515/demo.js +66 -0
  34. package/examples/comms/mcp2515/minimal.js +27 -0
  35. package/examples/comms/rda5807m/complete.js +55 -0
  36. package/examples/comms/rda5807m/demo.js +68 -0
  37. package/examples/comms/rda5807m/minimal.js +15 -0
  38. package/examples/comms/rfm9x/complete.js +50 -0
  39. package/examples/comms/rfm9x/demo.js +55 -0
  40. package/examples/comms/rfm9x/minimal.js +20 -0
  41. package/examples/display/pcf8576/complete.js +18 -15
  42. package/examples/display/pcf8576/demo.js +6 -6
  43. package/examples/display/pcf8576/minimal.js +12 -10
  44. package/examples/environmental/aht21/complete.js +15 -13
  45. package/examples/environmental/aht21/demo.js +8 -6
  46. package/examples/environmental/aht21/minimal.js +5 -5
  47. package/examples/environmental/bme280/complete.js +23 -20
  48. package/examples/environmental/bme280/demo.js +14 -14
  49. package/examples/environmental/bme280/minimal.js +13 -11
  50. package/examples/environmental/bme680/complete.js +25 -22
  51. package/examples/environmental/bme680/demo.js +38 -36
  52. package/examples/environmental/bme680/minimal.js +14 -12
  53. package/examples/gas/ens160/complete.js +29 -27
  54. package/examples/gas/ens160/demo.js +39 -37
  55. package/examples/gas/ens160/minimal.js +17 -15
  56. package/examples/gnss/neo6/complete.js +49 -0
  57. package/examples/gnss/neo6/demo.js +54 -0
  58. package/examples/gnss/neo6/minimal.js +30 -0
  59. package/examples/gyroscope/l3g4200d/complete.js +56 -0
  60. package/examples/gyroscope/l3g4200d/demo.js +49 -0
  61. package/examples/gyroscope/l3g4200d/minimal.js +19 -0
  62. package/examples/gyroscope/l3gd20h/complete.js +42 -0
  63. package/examples/gyroscope/l3gd20h/demo.js +29 -0
  64. package/examples/gyroscope/l3gd20h/minimal.js +13 -0
  65. package/examples/humidity/dht11/complete.js +22 -0
  66. package/examples/humidity/dht11/demo.js +38 -0
  67. package/examples/humidity/dht11/minimal.js +18 -0
  68. package/examples/imu/mpu6050/complete.js +27 -25
  69. package/examples/imu/mpu6050/demo.js +29 -26
  70. package/examples/imu/mpu6050/minimal.js +6 -6
  71. package/examples/imu/mpu9250/complete.js +65 -0
  72. package/examples/imu/mpu9250/demo.js +53 -0
  73. package/examples/imu/mpu9250/minimal.js +21 -0
  74. package/examples/imu/mpu9255/complete.js +73 -0
  75. package/examples/imu/mpu9255/demo.js +73 -0
  76. package/examples/imu/mpu9255/minimal.js +21 -0
  77. package/examples/io_expander/mcp23017/complete.js +70 -77
  78. package/examples/io_expander/mcp23017/demo.js +37 -33
  79. package/examples/io_expander/mcp23017/minimal.js +15 -11
  80. package/examples/io_expander/pcf8574/complete.js +60 -65
  81. package/examples/io_expander/pcf8574/demo.js +30 -25
  82. package/examples/io_expander/pcf8574/minimal.js +15 -11
  83. package/examples/io_expander/pcf8575/complete.js +24 -20
  84. package/examples/io_expander/pcf8575/demo.js +27 -23
  85. package/examples/io_expander/pcf8575/minimal.js +16 -12
  86. package/examples/io_expander/tpic6b595/complete.js +57 -0
  87. package/examples/io_expander/tpic6b595/demo.js +75 -0
  88. package/examples/io_expander/tpic6b595/minimal.js +26 -0
  89. package/examples/led/apa102/complete.js +72 -0
  90. package/examples/led/apa102/demo.js +92 -0
  91. package/examples/led/apa102/minimal.js +21 -0
  92. package/examples/led/sk6812rgbw/complete.js +42 -40
  93. package/examples/led/sk6812rgbw/demo.js +16 -16
  94. package/examples/led/sk6812rgbw/minimal.js +15 -17
  95. package/examples/led/ws2812b/complete.js +40 -38
  96. package/examples/led/ws2812b/demo.js +16 -16
  97. package/examples/led/ws2812b/minimal.js +13 -14
  98. package/examples/led/ws2814/complete.js +71 -0
  99. package/examples/led/ws2814/demo.js +82 -0
  100. package/examples/led/ws2814/minimal.js +23 -0
  101. package/examples/light/apds-9930/complete.js +46 -0
  102. package/examples/light/apds-9930/demo.js +31 -0
  103. package/examples/light/apds-9930/minimal.js +20 -0
  104. package/examples/light/apds9960/complete.js +45 -43
  105. package/examples/light/apds9960/demo.js +11 -9
  106. package/examples/light/apds9960/minimal.js +5 -5
  107. package/examples/magnetometer/as5600/complete.js +31 -29
  108. package/examples/magnetometer/as5600/demo.js +35 -33
  109. package/examples/magnetometer/as5600/minimal.js +7 -7
  110. package/examples/magnetometer/hmc5883l/complete.js +47 -0
  111. package/examples/magnetometer/hmc5883l/demo.js +50 -0
  112. package/examples/magnetometer/hmc5883l/minimal.js +15 -0
  113. package/examples/memory/24aa02uid/complete.js +23 -21
  114. package/examples/memory/24aa02uid/demo.js +32 -30
  115. package/examples/memory/24aa02uid/minimal.js +5 -5
  116. package/examples/motor/drv8830/complete.js +50 -0
  117. package/examples/motor/drv8830/demo.js +57 -0
  118. package/examples/motor/drv8830/minimal.js +23 -0
  119. package/examples/other/mpr121/complete.js +50 -0
  120. package/examples/other/mpr121/demo.js +30 -0
  121. package/examples/other/mpr121/minimal.js +17 -0
  122. package/examples/power/ade7953/complete.js +44 -0
  123. package/examples/power/ade7953/demo.js +28 -0
  124. package/examples/power/ade7953/minimal.js +15 -0
  125. package/examples/power/ina219/complete.js +20 -18
  126. package/examples/power/ina219/demo.js +15 -13
  127. package/examples/power/ina219/minimal.js +8 -8
  128. package/examples/power/ina226/complete.js +24 -22
  129. package/examples/power/ina226/demo.js +22 -20
  130. package/examples/power/ina226/minimal.js +5 -5
  131. package/examples/power/ina3221/complete.js +51 -49
  132. package/examples/power/ina3221/demo.js +13 -13
  133. package/examples/power/ina3221/minimal.js +8 -8
  134. package/examples/pressure/bmp085/complete.js +29 -0
  135. package/examples/pressure/bmp085/demo.js +34 -0
  136. package/examples/pressure/bmp085/minimal.js +19 -0
  137. package/examples/pressure/bmp180/complete.js +20 -17
  138. package/examples/pressure/bmp180/demo.js +24 -22
  139. package/examples/pressure/bmp180/minimal.js +13 -11
  140. package/examples/pressure/bmp280/complete.js +23 -20
  141. package/examples/pressure/bmp280/demo.js +44 -41
  142. package/examples/pressure/bmp280/minimal.js +13 -11
  143. package/examples/pressure/bmp384/complete.js +29 -0
  144. package/examples/pressure/bmp384/demo.js +40 -0
  145. package/examples/pressure/bmp384/minimal.js +18 -0
  146. package/examples/pressure/bmp581/complete.js +34 -0
  147. package/examples/pressure/bmp581/demo.js +56 -0
  148. package/examples/pressure/bmp581/minimal.js +19 -0
  149. package/examples/pressure/lps22df/complete.js +50 -0
  150. package/examples/pressure/lps22df/demo.js +41 -0
  151. package/examples/pressure/lps22df/minimal.js +19 -0
  152. package/examples/pressure/lps28dfw/complete.js +37 -0
  153. package/examples/pressure/lps28dfw/demo.js +33 -0
  154. package/examples/pressure/lps28dfw/minimal.js +19 -0
  155. package/examples/pressure/lps33hw/complete.js +43 -0
  156. package/examples/pressure/lps33hw/demo.js +43 -0
  157. package/examples/pressure/lps33hw/minimal.js +19 -0
  158. package/examples/rfid/mfrc522/complete.js +44 -0
  159. package/examples/rfid/mfrc522/demo.js +70 -0
  160. package/examples/rfid/mfrc522/minimal.js +17 -0
  161. package/examples/rtc/ds3231/complete.js +77 -0
  162. package/examples/rtc/ds3231/demo.js +60 -0
  163. package/examples/rtc/ds3231/minimal.js +23 -0
  164. package/examples/rtc/pcf8523/complete.js +66 -0
  165. package/examples/rtc/pcf8523/demo.js +65 -0
  166. package/examples/rtc/pcf8523/minimal.js +20 -0
  167. package/examples/temperature/mcp9808/complete.js +89 -0
  168. package/examples/temperature/mcp9808/demo.js +62 -0
  169. package/examples/temperature/mcp9808/minimal.js +21 -0
  170. package/examples/temperature/tmp117/complete.js +90 -0
  171. package/examples/temperature/tmp117/demo.js +73 -0
  172. package/examples/temperature/tmp117/minimal.js +21 -0
  173. package/examples/tof/vl53l0x/complete.js +118 -0
  174. package/examples/tof/vl53l0x/demo.js +83 -0
  175. package/examples/tof/vl53l0x/minimal.js +25 -0
  176. package/examples/tof/vl53l1x/complete.js +151 -0
  177. package/examples/tof/vl53l1x/demo.js +100 -0
  178. package/examples/tof/vl53l1x/minimal.js +25 -0
  179. package/package.json +5 -1
  180. package/src/chips/accelerometer/adxl345.js +482 -0
  181. package/src/chips/accelerometer/adxl362.js +594 -0
  182. package/src/chips/adc_dac/ad7705.js +345 -0
  183. package/src/chips/adc_dac/ad7706.js +331 -0
  184. package/src/chips/adc_dac/hx710a.js +184 -0
  185. package/src/chips/adc_dac/hx710b.js +186 -0
  186. package/src/chips/adc_dac/hx711.js +15 -15
  187. package/src/chips/adc_dac/mcp4725.js +48 -40
  188. package/src/chips/adc_dac/mcp4728.js +57 -44
  189. package/src/chips/adc_dac/pcf8591.js +196 -0
  190. package/src/chips/comms/mcp2515.js +659 -0
  191. package/src/chips/comms/rda5807m.js +393 -0
  192. package/src/chips/comms/rfm9x.js +590 -0
  193. package/src/chips/display/pcf8576.js +42 -33
  194. package/src/chips/environmental/aht21.js +52 -37
  195. package/src/chips/environmental/bme280.js +85 -66
  196. package/src/chips/environmental/bme680.js +110 -87
  197. package/src/chips/gas/ens160.js +82 -64
  198. package/src/chips/gnss/neo6.js +438 -0
  199. package/src/chips/gyroscope/l3g4200d.js +366 -0
  200. package/src/chips/gyroscope/l3gd20h.js +314 -0
  201. package/src/chips/humidity/dht11.js +135 -0
  202. package/src/chips/imu/mpu6050.js +89 -66
  203. package/src/chips/imu/mpu9250.js +394 -0
  204. package/src/chips/imu/mpu9255.js +447 -0
  205. package/src/chips/io_expander/mcp23017.js +240 -157
  206. package/src/chips/io_expander/pcf8574.js +149 -124
  207. package/src/chips/io_expander/pcf8575.js +164 -135
  208. package/src/chips/io_expander/tpic6b595.js +242 -0
  209. package/src/chips/led/_NeoPixelRGBBase.js +204 -0
  210. package/src/chips/led/_NeoPixelRGBWBase.js +218 -0
  211. package/src/chips/led/apa102.js +236 -0
  212. package/src/chips/led/sk6812rgbw.js +15 -149
  213. package/src/chips/led/ws2812b.js +14 -139
  214. package/src/chips/led/ws2814.js +49 -0
  215. package/src/chips/light/apds-9930.js +342 -0
  216. package/src/chips/light/apds9960.js +158 -123
  217. package/src/chips/magnetometer/as5600.js +102 -82
  218. package/src/chips/magnetometer/hmc5883l.js +222 -0
  219. package/src/chips/memory/_24aa02uid.js +32 -29
  220. package/src/chips/motor/drv8830.js +239 -0
  221. package/src/chips/other/mpr121.js +375 -0
  222. package/src/chips/power/ade7953.js +427 -0
  223. package/src/chips/power/ina219.js +45 -40
  224. package/src/chips/power/ina226.js +50 -45
  225. package/src/chips/power/ina3221.js +95 -76
  226. package/src/chips/pressure/bmp085.js +251 -0
  227. package/src/chips/pressure/bmp180.js +54 -37
  228. package/src/chips/pressure/bmp280.js +72 -53
  229. package/src/chips/pressure/bmp384.js +410 -0
  230. package/src/chips/pressure/bmp581.js +489 -0
  231. package/src/chips/pressure/lps22df.js +341 -0
  232. package/src/chips/pressure/lps28dfw.js +314 -0
  233. package/src/chips/pressure/lps33hw.js +255 -0
  234. package/src/chips/rfid/mfrc522.js +674 -0
  235. package/src/chips/rtc/ds3231.js +504 -0
  236. package/src/chips/rtc/pcf8523.js +539 -0
  237. package/src/chips/temperature/mcp9808.js +488 -0
  238. package/src/chips/temperature/tmp117.js +471 -0
  239. package/src/chips/tof/_vl53_base.js +160 -0
  240. package/src/chips/tof/vl53l0x.js +816 -0
  241. package/src/chips/tof/vl53l1x.js +816 -0
  242. package/src/connection/connection.js +111 -0
  243. package/src/connection/dhtxx.js +138 -0
  244. package/src/connection/dhtxx_mock.js +39 -0
  245. package/src/{transport → connection}/hx711.js +49 -22
  246. package/src/connection/hx711_mock.js +52 -0
  247. package/src/{transport → connection}/i2c.js +13 -9
  248. package/src/connection/i2c_mock.js +91 -0
  249. package/src/connection/input_pin.js +156 -0
  250. package/src/connection/neo6_mock.js +45 -0
  251. package/src/{transport → connection}/neopixel.js +23 -4
  252. package/src/connection/output_pin.js +41 -0
  253. package/src/connection/sipo.js +159 -0
  254. package/src/{transport → connection}/smbus.js +14 -10
  255. package/src/{transport → connection}/spi.js +12 -8
  256. package/src/connection/spi_mock.js +151 -0
  257. package/src/{transport → connection}/uart.js +33 -26
  258. package/examples/gnss/.gitkeep +0 -0
  259. package/examples/humidity/.gitkeep +0 -0
  260. package/examples/motor/.gitkeep +0 -0
  261. package/examples/temperature/.gitkeep +0 -0
  262. package/examples/tof/.gitkeep +0 -0
  263. package/src/chips/gnss/.gitkeep +0 -0
  264. package/src/chips/motor/.gitkeep +0 -0
  265. package/src/chips/temperature/.gitkeep +0 -0
  266. package/src/chips/tof/.gitkeep +0 -0
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ // Industrial freezer monitor: the healthy range is -25 °C to -15 °C, and
4
+ // -5 °C means the door has been left open too long. The Alert output fires
5
+ // in interrupt mode each time the temperature leaves or re-enters the
6
+ // window; the callback reports which boundary tripped. After a fixed number
7
+ // of alerts the monitor disables the Alert output and unsubscribes.
8
+
9
+ const { I2CConnection } = require('periph/src/connection/i2c');
10
+ const { MCP9808Full } = require('periph/src/chips/temperature/mcp9808');
11
+
12
+ const MAX_ALERTS = 10;
13
+
14
+ (async () => {
15
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
16
+ const connection = new I2CConnection(bus, MCP9808Full.I2C_ADDRESS);
17
+ const sensor = new MCP9808Full(connection); // Create MCP9808 Full driver, (connection)
18
+ await sensor.init(); // Confirm device identity, () → None
19
+
20
+ // --- Trade resolution for faster sampling ---
21
+ // 0.25 °C is plenty for a freezer and converts in ~65 ms instead of 250 ms,
22
+ // so a door opening shows up in the next reading almost immediately.
23
+ await sensor.setResolution(0.25); // Set resolution, (celsius 0.5|0.25|0.125|0.0625) → None
24
+
25
+ // --- Program the healthy window and the door-open threshold ---
26
+ // TLOWER/TUPPER bracket normal operation; TCRIT flags a door left open.
27
+ // 3 °C of hysteresis stops the Alert chattering while the compressor cycles.
28
+ await sensor.setLowerLimit(-25.0); // Set TLOWER, (celsius °C) → None
29
+ await sensor.setUpperLimit(-15.0); // Set TUPPER, (celsius °C) → None
30
+ await sensor.setCriticalLimit(-5.0); // Set TCRIT, (celsius °C) → None
31
+ await sensor.setHysteresis(3.0); // Set hysteresis, (celsius 0|1.5|3.0|6.0) → None
32
+
33
+ // --- Route every boundary to the Alert pin as a latched interrupt ---
34
+ // Interrupt mode latches each crossing until clearInterrupt(), so a short
35
+ // excursion is never missed between two reads.
36
+ await sensor.configureAlert('all', 'interrupt', 'active_low'); // Configure Alert, (mode='all', output='comparator', polarity='active_low') → None
37
+ await sensor.enableAlert(); // Enable Alert output, () → None
38
+
39
+ let alerts = 0;
40
+ let done;
41
+ const finished = new Promise((r) => { done = r; });
42
+
43
+ // --- Report which boundary tripped, then re-arm ---
44
+ // The status mask is a live read of TA's boundary bits; an empty mask
45
+ // means the temperature has come back inside the healthy window.
46
+ await sensor.onInterrupt(async (status) => { // Subscribe to Alert, (callback) → None
47
+ const t = await sensor.readTemperature(); // Read ambient temperature, () → number °C
48
+ if (status & MCP9808Full.SOURCE_CRITICAL) console.log(`${t.toFixed(2)} °C CRITICAL — door open?`);
49
+ else if (status & MCP9808Full.SOURCE_UPPER) console.log(`${t.toFixed(2)} °C too warm`);
50
+ else if (status & MCP9808Full.SOURCE_LOWER) console.log(`${t.toFixed(2)} °C too cold`);
51
+ else console.log(`${t.toFixed(2)} °C back in range`);
52
+ await sensor.clearInterrupt(); // Clear interrupt-mode Alert, () → None
53
+ if (++alerts >= MAX_ALERTS) done();
54
+ });
55
+ console.log(`monitoring, ${(await sensor.readTemperature()).toFixed(2)} °C now`); // Read ambient temperature, () → number °C
56
+ await finished;
57
+
58
+ // --- Shut down cleanly after the demo run ---
59
+ await sensor.disableAlert(); // Disable Alert output, () → None
60
+ await sensor.offInterrupt(); // Unsubscribe, () → None
61
+ await connection.close();
62
+ })();
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { MCP9808Minimal } = require('periph/src/chips/temperature/mcp9808');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, MCP9808Minimal.I2C_ADDRESS);
11
+ const sensor = new MCP9808Minimal(connection); // Create MCP9808 driver, (connection)
12
+ await sensor.init(); // Confirm device identity, () → None
13
+
14
+ for (let i = 0; i < 10; i++) {
15
+ const t = await sensor.readTemperature(); // Read ambient temperature, () → number °C
16
+ console.log(`${t.toFixed(4)} °C`);
17
+ await sleep(1000);
18
+ }
19
+
20
+ await connection.close();
21
+ })();
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ // Exercises every method in the TMP117 Full API. EEPROM unlock/lock is shown
4
+ // without any write in between, so no power-on default is changed.
5
+
6
+ const { I2CConnection } = require('periph/src/connection/i2c');
7
+ const { TMP117Full } = require('periph/src/chips/temperature/tmp117');
8
+
9
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
10
+
11
+ (async () => {
12
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
13
+ const connection = new I2CConnection(bus, TMP117Full.I2C_ADDRESS);
14
+ const sensor = new TMP117Full(connection); // Create TMP117 Full driver, (connection)
15
+ await sensor.init(); // Confirm device identity, () → None
16
+ // checks DEVICE_ID bits 11:0 == 0x117
17
+
18
+ const t = await sensor.readTemperature(); // Read temperature, () → number °C
19
+ // decodes TEMP_RESULT, 0.0078125 °C two's complement
20
+ console.log(`temperature ${t.toFixed(4)} °C`);
21
+
22
+ await sensor.configure('continuous', 32, 0.5); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
23
+ // writes MOD/AVG/CONV; cycle snaps to the nearest CONV step
24
+ console.log('config', await sensor.getConfig()); // Read conversion config, () → {mode, averaging, cycleSeconds s}
25
+ // decodes MOD, AVG and CONV from CONFIGURATION
26
+
27
+ await sensor.configure('shutdown'); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
28
+ // MOD=01 stops conversions; TEMP_RESULT keeps its last value
29
+ console.log('shutdown', await sensor.isShutdown()); // Check Shutdown mode, () → boolean
30
+ // reads MOD[1:0] == 01
31
+ await sensor.triggerOneShot(); // Start one conversion, () → None
32
+ // MOD=11; returns to Shutdown when done
33
+ while (!(await sensor.isDataReady())) { // Check for a fresh result, () → boolean
34
+ await sleep(10); // reading Data_Ready clears it
35
+ }
36
+ console.log(`one-shot ${(await sensor.readTemperature()).toFixed(4)} °C`); // Read temperature, () → number °C
37
+ // the one-shot result
38
+ await sensor.configure(); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
39
+ // back to the POR default
40
+
41
+ await sensor.setHighLimit(30.0); // Set THIGH_LIMIT, (celsius °C) → None
42
+ // rounded to the nearest 0.0078125 °C step
43
+ await sensor.setLowLimit(10.0); // Set TLOW_LIMIT, (celsius °C) → None
44
+ // rounded to the nearest 0.0078125 °C step
45
+ console.log('high', await sensor.getHighLimit()); // Read THIGH_LIMIT, () → number °C
46
+ // same format as TEMP_RESULT
47
+ console.log('low', await sensor.getLowLimit()); // Read TLOW_LIMIT, () → number °C
48
+ // same format as TEMP_RESULT
49
+
50
+ await sensor.setTemperatureOffset(0.25); // Set calibration offset, (celsius °C) → None
51
+ // added to every result after linearization
52
+ console.log('offset', await sensor.getTemperatureOffset()); // Read calibration offset, () → number °C
53
+ // decodes TEMP_OFFSET
54
+ await sensor.setTemperatureOffset(0.0); // Set calibration offset, (celsius °C) → None
55
+ // remove the offset again
56
+
57
+ await sensor.unlockEeprom(); // Unlock EEPROM, () → None
58
+ // EUN=1: EEPROM-backed writes now persist
59
+ console.log('eeprom busy', await sensor.isEepromBusy()); // Check EEPROM busy, () → boolean
60
+ // reads EEPROM_UL.EEPROM_Busy
61
+ await sensor.lockEeprom(); // Lock EEPROM, () → None
62
+ // EUN=0: writes are volatile again
63
+ const eeprom1 = await sensor.readEepromScratch(1); // Read EEPROM scratch, (slot 1|2|3) → number
64
+ // slot 1 holds part of the factory unique ID
65
+ console.log(`eeprom1 0x${eeprom1.toString(16).padStart(4, '0')}`);
66
+ await sensor.writeEepromScratch(2, 0x1234); // Write EEPROM scratch, (slot 2, value 16-bit) → None
67
+ // only EEPROM2 is writable; volatile while locked
68
+ const eeprom2 = await sensor.readEepromScratch(2); // Read EEPROM scratch, (slot 1|2|3) → number
69
+ // reads back EEPROM2
70
+ console.log(`eeprom2 0x${eeprom2.toString(16).padStart(4, '0')}`);
71
+
72
+ await sensor.configureAlert('alert', 'active_low', 'alert'); // Configure ALERT, (mode='alert', polarity='active_low', pinFunction='alert') → None
73
+ // sets T/nA, POL and DR/Alert together
74
+
75
+ const status = await sensor.pollInterrupt(); // Read alert flags, () → number mask
76
+ // HIGH_Alert/LOW_Alert; the read clears them in Alert mode
77
+ console.log('above high', (status & TMP117Full.SOURCE_HIGH) !== 0,
78
+ 'below low', (status & TMP117Full.SOURCE_LOW) !== 0);
79
+
80
+ await sensor.onInterrupt((s) => console.log('alert, status mask', s)); // Subscribe to ALERT, (callback) → None
81
+ // callback receives the pollInterrupt() mask
82
+ await sleep(5000);
83
+ await sensor.offInterrupt(); // Unsubscribe, () → None
84
+ // detaches the edge handler or stops the polling timer
85
+
86
+ await sensor.reset(); // Software reset, () → None
87
+ // reloads CONFIGURATION/limits/offset from EEPROM, 2 ms
88
+
89
+ await connection.close();
90
+ })();
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ // PT100-replacement cold-chain container thermometer: maximum averaging gives
4
+ // the lowest-noise reading, and the ALERT output fires when the cargo leaves
5
+ // the -25 °C to 8 °C safe transport range; the callback reports which
6
+ // boundary tripped. Set REFERENCE_C to a reference thermometer reading to
7
+ // calibrate once and persist the offset to EEPROM. After a fixed number of
8
+ // alerts the monitor unsubscribes.
9
+
10
+ const { I2CConnection } = require('periph/src/connection/i2c');
11
+ const { TMP117Full } = require('periph/src/chips/temperature/tmp117');
12
+
13
+ const MAX_ALERTS = 10;
14
+ const REFERENCE_C = process.env.REFERENCE_C ? parseFloat(process.env.REFERENCE_C) : null;
15
+
16
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
17
+
18
+ (async () => {
19
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
20
+ const connection = new I2CConnection(bus, TMP117Full.I2C_ADDRESS);
21
+ const sensor = new TMP117Full(connection); // Create TMP117 Full driver, (connection)
22
+ await sensor.init(); // Confirm device identity, () → None
23
+
24
+ // --- Lowest-noise continuous conversion ---
25
+ // 64-conversion averaging with a 1 s cycle gives the quietest result the
26
+ // chip can deliver — a cold-chain log needs stability, not speed.
27
+ await sensor.configure('continuous', 64, 1.0); // Configure conversion, (mode='continuous', averaging=8, cycleSeconds=1.0 s) → None
28
+
29
+ // --- One-time calibration against a reference thermometer ---
30
+ // The observed error is written to TEMP_OFFSET with the EEPROM unlocked, so
31
+ // the correction survives power cycles. EEPROM endurance is limited — this
32
+ // is a once-per-deployment step, not a loop.
33
+ if (REFERENCE_C !== null) {
34
+ await sleep(1100);
35
+ const offset = REFERENCE_C - (await sensor.readTemperature()) // Read temperature, () → number °C
36
+ + (await sensor.getTemperatureOffset()); // Read calibration offset, () → number °C
37
+ await sensor.unlockEeprom(); // Unlock EEPROM, () → None
38
+ await sensor.setTemperatureOffset(offset); // Set calibration offset, (celsius °C) → None
39
+ while (await sensor.isEepromBusy()) { // Check EEPROM busy, () → boolean
40
+ await sleep(1);
41
+ }
42
+ await sensor.lockEeprom(); // Lock EEPROM, () → None
43
+ console.log(`calibrated, offset ${offset.toFixed(4)} °C`);
44
+ }
45
+
46
+ // --- Program the safe transport range ---
47
+ // Alert mode flags either side of the window independently; ALERT is
48
+ // active-low open-drain, pulled up on the board.
49
+ await sensor.setHighLimit(8.0); // Set THIGH_LIMIT, (celsius °C) → None
50
+ await sensor.setLowLimit(-25.0); // Set TLOW_LIMIT, (celsius °C) → None
51
+ await sensor.configureAlert('alert', 'active_low'); // Configure ALERT, (mode='alert', polarity='active_low', pinFunction='alert') → None
52
+
53
+ let alerts = 0;
54
+ let done;
55
+ const finished = new Promise((r) => { done = r; });
56
+
57
+ // --- Report which boundary tripped ---
58
+ // The status mask comes from CONFIGURATION's alert flags; reading them
59
+ // clears them in Alert mode, re-arming the pin for the next excursion.
60
+ await sensor.onInterrupt(async (status) => { // Subscribe to ALERT, (callback) → None
61
+ if (!status) return;
62
+ const t = await sensor.readTemperature(); // Read temperature, () → number °C
63
+ if (status & TMP117Full.SOURCE_HIGH) console.log(`${t.toFixed(2)} °C too warm — cargo above 8 °C`);
64
+ else if (status & TMP117Full.SOURCE_LOW) console.log(`${t.toFixed(2)} °C too cold — cargo below -25 °C`);
65
+ if (++alerts >= MAX_ALERTS) done();
66
+ });
67
+ console.log(`monitoring, ${(await sensor.readTemperature()).toFixed(2)} °C now`); // Read temperature, () → number °C
68
+ await finished;
69
+
70
+ // --- Stop monitoring after the demo run ---
71
+ await sensor.offInterrupt(); // Unsubscribe, () → None
72
+ await connection.close();
73
+ })();
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { TMP117Minimal } = require('periph/src/chips/temperature/tmp117');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, TMP117Minimal.I2C_ADDRESS);
11
+ const sensor = new TMP117Minimal(connection); // Create TMP117 driver, (connection)
12
+ await sensor.init(); // Confirm device identity, () → None
13
+
14
+ for (let i = 0; i < 10; i++) {
15
+ const t = await sensor.readTemperature(); // Read temperature, () → number °C
16
+ console.log(`${t.toFixed(4)} °C`);
17
+ await sleep(1000);
18
+ }
19
+
20
+ await connection.close();
21
+ })();
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ // Exercises every method in the VL53L0X Full API, and finally moves the
4
+ // sensor to another I²C address and back to 0x29.
5
+
6
+ const { I2CConnection } = require('periph/src/connection/i2c');
7
+ const { VL53L0XFull } = require('periph/src/chips/tof/vl53l0x');
8
+
9
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
10
+
11
+ (async () => {
12
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
13
+ const connection = new I2CConnection(bus, VL53L0XFull.I2C_ADDRESS);
14
+ const sensor = new VL53L0XFull(connection); // Create VL53L0X Full driver, (connection)
15
+ await sensor.init(); // Wait for init sequence, () → None
16
+ // ID check, tuning, SPADs, VHV + phase calibration
17
+
18
+ console.log('model', (await sensor.modelId()).toString(16)); // Read model ID, () → number
19
+ // IDENTIFICATION_MODEL_ID, always 0xEE
20
+ console.log('revision', (await sensor.revisionId()).toString(16)); // Read revision ID, () → number
21
+ // IDENTIFICATION_REVISION_ID, 0x10 on current silicon
22
+
23
+ const d = await sensor.distance(); // Measure distance, () → number mm
24
+ // single shot; blocks for about one timing budget
25
+ console.log('distance', d, 'mm, valid', await sensor.rangeValid()); // Check last measurement, () → boolean
26
+ // device range status == 11 (range complete)
27
+ console.log('range status', await sensor.rangeStatus()); // Read last range status, () → number 0–15
28
+ // 11 = valid, 4 = no target
29
+ const m = await sensor.readMeasurement(); // Read result block, () → {distanceMm, rangeStatus, signalRateMcps, ambientRateMcps, effectiveSpadCount}
30
+ // distance, status, signal/ambient MCPS, SPAD count
31
+ console.log(`signal ${m.signalRateMcps.toFixed(2)} MCPS, ambient ${m.ambientRateMcps.toFixed(2)} MCPS`);
32
+
33
+ await sensor.startContinuous(); // Start continuous ranging, (periodMs=0 ms) → None
34
+ // 0 = back-to-back measurements
35
+ for (let i = 0; i < 5; i++) {
36
+ console.log('continuous', await sensor.readContinuous(), 'mm'); // Read next continuous result, () → number mm
37
+ // waits for a fresh data-ready, then clears it
38
+ }
39
+ await sensor.stopContinuous(); // Stop continuous ranging, () → None
40
+ // does not wait for a running measurement
41
+
42
+ await sensor.startContinuous(100); // Start continuous ranging, (periodMs=0 ms) → None
43
+ // timed mode: one measurement every 100 ms
44
+ while (!(await sensor.dataReady())) { // Check for a result, () → boolean
45
+ await sleep(10); // RESULT_INTERRUPT_STATUS bits 2:0 non-zero
46
+ }
47
+ console.log('timed', (await sensor.readMeasurement()).distanceMm, 'mm'); // Read result block, () → {distanceMm, …}
48
+ // non-blocking; clears the interrupt
49
+ await sensor.stopContinuous(); // Stop continuous ranging, () → None
50
+ // back to software standby
51
+
52
+ console.log('budget', await sensor.timingBudget(), 'us'); // Read timing budget, () → number µs
53
+ // computed from the sequence-step timeouts
54
+ await sensor.setTimingBudget(50000); // Set timing budget, (budgetUs µs) → None
55
+ // longer budget = lower noise, ≥ 20000 µs
56
+ console.log('signal limit', await sensor.signalRateLimit(), 'MCPS'); // Read signal-rate limit, () → number MCPS
57
+ // 9.7 fixed point
58
+ await sensor.setSignalRateLimit(0.1); // Set signal-rate limit, (limitMcps MCPS) → None
59
+ // lower = longer range, more noise
60
+ await sensor.setVcselPulsePeriod('pre_range', 18); // Set VCSEL period, (periodType, pclks) → None
61
+ // pre-range 12/14/16/18; redoes phase calibration
62
+ await sensor.setVcselPulsePeriod('final_range', 14); // Set VCSEL period, (periodType, pclks) → None
63
+ // final-range 8/10/12/14
64
+ console.log('vcsel', await sensor.vcselPulsePeriod('pre_range'), // Read VCSEL period, (periodType) → number PCLKs
65
+ await sensor.vcselPulsePeriod('final_range')); // (reg + 1) × 2
66
+ await sensor.setProfile('default'); // Apply ranging profile, (profile) → None
67
+ // 0.25 MCPS, 14/10 PCLKs, 33 ms
68
+
69
+ const original = await sensor.offset(); // Read range offset, () → number mm
70
+ // NVM factory value, 0.25 mm steps
71
+ await sensor.setOffset(original - 5); // Set range offset, (offsetMm mm) → None
72
+ // volatile override, −512.0 to 511.75 mm
73
+ console.log('offset', await sensor.offset(), 'mm'); // Read range offset, () → number mm
74
+ // 12-bit two's complement × 0.25
75
+ await sensor.setOffset(original); // Set range offset, (offsetMm mm) → None
76
+ // restore the factory value
77
+ await sensor.setCrosstalkCompensation(0); // Set crosstalk compensation, (rateMcps MCPS) → None
78
+ // 0 = compensation off
79
+
80
+ await sensor.recalibrate(); // Rerun reference calibration, () → None
81
+ // VHV + phase; needed after a > 8 °C change
82
+
83
+ await sensor.setInterruptThresholds(100, 800); // Set distance thresholds, (lowMm mm, highMm mm) → None
84
+ // 2 mm resolution
85
+ console.log('thresholds', await sensor.interruptThresholds()); // Read distance thresholds, () → {lowMm, highMm} mm
86
+ // decoded from SYSTEM_THRESH_LOW/HIGH
87
+ await sensor.enableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Select interrupt source, (source) → None
88
+ // replaces the active source (mutually exclusive)
89
+ await sensor.disableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Disable interrupt source, (source) → None
90
+ // only if it is the active one
91
+ await sensor.enableInterrupt(VL53L0XFull.SOURCE_NEW_SAMPLE_READY); // Select interrupt source, (source) → None
92
+ // back to the default data-ready source
93
+
94
+ await sensor.onInterrupt((status) => console.log('interrupt, source', status)); // Subscribe to GPIO1, (callback) → None
95
+ // status is read and cleared before the callback
96
+ await sensor.startContinuous(200); // Start continuous ranging, (periodMs=0 ms) → None
97
+ // timed mode feeds the subscription
98
+ await sleep(1000);
99
+ await sensor.stopContinuous(); // Stop continuous ranging, () → None
100
+ // no more samples
101
+ await sensor.offInterrupt(); // Unsubscribe, () → None
102
+ // detaches the pin handler or stops the polling timer
103
+ console.log('pending', await sensor.pollInterrupt()); // Read and clear status, () → number
104
+ // SOURCE_* value that fired, 0 = nothing pending
105
+
106
+ await sensor.setAddress(0x30); // Change I²C address, (address) → None
107
+ // volatile; this driver instance is now unusable
108
+ await connection.close();
109
+ const movedConnection = new I2CConnection(bus, 0x30);
110
+ const moved = new VL53L0XFull(movedConnection); // Create VL53L0X Full driver, (connection)
111
+ await moved.init(); // Wait for init sequence, () → None
112
+ // re-init at the new address is safe
113
+ console.log('at 0x30', await moved.distance(), 'mm'); // Measure distance, () → number mm
114
+ // same sensor, new address
115
+ await moved.setAddress(VL53L0XFull.I2C_ADDRESS); // Change I²C address, (address) → None
116
+ // back to the power-on 0x29
117
+ await movedConnection.close();
118
+ })();
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ // Touchless presence gate with multi-rate ranging: a first measurement picks
4
+ // the profile (long range in a dark room, default otherwise), then timed
5
+ // continuous ranging at 100 ms feeds an out-of-window interrupt — closer than
6
+ // 10 cm is an ENTER event, the scene clearing beyond 80 cm a LEAVE event.
7
+ // After 20 events or 60 s, it prints statistics over 10 fresh samples, stops
8
+ // ranging and recalibrates. Without a GPIO1 pin on the connection the
9
+ // driver's polling fallback delivers the events.
10
+
11
+ const { I2CConnection } = require('periph/src/connection/i2c');
12
+ const { VL53L0XFull } = require('periph/src/chips/tof/vl53l0x');
13
+
14
+ const MAX_EVENTS = 20;
15
+ const MAX_MS = 60000;
16
+
17
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
18
+
19
+ (async () => {
20
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
21
+ const connection = new I2CConnection(bus, VL53L0XFull.I2C_ADDRESS);
22
+ const sensor = new VL53L0XFull(connection); // Create VL53L0X Full driver, (connection)
23
+ await sensor.init(); // Wait for init sequence, () → None
24
+
25
+ // --- Pick a profile from the ambient light level ---
26
+ // The long-range profile (0.1 MCPS limit, 18/14 PCLK VCSEL periods) reaches
27
+ // ~2 m, but only without IR background; in daylight it mostly adds invalid
28
+ // readings. One single-shot measurement tells us how bright the scene is.
29
+ await sensor.distance(); // Measure distance, () → number mm
30
+ const first = await sensor.readMeasurement(); // Read result block, () → {distanceMm, …}
31
+ if (first.ambientRateMcps < 0.5) {
32
+ await sensor.setProfile('long_range'); // Apply ranging profile, (profile) → None
33
+ console.log(`dark scene (${first.ambientRateMcps.toFixed(2)} MCPS ambient): long_range profile`);
34
+ } else {
35
+ await sensor.setProfile('default'); // Apply ranging profile, (profile) → None
36
+ console.log(`bright scene (${first.ambientRateMcps.toFixed(2)} MCPS ambient): default profile`);
37
+ }
38
+
39
+ // --- Arm the presence gate ---
40
+ // Timed ranging every 100 ms keeps the laser mostly idle. The firmware
41
+ // compares each result with the 100 mm / 800 mm window itself and only
42
+ // raises GPIO1 when a reading falls outside it.
43
+ await sensor.setInterruptThresholds(100, 800); // Set distance thresholds, (lowMm mm, highMm mm) → None
44
+ await sensor.enableInterrupt(VL53L0XFull.SOURCE_OUT_OF_WINDOW); // Select interrupt source, (source) → None
45
+ await sensor.startContinuous(100); // Start continuous ranging, (periodMs=0 ms) → None
46
+
47
+ // --- Classify each event ---
48
+ // The status is already cleared; the result block still holds the
49
+ // measurement that triggered it.
50
+ let events = 0;
51
+ await sensor.onInterrupt(async () => { // Subscribe to GPIO1, (callback) → None
52
+ const d = (await sensor.readMeasurement()).distanceMm; // Read result block, () → {distanceMm, …}
53
+ events++;
54
+ console.log(d < 100 ? 'ENTER' : 'LEAVE', d, 'mm');
55
+ });
56
+ const start = Date.now();
57
+ while (events < MAX_EVENTS && Date.now() - start < MAX_MS) await sleep(50);
58
+
59
+ // --- Statistics over fresh samples ---
60
+ // Threshold sources hide ordinary samples from dataReady(), so switch back
61
+ // to new-sample-ready before using the blocking continuous reads.
62
+ await sensor.offInterrupt(); // Unsubscribe, () → None
63
+ await sensor.enableInterrupt(VL53L0XFull.SOURCE_NEW_SAMPLE_READY); // Select interrupt source, (source) → None
64
+ await sensor.pollInterrupt(); // Read and clear status, () → number
65
+ const samples = [];
66
+ let rate = 0;
67
+ for (let i = 0; i < 10; i++) {
68
+ samples.push(await sensor.readContinuous()); // Read next continuous result, () → number mm
69
+ rate += (await sensor.readMeasurement()).signalRateMcps; // Read result block, () → {signalRateMcps, …}
70
+ }
71
+ const mean = samples.reduce((a, b) => a + b, 0) / samples.length;
72
+ console.log(`mean ${mean.toFixed(0)} mm, min ${Math.min(...samples)} mm, max ${Math.max(...samples)} mm, ` +
73
+ `signal ${(rate / samples.length).toFixed(2)} MCPS`);
74
+
75
+ // --- Shut down and recalibrate ---
76
+ // Reference calibration must run in software standby. Repeat it whenever
77
+ // the sensor's temperature has drifted more than 8 °C.
78
+ await sensor.stopContinuous(); // Stop continuous ranging, () → None
79
+ await sleep(200);
80
+ await sensor.recalibrate(); // Rerun reference calibration, () → None
81
+ console.log('done');
82
+ await connection.close();
83
+ })();
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { VL53L0XMinimal } = require('periph/src/chips/tof/vl53l0x');
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ (async () => {
9
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
10
+ const connection = new I2CConnection(bus, VL53L0XMinimal.I2C_ADDRESS);
11
+ const sensor = new VL53L0XMinimal(connection); // Create VL53L0X driver, (connection)
12
+ await sensor.init(); // Wait for init sequence, () → None
13
+
14
+ for (let i = 0; i < 50; i++) {
15
+ const d = await sensor.distance(); // Measure distance, () → number mm
16
+ if (await sensor.rangeValid()) { // Check last measurement, () → boolean
17
+ console.log(`${d} mm`);
18
+ } else {
19
+ console.log('out of range');
20
+ }
21
+ await sleep(100);
22
+ }
23
+
24
+ await connection.close();
25
+ })();