denko 0.13.3 → 0.13.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '082654ef6ccaec931c9cba643db7c528cc8b20d33e969af6a101a735078b7c02'
4
- data.tar.gz: 780397a81acfa1a44591deb0c1beedb6f39071b606fb108914c79af334e47847
3
+ metadata.gz: db3ab91a78e9e78ce4f973237f2de09e93561d8dae7cd239708ab9ab85bff3c7
4
+ data.tar.gz: bb904d187be4fbeaa238ee8d259d7f24abecc900b2244c9d01599752141c019f
5
5
  SHA512:
6
- metadata.gz: 58e7ec2753368aa202a63792c6f142bd150a386c95d37605ee4c1985022d4c06e552108f504675c599effcde0e0438b7d1029d0c700ec7fee40fffdffc60d1f4
7
- data.tar.gz: fec058bef713c8f5c7e84eed3dd87a84db93267e921abb27d3c4966b40bf66a223a3a76442559742bec04a58665e18d3d8d30cd3954fdb846148e5d1fb3b0cd2
6
+ metadata.gz: f943f022e9058de0cc22ff88ea35588c78f35ea6282a72f5607e5059f73b5975fbd3c05ca5fa06448aff19e90227e67d9b38e0359a9168a13d08ed70dfa38028
7
+ data.tar.gz: 3fc9bca5801515fc7f1ba01aefd13888b9e9acb84e434335e571c75d383afbcccef066c285b749f12a0a9ab470dfb87b3a39c7aa16193b9e250785e6c55313a0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.5
4
+
5
+ ### New Components
6
+
7
+ - HC-SR04 Ultrasonic Distance Sensor:
8
+ - Class: `Denko::Sensor::HCSRO4`
9
+ - Custom function on the board to handle ping and response.
10
+ - Simple interface. `#read` returns a distance in mm.
11
+
12
+ ### Bug Fixes
13
+
14
+ - OTA updating now works on ESP32.
15
+ - Adjust ESP32 expected serial buffer sizes and acknowledge intervals to to be more reliable.
16
+ - Fixed a bug on Windows where submodules weren't being included in load path.
17
+ - Fixed a bug where the board could incorrectly report EEPROM_LENGTH as 0.
18
+
19
+ ## 0.13.4
20
+
21
+ ### New Components
22
+
23
+ - Generic PIR sensors:
24
+ - Class: `Denko::Sensor::GenericPIR`
25
+ - Based on `Denko::DigitalIO::Input` class.
26
+ - Tested with AS312 and HC-SR501 sensors. Should work with AM312 and others.
27
+
28
+ - Bosch BMP 180 Temperature + Pressure Sensor:
29
+ - Class: `Denko::Sensor::BMP180`
30
+ - Connects via I2C bus. Ruby driver.
31
+ - Similar to BMP280, but fewer features (older version).
32
+ - Should work for BMP085 sensor as well.
33
+
34
+ - SHT30/31/35 Temperature + Humidity Sensor:
35
+ - Class: `Denko::Sensor::SHTX`
36
+ - Connects via I2C bus. Ruby driver.
37
+ - One-shot reading mode only.
38
+
39
+ - RCWL-9620 Ultrasonic Distance Sensor:
40
+ - Class: `Denko::Sensor::RCWL9620`
41
+ - Connects via I2C bus. Ruby driver.
42
+ - Very simple interface. `#read` returns a distance in mm.
43
+
44
+ ### Component Changes
45
+
46
+ - HTU21D:
47
+ - Humidity values outside the 0-100% range will be clipped to those values automatically.
48
+
49
+ ### Example Changes
50
+
51
+ - Added a simple button example, separate from tutorial.
52
+ - Standardize temp/pressure/humidity sensor examples (except DHT, DS18B20, HTU21D) so readings display the same.
53
+
54
+ ### Bug Fixes
55
+
56
+ - Fixed bug where `BMP280` sensor class would not autoload.
57
+
3
58
  ## 0.13.3
4
59
 
5
60
  ### Board Updates / Fixes
data/DEPS_IDE.md CHANGED
@@ -33,7 +33,8 @@ All platforms will require libraries to be installed. To install a library do th
33
33
  Arduino SAMD Boards (32-bits ARM Cortex-M0+)
34
34
  Arduino UNO R4 Boards
35
35
  ESP8266 Boards
36
- ESP32 Boards
36
+ ESP32 Boards
37
+ Raspberry Pi Pico/RP2040
37
38
  ````
38
39
  * Libraries:
39
40
  ````
@@ -119,7 +120,7 @@ All platforms will require libraries to be installed. To install a library do th
119
120
  ````
120
121
  * Boards:
121
122
  ````
122
- Raspberry Pi Pico/RP2040
123
+ Raspberry Pi Pico/RP2040
123
124
  ````
124
125
  * Libraries:
125
126
  ````
data/HARDWARE.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  | Chip | Status | Products | Notes |
10
10
  | :-------- | :------: | :--------------- |------ |
11
- | ATmega168 | :green_heart: | Duemilanove, Diecimila, Pro | Features omitted to save memory. `denko targets` for more info.
11
+ | ATmega168 | :green_heart: | Duemilanove, Diecimila, Pro | Omits features. `denko targets` for info.
12
12
  | ATmega328 | :green_heart: | Uno R3, Uno WiFi, Nano, Fio, Pro |
13
13
  | ATmega32u4 | :green_heart: | Leonardo, Micro, Leonardo ETH, Esplora, LilyPad USB |
14
14
  | ATmega1280 | :green_heart: | Mega |
@@ -24,7 +24,7 @@
24
24
 
25
25
  | Chip | Status | Products | Notes |
26
26
  | :-------- | :------: | :--------------- |------ |
27
- | ATSAM3X8E | :yellow_heart: | Due | Native USB port. Tone, and IR Out don't work.
27
+ | ATSAM3X8E | :yellow_heart: | Due | Uses Native USB. Tone and IR Out don't work.
28
28
  | ATSAMD21 | :green_heart: | Zero, M0 Series, Nano 33 IOT, MKR WiFi 1010 | Native USB
29
29
  | RA4M1 | :yellow_heart: | Uno R4 Minima, Uno R4 WiFi | IR and WS2812 libraries don't support this yet
30
30
 
@@ -37,6 +37,12 @@
37
37
  | ATWINC1500 | :green_heart: | MKR1000, WiFi Shield 101 | #define WIFI_101 for shield. Automatic for MKR1000
38
38
  | u-blox NINA-W102 | :question: | Uno WiFi Rev 2, MKR WiFi 1010, Nano 33 IOT | Should work. No hardware
39
39
 
40
+ ### AVR Chips from [MightyCore](https://github.com/MCUdude/MightyCore)
41
+
42
+ | Chip | Status | Products | Notes |
43
+ | :-------- | :------: | :--------------- |------ |
44
+ | ATmega1284 | :heart: | Used in many 8-bit 3D printer boards. |
45
+
40
46
  ### Espressif Chips with Built-In Wi-Fi
41
47
  [![ESP8266 Build Status](https://github.com/denko-rb/denko/actions/workflows/build_esp8266.yml/badge.svg)](https://github.com/denko-rb/denko/actions/workflows/build_esp8266.yml)
42
48
  [![ESP32 Build Status](https://github.com/denko-rb/denko/actions/workflows/build_esp32.yml/badge.svg)](https://github.com/denko-rb/denko/actions/workflows/build_esp32.yml)
@@ -49,6 +55,8 @@
49
55
  | ESP32-S2 | :green_heart: | LOLIN S2 Pico | Native USB
50
56
  | ESP32-S3 | :green_heart: | LOLIN S3 V1.0.0 | Native USB
51
57
  | ESP32-C3 | :green_heart: | LOLIN C3 Mini V2.1.0 | Native USB
58
+ | ESP32-H2 | :heart: | - | Support in Arduino ESP32 core beta
59
+ | ESP32-C6 | :heart: | - | Support in Arduino ESP32 core beta
52
60
 
53
61
  **Note:** For ESP32 chips using native USB, make sure `USB CDC On Boot` is `Enabled` in the IDE's `Tools` menu. Flashing from the CLI doesn't automatically enable this, so the IDE is recommended for now.
54
62
 
@@ -119,6 +127,7 @@ Polling and reading follow a call and response pattern.
119
127
  | LED | :green_heart: | Digi/Ana Out | `LED::Base` |
120
128
  | RGB LED | :green_heart: | Digi/Ana Out | `LED::RGB` |
121
129
  | 7 Segment Display | :yellow_heart: | Digital Out | `LED::SevenSegment` | No decimal point
130
+ | 8x8 LED (MAX7219) | :heart: | SPI | `LED::MAX7219` |
122
131
  | TM1637 | :heart: | BitBang SPI | `LED::TM1637` | 4x 7 Segment + Colon
123
132
  | Neopixel / WS2812B | :yellow_heart: | Adafruit Library | `LED::WS2812` | Not working on RP2040
124
133
  | Dotstar / APA102 | :green_heart: | SPI | `LED::APA102` |
@@ -129,6 +138,12 @@ Polling and reading follow a call and response pattern.
129
138
  | :--------------- | :------: | :-------- | :--------------- |------ |
130
139
  | HD44780 LCD | :green_heart: | Digital Out, Output Register | `Display::HD44780` |
131
140
  | SSD1306 OLED | :yellow_heart: | I2C | `Display::SSD1306` | 1 font, some graphics
141
+ | ST7565R (128x64 Mono) | :heart: | SPI | `Display::ST7565R` |
142
+ | ST7735S (160x128 RGB) | :heart: | SPI | `Display::ST7735S` |
143
+ | ILI9341 (240x320 RGB) | :heart: | SPI | `Display::ILI9341` |
144
+ | GC9107 (128x128 RGB) | :heart: | SPI | `Display::GC9107` |
145
+ | GC9A01 (240x240 Round) | :heart: | SPI | `Display::GCA9A01` |
146
+ | IL0373 (212x104 E-Paper) | :heart: | SPI | `Display::IL0373` |
132
147
 
133
148
  ### Sound
134
149
 
@@ -142,10 +157,13 @@ Polling and reading follow a call and response pattern.
142
157
  | :--------------- | :------: | :-------- | :--------------- |------ |
143
158
  | Generic Hobby Servo | :green_heart: | Servo/ESC PWM | `Motor::Servo` | Max depends on PWM channel count
144
159
  | Generic ESC | :yellow_heart: | Servo/ESC PWM | `Motor::Servo` | Works. Needs its own class.
145
- | PCA9685 | :heart: | I2C | `PulseIO::PCA9685` | 16ch 12-bit PWM for servo or LED
160
+ | PCA9685 | :heart: | I2C | `PulseIO::PCA9685` | 16-ch, 12-bit PWM for servo or LED
146
161
  | L298N | :green_heart: | Digi + PWM Out | `Motor::L298` | H-Bridge DC motor driver
147
- | A3967 | :green_heart: | Digital Out | `Motor::Stepper` | 1ch microstepper (EasyDriver)
148
- | TMC2209 | :heart: | - | - | 1ch silent stepper driver
162
+ | DRV8833 | :heart: | Digi + PWM Out | `Motor::DRV8833` | H-Bridge DC motor driver
163
+ | TB6612 | :heart: | Digi + PWM Out | `Motor::TB6612` | H-Bridge DC motor driver
164
+ | A3967 | :green_heart: | Digital Out | `Motor::Stepper` | 1-ch microstepper (EasyDriver)
165
+ | A4988 | :yellow_heart: | DigitalOut | `Motor::Stepper` | 1-ch microstepper
166
+ | TMC2209 | :heart: | - | - | 1-ch silent stepper driver
149
167
 
150
168
  ### I/O Expansion
151
169
 
@@ -153,64 +171,84 @@ Polling and reading follow a call and response pattern.
153
171
  | :--------------- | :------: | :-------- | :--------------- |------ |
154
172
  | Input Register | :green_heart: | SPI | `SPI::InputRegister` | Tested on CD4021B
155
173
  | Output Register | :green_heart: | SPI | `SPI::OutputRegister`| Tested on 74HC595
156
- | PCF8574 Expander | :heart: | I2C | `DigitalIO::PCF8574` | 8ch bi-directional digital I/O
157
- | ADS1100 ADC | :heart: | I2C | `AnalogIO::ADS1100` | 15-bit +/- 1ch ADC
158
- | ADS1115 ADC | :green_heart: | I2C | `AnalogIO::ADS1115` | 15-bit +/- 4ch ADC. Comparator not implemented.
159
- | ADS1118 ADC | :green_heart: | SPI | `AnalogIO::ADS1118` | 15-bit +/- 4ch ADC + temperature
160
- | PCF8591 ADC/DAC | :heart: | I2C | `AnalogIO::PCF8591` | 4ch ADC + 1ch DAC, 8-bit resolution
161
- | MCP4725 DAC | :heart: | I2C | `AnalogIO::MCP4275` | 1ch 12-bit DAC
174
+ | PCF8574 Expander | :heart: | I2C | `DigitalIO::PCF8574` | 8-ch bi-directional digital I/O
175
+ | ADS1100 ADC | :heart: | I2C | `AnalogIO::ADS1100` | 1-ch, 16-bit ADC
176
+ | ADS1115 ADC | :green_heart: | I2C | `AnalogIO::ADS1115` | 4-ch, 16-bit ADC. Comparator not implemented.
177
+ | ADS1118 ADC | :green_heart: | SPI | `AnalogIO::ADS1118` | 4-ch, 16-bit ADC + temperature
178
+ | ADS1232 ADC | :heart: | SPI | `AnalogIO::ADS1232` | 2-ch, 24-bit ADC + temperature
179
+ | PCF8591 ADC/DAC | :heart: | I2C | `AnalogIO::PCF8591` | 4-ch, 8-bit ADC + 1-chm 8-bit DAC
180
+ | MCP4725 DAC | :heart: | I2C | `AnalogIO::MCP4275` | 1-ch, 12-bit DAC
181
+ | PCA9548 I2C Mux | :heart: | I2C | `I2C::PCA9548` | 8-way I2C multiplexer
162
182
 
163
183
  ### Environmental Sensors
164
184
 
165
- | Name | Status | Interface | Component Class | Notes |
166
- | :--------------- | :------: | :-------- | :--------------- |------ |
167
- | DS18B20 | :green_heart: | OneWire | `Sensor::DS18B20` | Temp
168
- | DHT 11/21/22 | :green_heart: | Digi In/Out | `Sensor::DHT` | Temp/RH
169
- | SHT30 | :heart: | I2C | `Sensor::SHT30` | Temp/RH
170
- | QMP6988 | :heart: | I2C | `Sensor::QMP6988` | Pressure
171
- | BME280 | :green_heart: | I2C | `Sensor::BME280` | Temp/RH/Press
172
- | BMP280 | :green_heart: | I2C | `Sensor::BMP280` | Temp/Press
173
- | HTU21D | :green_heart: | I2C | `Sensor::HTU21D` | Temp/RH. User register read not implemented.
174
- | HTU31D | :green_heart: | I2C | `Sensor::HTU31D` | Temp/RH. Diagnostic read not implemented.
175
- | AHT10/15 | :green_heart: | I2C | `Sensor::AHT10` | Temp/RH. Always uses calibrated mode.
176
- | AHT20/21/25 | :green_heart: | I2C | `Sensor::AHT20` | Temp/RH. Always uses calibrated mode + CRC.
177
- | ENS160 | :heart: | I2C | `Sensor::ENS160` | CO2e/TVOC/AQI
178
- | AGS02MA | :heart: | I2C | `Sensor::AGS02MA` | TVOC
179
- | MAX31850 | :heart: | OneWire | `Sensor::MAX31850` | Thermocouple Amplifier
185
+ | Name | Status | Interface | Component Class | Type | Notes |
186
+ | :--------------- | :------: | :-------- | :--------------- |--------------- | ---------------------- |
187
+ | MAX31850 | :heart: | OneWire | `Sensor::MAX31850` | Thermocouple |
188
+ | MAX6675 | :heart: | SPI | `Sensor::MAX6675` | Thermocouple |
189
+ | DS18B20 | :green_heart: | OneWire | `Sensor::DS18B20` | Temp |
190
+ | DHT11/21/22 | :green_heart: | Digi In/Out | `Sensor::DHT` | Temp / RH |
191
+ | SHT30/31/35 | :green_heart: | I2C | `Sensor::SHT3X` | Temp / RH | M5Stack ENV III, one-shot only
192
+ | SHT40/41 | :heart: | I2C | `Sensor::SHT4X` | Temp / RH |
193
+ | QMP6988 | :green_heart: | I2C | `Sensor::QMP6988` | Temp / Press | M5Stack ENV III
194
+ | BMP180 | :green_heart: | I2C | `Sensor::BMP180` | Temp / Press |
195
+ | BMP280 | :green_heart: | I2C | `Sensor::BMP280` | Temp / Press |
196
+ | BME280 | :green_heart: | I2C | `Sensor::BME280` | Temp / Press / RH |
197
+ | BME680 | :heart: | I2C | `Sensor::BME680` | Temp / Press / RH / TVOC |
198
+ | HTU21D | :green_heart: | I2C | `Sensor::HTU21D` | Temp / RH | No user register read
199
+ | HTU31D | :green_heart: | I2C | `Sensor::HTU31D` | Temp / RH | No diagnostic read
200
+ | AHT10/15 | :green_heart: | I2C | `Sensor::AHT10` | Temp / RH |
201
+ | AHT20/21/25 | :green_heart: | I2C | `Sensor::AHT20` | Temp / RH |
202
+ | ENS160 | :heart: | I2C | `Sensor::ENS160` | eCO2 / TVOC / AQI |
203
+ | AGS02MA | :heart: | I2C | `Sensor::AGS02MA` | TVOC |
204
+ | SCD40 | :heart: | I2C | `Sensor::SDC40` | Temp / Press / CO2 |
205
+ | CCS811 | :heart: | I2C | `Sensor::CCS811` | eCO2 |
180
206
 
181
207
  ### Light Sensors
182
208
 
183
209
  | Name | Status | Interface | Component Class | Notes |
184
210
  | :--------------- | :------: | :-------- | :--------------- |------ |
185
211
  | BH1750 | :heart: | Digital In | `Sensor::BH1750` | Ambient Light
186
- | HC-SR501 | :yellow_heart: | Digital In | `DigitalIO::Input` | PIR. Needs class: `Sensor::HC-SR501`
187
- | AS312 | :heart: | I2C | `Sensor::AS312` | PIR
212
+ | TCS34725 | :heart: | I2C | `Sensor::TCS34725` | RGB
188
213
  | APDS9960 | :heart: | I2C | `Sensor::APDS9960` | Proximity, RGB, Gesture
189
214
 
215
+ ### PIR Motion Sensors
216
+ | Name | Status | Interface | Component Class | Notes |
217
+ | :--------------- | :------: | :-------- | :--------------- |------ |
218
+ | HC-SR501 | :green_heart: | Digital In | `Sensor::GenericPIR` |
219
+ | HC-SR505 | :yellow_heart: | Digital In | `Sensor::GenericPIR` |
220
+ | AS312 | :green_heart: | Digital In | `Sensor::GenericPIR` |
221
+ | AM312 | :yellow_heart: | Digital In | `Sensor::GenericPIR` |
222
+
190
223
  ### Distance Sensors
191
224
 
192
225
  | Name | Status | Interface | Component Class | Notes |
193
226
  | :--------------- | :------: | :-------- | :--------------- |------ |
194
- | HC-SR04 | :heart: | Digi In/Out | `Sensor::HCSR04` | Ultrasonic, 20-4000mm
195
- | RCWL-9620 | :heart: | I2C | `Sensor::RCWL9260` | Ultrasonic, 20-4500mm
227
+ | HC-SR04 | :green_heart: | Digi In/Out | `Sensor::HCSR04` | Ultrasonic, 20-4000mm
228
+ | RCWL-9620 | :green_heart: | I2C | `Sensor::RCWL9260` | Ultrasonic, 20-4500mm
196
229
  | VL53L0X | :heart: | I2C | `Sensor::VL53L0X` | Laser, 30 - 1000mm
197
230
  | GP2Y0E03 | :heart: | I2C | `Sensor::GP2Y0E03` | Infrared, 40 - 500mm
198
231
 
199
- ### Motion Sensors
232
+ ### Inertial Measurement Units
200
233
 
201
234
  | Name | Status | Interface | Component Class | Notes |
202
235
  | :--------------- | :------: | :-------- | :--------------- |------ |
203
- | ADXL345 | :heart: | I2C | `Sensor::ADXL345` | 3-axis Accelerometer
204
- | IT3205 | :heart: | I2C | `Sensor::IT3205` | 3-axis Gyroscope
205
- | HMC5883L | :heart: | I2C | `Sensor::HMC5883L` | 3-axis Compass
206
- | MPU6886 | :heart: | I2C | `Sensor::MPU6886` | 3-axis Gyro + Accel
236
+ | ADXL345 | :heart: | I2C | `Sensor::ADXL345` | Accelerometer
237
+ | IT3205 | :heart: | I2C | `Sensor::IT3205` | Gyroscope
238
+ | HMC5883L | :heart: | I2C | `Sensor::HMC5883L` | Compass
239
+ | MPU6050 | :heart: | I2C | `Sensor::MPU6050` | Gyro + Accelerometer
240
+ | MPU6886 | :heart: | I2C | `Sensor::MPU6886` | Gyro + Accelerometer
241
+ | BMI160 | :heart: | I2C | `Sensor::BMI160` | Gyro + Accelerometer
242
+ | LSM6DS3 | :heart: | I2C | `Sensor:LSM6DS3` | Gyro + Accelerometer
207
243
 
208
244
  ### Real Time Clocks
209
245
 
210
246
  | Name | Status | Interface | Component Class | Notes |
211
247
  | :--------------- | :------: | :-------- | :--------------- |------ |
212
248
  | DS1302 | :heart: | I2C | `RTC::DS1302` |
249
+ | DS1307 | :heart: | I2C | `RTC::DS1307` |
213
250
  | DS3231 | :green_heart: | I2C | `RTC::DS3231` | Alarms not implemented
251
+ | PCF8563 | :heart: | I2C | `RTC::PCF8563` |
214
252
 
215
253
  ### GPS
216
254
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Denko 0.13.3 [![Test Status](https://github.com/denko-rb/denko/actions/workflows/ruby.yml/badge.svg)](https://github.com/denko-rb/denko/actions/workflows/ruby.yml)
1
+ # Denko 0.13.4 [![Test Status](https://github.com/denko-rb/denko/actions/workflows/ruby.yml/badge.svg)](https://github.com/denko-rb/denko/actions/workflows/ruby.yml)
2
2
  ### Ruby Meets Microcontrollers
3
3
  Denko gives you a high-level Ruby interface to low-level hardware, without writing microcontroller code. Use LEDs, buttons, sensors and more, just as easily as any Ruby object:
4
4
 
@@ -23,10 +23,10 @@ High-level abstraction in Ruby makes hardware classes easy to implement, with in
23
23
  Full list of supported mircocontroller platforms, interfaces, and peripherals is located [here](HARDWARE.md).
24
24
 
25
25
  ##### denko-piboard
26
- There's an add-on in development, [denko-piboard](https://github.com/denko-rb/denko-piboard), which supports the Raspberry Pi's built in GPIO pins, as `Denko::PiBoard`, class-compatible with `Denko::Board`. Connect peripherals directly to the Pi, with no microcontroller between, then use the peripheral classes from this gem.
26
+ The [denko-piboard](https://github.com/denko-rb/denko-piboard) add-on gem, uses a Raspberry Pi's built in GPIO header instead of an attached microcontroller. Connect things directly to the Pi, and use the peripheral classes from this gem.
27
27
 
28
28
  ##### mruby-denko
29
- A solo Raspberry Pi (or other small SBC + microcontroller) is a great standalone setup if your project needs the compute power anyway, but what if you don't? Why not run Ruby on the microcontroller itself?
29
+ A solo Raspberry Pi (or other SBC + microcontroller) is great if you need the compute power anyway, but what if you don't? Why not run Ruby on the microcontroller itself?
30
30
 
31
31
  That's the goal of [mruby-denko](https://github.com/denko-rb/mruby-denko): write mruby on the ESP32, using peripheral classes as close to this gem as possible. Still early in development, so limited features, but already usable.
32
32
 
@@ -30,6 +30,11 @@
30
30
  # Arduino Nano Every : 9.2 fps (USB through ATSAMD11 @ 115200, 128-byte I2C limit, no I2C level shifter)
31
31
  # Arduino Nano Every : 13.0 fps (USB through ATSAMD11 @ 230400, 128-byte I2C limit, no I2C level shifter)
32
32
  #
33
+ # February 25 2024 | i7 8700k CPU | CRuby 3.2.1 | 100 frames | 1 Mhz I2C frequency | Average of 3 runs
34
+ #
35
+ # ESP32-S3 : 51.8 fps (native USB) - Changed from 64 to 128 serial ACK interval
36
+ # ESP32-C3 : 51.7 fps (native USB) - Changed from 64 to 128 serial ACK interval
37
+ #
33
38
  require 'bundler/setup'
34
39
  require 'denko'
35
40
 
data/denko.gemspec CHANGED
@@ -17,10 +17,10 @@ Gem::Specification.new do |gem|
17
17
  # get an array of submodule dirs by executing 'pwd' inside each submodule
18
18
  gem_dir = File.expand_path(File.dirname(__FILE__)) + "/"
19
19
  `git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
20
- # Fix submodule paths on Windows.
21
- if RUBY_PLATFORM.match(/mswin|mingw/i)
22
- submodule_path = `cygpath -m #{submodule_path}`.strip
23
- end
20
+ # Fix submodule paths on Windows, by removing prepended / and drive letter.
21
+ if RUBY_PLATFORM.match(/mswin|mingw/i)
22
+ submodule_path = submodule_path[2..-1]
23
+ end
24
24
 
25
25
  Dir.chdir(submodule_path) do
26
26
  submodule_relative_path = submodule_path.sub gem_dir, ""
@@ -0,0 +1,48 @@
1
+ #
2
+ # This example combines the SHTX and QMP6988 examples. The M5Stack ENV III unit
3
+ # contains both sensors, accessible over a single I2C connection.
4
+ #
5
+ require 'bundler/setup'
6
+ require 'denko'
7
+
8
+ board = Denko::Board.new(Denko::Connection::Serial.new)
9
+ bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
10
+ sht = Denko::Sensor::SHT3X.new(bus: bus) # address: 0x44 default
11
+ qmp = Denko::Sensor::QMP6988.new(bus: bus) # address: 0x70 default
12
+
13
+ # Configure for higher accuracy.
14
+ sht.repeatability = :high
15
+ qmp.temperature_samples = 2
16
+ qmp.pressure_samples = 16
17
+ qmp.iir_coefficient = 2
18
+
19
+ # Buggy on ESP32-S3 in forced mode. Data registers return zeroes on all but first read.
20
+ # Can't recreate on ESP32 V1, AVR or SAMD21. Put it in contiuous mode just in case.
21
+ qmp.continuous_mode
22
+
23
+ # Get the shared #print_tph_reading method to print readings neatly.
24
+ require_relative '../sensor/neat_tph_readings'
25
+
26
+ # How many degrees C the two temperature values can differ by before a warning.
27
+ TOLERANCE = 0.50
28
+
29
+ loop do
30
+ # Read both sensors.
31
+ qmp_reading = qmp.read
32
+ sht_reading = sht.read
33
+
34
+ # Retry immediately if either failed.
35
+ next unless (sht_reading && qmp_reading)
36
+
37
+ # Warn if large gap between temperature readings.
38
+ difference = (qmp_reading[:temperature] - sht_reading[:temperature]).abs
39
+ if (difference > TOLERANCE)
40
+ puts "WARNING: temperature values differed by more than #{TOLERANCE}\xC2\xB0C (#{difference.round(4)} \xC2\xB0C actual)"
41
+ end
42
+
43
+ # Combine values from both sensors, averaging their temperatures.
44
+ average_temperature = (qmp_reading[:temperature] + sht_reading[:temperature]) / 2.0
45
+ print_tph_reading(temperature: average_temperature, humidity: sht_reading[:humidity], pressure: qmp_reading[:pressure])
46
+
47
+ sleep 5
48
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # Simple button example.
3
+ #
4
+ require 'bundler/setup'
5
+ require 'denko'
6
+
7
+ board = Denko::Board.new(Denko::Connection::Serial.new)
8
+ button = Denko::DigitalIO::Button.new(board: board, pin: 5, pullup: true)
9
+
10
+ button.up { puts "Button released!" }
11
+ button.down { puts "Button pressed!" }
12
+
13
+ sleep
@@ -23,6 +23,8 @@ unless board.map
23
23
 
24
24
  # Else get defaults from map.
25
25
  else
26
+ puts "Detected board: #{board.name}"
27
+
26
28
  sda = board.map[:SDA] || board.map[:SDA0]
27
29
  scl = board.map[:SCL] || board.map[:SCL0]
28
30
 
@@ -6,10 +6,14 @@ require 'denko'
6
6
 
7
7
  board = Denko::Board.new(Denko::Connection::Serial.new)
8
8
  bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
9
- aht10 = Denko::Sensor::AHT10.new(bus: bus)
9
+ sensor = Denko::Sensor::AHT10.new(bus: bus) # address: 0x38 default
10
10
 
11
- aht10.poll(2) do |reading|
12
- puts "Polled Reading: #{reading[:temperature].round(3)} \xC2\xB0C | #{reading[:humidity].round(3)} % RH"
11
+ # Get the shared #print_tph_reading method to print readings neatly.
12
+ require_relative 'neat_tph_readings'
13
+
14
+ # Poll it and print readings.
15
+ sensor.poll(5) do |reading|
16
+ print_tph_reading(reading)
13
17
  end
14
18
 
15
19
  sleep
@@ -6,10 +6,14 @@ require 'denko'
6
6
 
7
7
  board = Denko::Board.new(Denko::Connection::Serial.new)
8
8
  bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
9
- aht20 = Denko::Sensor::AHT20.new(bus: bus)
9
+ sensor = Denko::Sensor::AHT20.new(bus: bus) # address: 0x38 default
10
10
 
11
- aht20.poll(2) do |reading|
12
- puts "Polled Reading: #{reading[:temperature].round(3)} \xC2\xB0C | #{reading[:humidity].round(3)} % RH"
11
+ # Get the shared #print_tph_reading method to print readings neatly.
12
+ require_relative 'neat_tph_readings'
13
+
14
+ # Poll it and print readings.
15
+ sensor.poll(5) do |reading|
16
+ print_tph_reading(reading)
13
17
  end
14
18
 
15
19
  sleep
@@ -5,28 +5,11 @@ require 'bundler/setup'
5
5
  require 'denko'
6
6
 
7
7
  board = Denko::Board.new(Denko::Connection::Serial.new)
8
-
9
- #
10
- # Default pins for the I2C0 (first) interface on most chips:
11
- #
12
- # ATmega 328p: SDA = 'A4' SCL = 'A5' - Arduino Uno, Nano
13
- # ATmega 32u4: SDA = 2 SCL = 3 - Arduino Leonardo, Pro Micro
14
- # ATmega1280 / 2560: SDA = 20 SCL = 21 - Arduino Mega
15
- # SAM3X8E: SDA = 20 SCL = 21 - Arduino Due
16
- # SAMD21G18: SDA = 20 SCL = 21 - Arduino Zero, M0, M0 Pro
17
- # ESP8266: SDA = 4 SCL = 5
18
- # ESP32: SDA = 21 SCL = 22
19
- # RP2040: SDA = 4 SCL = 5 - Raspberry Pi Pico (W)
20
- #
21
- # Only give the SDA pin of the I2C bus. SCL (clock) pin must be
22
- # connected for it to work, but we don't need to control it.
23
- #
24
8
  bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
25
9
 
26
- sensor = Denko::Sensor::BME280.new(bus: bus, address: 0x76)
27
-
10
+ sensor = Denko::Sensor::BME280.new(bus: bus) # address: 0x76 default
28
11
  # Use A BMP280 with no humidity instead.
29
- # sensor = Denko::Sensor::BMP280.new(bus: bus, address: 0x76)
12
+ # sensor = Denko::Sensor::BMP280.new(bus: bus) # address: 0x76
30
13
 
31
14
  # Default reading mode is oneshot ("forced" in datasheet).
32
15
  # sensor.oneshot_mode
@@ -44,32 +27,12 @@ sensor = Denko::Sensor::BME280.new(bus: bus, address: 0x76)
44
27
  # Print raw config register bits.
45
28
  # print sensor.config_register_bits
46
29
 
47
- def display_reading(reading)
48
- # Time
49
- print "#{Time.now.strftime '%Y-%m-%d %H:%M:%S'} - "
50
-
51
- # Temperature
52
- formatted_temp = reading[:temperature].round(2).to_s.ljust(5, '0')
53
- print "Temperature: #{formatted_temp} \xC2\xB0C"
54
-
55
- # Pressure
56
- if reading[:pressure]
57
- formatted_pressure = (reading[:pressure] / 101325).round(5).to_s.ljust(7, '0')
58
- print " | Pressure #{formatted_pressure} atm"
59
- end
60
-
61
- # Humidity
62
- if reading[:humidity]
63
- formatted_humidity = reading[:humidity].round(2).to_s.ljust(5, '0')
64
- print " | Humidity #{formatted_humidity} %"
65
- end
66
-
67
- puts
68
- end
30
+ # Get the shared #print_tph_reading method to print readings neatly.
31
+ require_relative 'neat_tph_readings'
69
32
 
70
- # Poll the sensor and print readings.
33
+ # Poll it and print readings.
71
34
  sensor.poll(5) do |reading|
72
- display_reading(reading)
35
+ print_tph_reading(reading)
73
36
  end
74
37
 
75
38
  sleep
@@ -0,0 +1,22 @@
1
+ #
2
+ # Example using a BMP180 sensor over I2C, for temperature and pressure.
3
+ #
4
+ require 'bundler/setup'
5
+ require 'denko'
6
+
7
+ board = Denko::Board.new(Denko::Connection::Serial.new)
8
+ bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
9
+ sensor = Denko::Sensor::BMP180.new(bus: bus) # address: 0x77 default
10
+
11
+ # Enable oversampling for the pressure sensor only (1,2,4, 8).
12
+ # sensor.pressure_samples = 8
13
+
14
+ # Get the shared #print_tph_reading method to print readings neatly.
15
+ require_relative 'neat_tph_readings'
16
+
17
+ # Poll it and print readings.
18
+ sensor.poll(5) do |reading|
19
+ print_tph_reading(reading)
20
+ end
21
+
22
+ sleep
@@ -0,0 +1,25 @@
1
+ #
2
+ # Example using a PIR motion sensor. Tested with AS312 and HC-SR501 sensors.
3
+ #
4
+ # General notes:
5
+ # - Both sensors have a few seconds "dead time" after "motion stop" (logical 0), where further
6
+ # motion will not trigger "motion start" (logical 1).
7
+ #
8
+ # HC-SR501 notes:
9
+ # - Needs some time to warm up and start working properly.
10
+ # - Set the time potentiometer to its lowest value.
11
+ # - Make sure retriggering is enabled. It might be default, but there's a jumper to solder too.
12
+ #
13
+ require 'bundler/setup'
14
+ require 'denko'
15
+
16
+ board = Denko::Board.new(Denko::Connection::Serial.new)
17
+ sensor = Denko::Sensor::GenericPIR.new(board: board, pin: 8)
18
+
19
+ sensor.on_motion_start { print "Motion detected! \r" }
20
+ sensor.on_motion_stop { print "No motion detected... \r" }
21
+
22
+ # Read initial state.
23
+ sensor.read
24
+
25
+ sleep
@@ -0,0 +1,14 @@
1
+ #
2
+ # Example of reading an HC-SR04 ultrasonic sensor.
3
+ #
4
+ require 'bundler/setup'
5
+ require 'denko'
6
+
7
+ board = Denko::Board.new(Denko::Connection::Serial.new)
8
+ hcsr04 = Denko::Sensor::HCSR04.new(board: board, pins: {trigger: 6, echo: 7})
9
+
10
+ hcsr04.poll(0.05) do |distance|
11
+ puts "Distance: #{distance} mm"
12
+ end
13
+
14
+ sleep
@@ -6,7 +6,7 @@ require 'denko'
6
6
 
7
7
  board = Denko::Board.new(Denko::Connection::Serial.new)
8
8
  bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
9
- htu21d = Denko::Sensor::HTU21D.new(bus: bus)
9
+ htu21d = Denko::Sensor::HTU21D.new(bus: bus) # address: 0x40 default
10
10
 
11
11
  # Get and set heater state.
12
12
  htu21d.heater_on
@@ -6,26 +6,30 @@ require 'denko'
6
6
 
7
7
  board = Denko::Board.new(Denko::Connection::Serial.new)
8
8
  bus = Denko::I2C::Bus.new(board: board, pin: :SDA)
9
- htu31d = Denko::Sensor::HTU31D.new(bus: bus)
9
+ sensor = Denko::Sensor::HTU31D.new(bus: bus)
10
10
 
11
11
  # Get and set heater state.
12
- htu31d.heater_on
13
- puts "Heater on: #{htu31d.heater_on?}"
14
- htu31d.heater_off
15
- puts "Heater off: #{htu31d.heater_off?}"
12
+ sensor.heater_on
13
+ puts "Heater on: #{sensor.heater_on?}"
14
+ sensor.heater_off
15
+ puts "Heater off: #{sensor.heater_off?}"
16
16
 
17
17
  # Back to default settings, including heater off, unlike HTU21D.
18
- htu31d.reset
19
- puts "Resetting HTU31D... Heater off: #{htu31d.heater_off?}"
18
+ sensor.reset
19
+ puts "Resetting HTU31D..."
20
+ puts "Heater off: #{sensor.heater_off?}"
20
21
  puts
21
22
 
22
23
  # Resolution goes from 0..3 separately for temperature and humidity. See datasheet.
23
- htu31d.temperature_resolution = 3
24
- htu31d.humidity_resolution = 3
24
+ sensor.temperature_resolution = 3
25
+ sensor.humidity_resolution = 3
26
+
27
+ # Get the shared #print_tph_reading method to print readings neatly.
28
+ require_relative 'neat_tph_readings'
25
29
 
26
30
  # Unlike HTU21D, HTU31D works as a regular polled sensor.
27
- htu31d.poll(2) do |reading|
28
- puts "Polled Reading: #{reading[:temperature].round(3)} \xC2\xB0C | #{reading[:humidity].round(3)} % RH"
31
+ sensor.poll(5) do |reading|
32
+ print_tph_reading(reading)
29
33
  end
30
34
 
31
35
  sleep