denko 0.13.6 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{build_avr.yml → build_atmega_avr.yml} +18 -18
- data/.github/workflows/{build_megaavr.yml → build_atmega_megaavr.yml} +18 -18
- data/.github/workflows/{build_sam3x.yml → build_atsam3x.yml} +17 -17
- data/.github/workflows/{build_samd.yml → build_atsamd21.yml} +18 -18
- data/.github/workflows/build_esp32.yml +17 -18
- data/.github/workflows/build_esp32c3.yml +57 -0
- data/.github/workflows/build_esp32c6.yml +57 -0
- data/.github/workflows/build_esp32h2.yml +56 -0
- data/.github/workflows/build_esp32s2.yml +57 -0
- data/.github/workflows/build_esp32s3.yml +57 -0
- data/.github/workflows/build_esp8266.yml +15 -15
- data/.github/workflows/build_ra4m1.yml +16 -16
- data/.github/workflows/build_rp2040.yml +17 -16
- data/.github/workflows/ruby.yml +20 -20
- data/CHANGELOG.md +195 -11
- data/DEPS_CLI.md +9 -9
- data/DEPS_IDE.md +17 -18
- data/HARDWARE.md +50 -51
- data/README.md +61 -53
- data/Rakefile +1 -1
- data/benchmarks/analog_listen.rb +49 -0
- data/benchmarks/digital_write.rb +28 -0
- data/benchmarks/i2c_ssd1306_refresh.rb +13 -6
- data/build +1 -1
- data/denko.gemspec +5 -2
- data/examples/advanced/{m5_env.rb → m5_env3.rb} +12 -14
- data/examples/advanced/rotary_encoder_mac_volume.rb +18 -13
- data/examples/advanced/ssd1306_time_temp_rh.rb +8 -13
- data/examples/analog_io/ads1100.rb +48 -0
- data/examples/analog_io/ads1115.rb +2 -2
- data/examples/analog_io/ads1118.rb +3 -11
- data/examples/analog_io/input.rb +17 -16
- data/examples/analog_io/input_smoothing.rb +27 -0
- data/examples/analog_io/potentiometer.rb +31 -0
- data/examples/connection/binary_echo.rb +34 -0
- data/examples/connection/tcp.rb +12 -27
- data/examples/digital_io/button.rb +7 -3
- data/examples/digital_io/relay.rb +17 -0
- data/examples/digital_io/rotary_encoder.rb +21 -11
- data/examples/display/hd44780.rb +13 -5
- data/examples/display/ssd1306.rb +20 -17
- data/examples/display/ssd1306_s2_pico.rb +2 -2
- data/examples/i2c/search.rb +10 -26
- data/examples/led/apa102_bounce.rb +3 -4
- data/examples/led/apa102_fade.rb +44 -0
- data/examples/led/builtin_blink.rb +3 -1
- data/examples/led/builtin_fade.rb +19 -0
- data/examples/led/rgb_led.rb +31 -0
- data/examples/led/seven_segment_char_echo.rb +4 -2
- data/examples/led/ws2812_bounce.rb +5 -7
- data/examples/led/ws2812_builtin_blink.rb +3 -2
- data/examples/led/ws2812_fade.rb +43 -0
- data/examples/motor/l298.rb +10 -8
- data/examples/motor/servo.rb +4 -3
- data/examples/motor/stepper.rb +13 -13
- data/examples/one_wire/search.rb +32 -0
- data/examples/pulse_io/buzzer.rb +8 -3
- data/examples/pulse_io/ir_output.rb +51 -0
- data/examples/pulse_io/pwm_output.rb +30 -0
- data/examples/rtc/ds3231.rb +18 -35
- data/examples/sensor/aht10.rb +4 -6
- data/examples/sensor/aht20.rb +4 -6
- data/examples/sensor/bme280.rb +4 -4
- data/examples/sensor/bmp180.rb +9 -5
- data/examples/sensor/dht.rb +20 -15
- data/examples/sensor/ds18b20.rb +20 -21
- data/examples/sensor/generic_pir.rb +4 -2
- data/examples/sensor/hcsr04.rb +5 -2
- data/examples/sensor/htu21d.rb +9 -20
- data/examples/sensor/htu31d.rb +7 -9
- data/examples/sensor/neat_tph_readings.rb +15 -9
- data/examples/sensor/qmp6988.rb +5 -7
- data/examples/sensor/rcwl9620.rb +3 -3
- data/examples/sensor/sht3x.rb +4 -6
- data/examples/spi/bitbang_loopback.rb +46 -0
- data/examples/spi/input_register.rb +9 -19
- data/examples/spi/output_register.rb +9 -17
- data/examples/spi/ssd_through_registers.rb +28 -0
- data/examples/spi/two_registers.rb +18 -24
- data/examples/uart/bit_bang_demo.rb +25 -0
- data/examples/uart/board_passthrough.rb +19 -13
- data/examples/uart/hardware_loopback.rb +1 -1
- data/lib/denko/analog_io/ads1100.rb +127 -0
- data/lib/denko/analog_io/ads1115.rb +8 -25
- data/lib/denko/analog_io/ads1118.rb +10 -25
- data/lib/denko/analog_io/ads111x.rb +25 -11
- data/lib/denko/analog_io/input.rb +29 -55
- data/lib/denko/analog_io/input_helper.rb +42 -0
- data/lib/denko/analog_io/output.rb +5 -5
- data/lib/denko/analog_io/potentiometer.rb +6 -8
- data/lib/denko/analog_io.rb +2 -1
- data/lib/denko/behaviors/board_proxy.rb +13 -1
- data/lib/denko/behaviors/bus_controller.rb +1 -0
- data/lib/denko/behaviors/bus_controller_addressed.rb +1 -0
- data/lib/denko/behaviors/bus_peripheral.rb +3 -4
- data/lib/denko/behaviors/bus_peripheral_addressed.rb +8 -6
- data/lib/denko/behaviors/callbacks.rb +9 -7
- data/lib/denko/behaviors/component.rb +16 -14
- data/lib/denko/behaviors/input_pin.rb +14 -15
- data/lib/denko/behaviors/lifecycle.rb +51 -0
- data/lib/denko/behaviors/multi_pin.rb +22 -18
- data/lib/denko/behaviors/output_pin.rb +9 -4
- data/lib/denko/behaviors/single_pin.rb +1 -0
- data/lib/denko/behaviors/state.rb +15 -9
- data/lib/denko/behaviors/subcomponents.rb +72 -12
- data/lib/denko/behaviors.rb +2 -1
- data/lib/denko/board/core.rb +36 -18
- data/lib/denko/board/i2c.rb +14 -14
- data/lib/denko/board/i2c_bit_bang.rb +49 -0
- data/lib/denko/board/infrared.rb +6 -6
- data/lib/denko/board/led_array.rb +6 -5
- data/lib/denko/board/spi.rb +15 -10
- data/lib/denko/board/spi_bit_bang.rb +9 -7
- data/lib/denko/board.rb +35 -33
- data/lib/denko/connection/binary_echo.rb +17 -0
- data/lib/denko/connection/flow_control.rb +11 -15
- data/lib/denko/connection/handshake.rb +2 -0
- data/lib/denko/digital_io/button.rb +4 -0
- data/lib/denko/digital_io/c_bit_bang.rb +15 -0
- data/lib/denko/digital_io/input.rb +4 -5
- data/lib/denko/digital_io/output.rb +7 -6
- data/lib/denko/digital_io/relay.rb +2 -0
- data/lib/denko/digital_io/rotary_encoder.rb +78 -60
- data/lib/denko/digital_io.rb +1 -0
- data/lib/denko/display/hd44780.rb +136 -93
- data/lib/denko/display/sh1106.rb +42 -0
- data/lib/denko/display/ssd1306.rb +105 -45
- data/lib/denko/display.rb +1 -0
- data/lib/denko/eeprom/built_in.rb +19 -16
- data/lib/denko/i2c/bit_bang.rb +31 -0
- data/lib/denko/i2c/bus.rb +8 -36
- data/lib/denko/i2c/bus_common.rb +45 -0
- data/lib/denko/i2c/peripheral.rb +28 -19
- data/lib/denko/i2c.rb +2 -0
- data/lib/denko/led/apa102.rb +43 -29
- data/lib/denko/led/base.rb +8 -2
- data/lib/denko/led/rgb.rb +5 -7
- data/lib/denko/led/seven_segment.rb +24 -9
- data/lib/denko/led/ws2812.rb +10 -7
- data/lib/denko/message.rb +5 -0
- data/lib/denko/motor/l298.rb +11 -10
- data/lib/denko/motor/servo.rb +22 -10
- data/lib/denko/motor/stepper.rb +11 -14
- data/lib/denko/mutex_stub.rb +7 -0
- data/lib/denko/one_wire/bus.rb +9 -5
- data/lib/denko/one_wire/peripheral.rb +0 -3
- data/lib/denko/pulse_io/buzzer.rb +9 -3
- data/lib/denko/pulse_io/{ir_transmitter.rb → ir_output.rb} +9 -4
- data/lib/denko/pulse_io/pwm_output.rb +69 -15
- data/lib/denko/pulse_io.rb +3 -3
- data/lib/denko/rtc/ds3231.rb +11 -13
- data/lib/denko/sensor/aht.rb +22 -21
- data/lib/denko/sensor/bme280.rb +60 -63
- data/lib/denko/sensor/bmp180.rb +41 -38
- data/lib/denko/sensor/dht.rb +22 -5
- data/lib/denko/sensor/ds18b20.rb +40 -34
- data/lib/denko/sensor/hcsr04.rb +7 -5
- data/lib/denko/sensor/helper.rb +37 -0
- data/lib/denko/sensor/htu21d.rb +44 -55
- data/lib/denko/sensor/htu31d.rb +32 -33
- data/lib/denko/sensor/qmp6988.rb +25 -23
- data/lib/denko/sensor/rcwl9620.rb +2 -5
- data/lib/denko/sensor/sht3x.rb +23 -21
- data/lib/denko/sensor.rb +1 -2
- data/lib/denko/spi/base_register.rb +22 -22
- data/lib/denko/spi/bit_bang.rb +17 -51
- data/lib/denko/spi/bus.rb +15 -29
- data/lib/denko/spi/bus_common.rb +36 -0
- data/lib/denko/spi/input_register.rb +36 -30
- data/lib/denko/spi/output_register.rb +25 -40
- data/lib/denko/spi/peripheral.rb +93 -24
- data/lib/denko/spi.rb +6 -1
- data/lib/denko/uart/bit_bang.rb +5 -3
- data/lib/denko/uart/hardware.rb +9 -8
- data/lib/denko/version.rb +1 -1
- data/lib/denko.rb +10 -0
- data/lib/denko_cli/generator.rb +2 -2
- data/lib/denko_cli/packages.rb +8 -10
- data/lib/denko_cli/targets.rb +8 -8
- data/lib/denko_cli/targets.txt +4 -4
- data/lib/denko_cli/usage.txt +1 -1
- data/src/denko_ethernet.ino +0 -14
- data/src/denko_serial.ino +0 -14
- data/src/denko_wifi.ino +6 -15
- data/src/lib/Denko.cpp +39 -3
- data/src/lib/Denko.h +42 -26
- data/src/lib/DenkoCoreIO.cpp +57 -102
- data/src/lib/DenkoDefines.h +36 -31
- data/src/lib/DenkoI2C.cpp +54 -45
- data/src/lib/DenkoI2CBB.cpp +238 -0
- data/src/lib/DenkoIROut.cpp +12 -7
- data/src/lib/DenkoLEDArray.cpp +36 -13
- data/src/lib/DenkoSPI.cpp +6 -5
- data/src/lib/DenkoSPIBB.cpp +7 -6
- data/target.yml +37 -2
- data/test/analog_io/potentiometer_test.rb +10 -10
- data/test/behaviors/board_proxy_test.rb +1 -1
- data/test/behaviors/callbacks_test.rb +11 -3
- data/test/behaviors/component_test.rb +17 -9
- data/test/behaviors/input_pin_test.rb +14 -9
- data/test/behaviors/multi_pin_test.rb +14 -4
- data/test/behaviors/output_pin_test.rb +11 -8
- data/test/behaviors/poller_test.rb +1 -0
- data/test/behaviors/reader_test.rb +3 -2
- data/test/behaviors/subcomponents_test.rb +22 -2
- data/test/board/core_test.rb +15 -11
- data/test/board/i2c_test.rb +39 -33
- data/test/board/infrared_test.rb +1 -1
- data/test/board/message_test.rb +17 -11
- data/test/board/spi_test.rb +21 -21
- data/test/digital_io/button_test.rb +15 -0
- data/test/digital_io/relay_test.rb +18 -0
- data/test/digital_io/rotary_encoder_test.rb +80 -60
- data/test/eeprom/built_in_test.rb +9 -9
- data/test/i2c/bus_test.rb +30 -14
- data/test/i2c/peripheral_test.rb +36 -17
- data/test/led/base_test.rb +2 -1
- data/test/led/rgb_test.rb +6 -6
- data/test/led/seven_segment_test.rb +7 -7
- data/test/motor/servo_test.rb +1 -1
- data/test/motor/stepper_test.rb +2 -2
- data/test/one_wire/bus_test.rb +1 -0
- data/test/pulse_io/buzzer_test.rb +7 -4
- data/test/pulse_io/{ir_transmitter_test.rb → ir_output_test.rb} +10 -10
- data/test/pulse_io/pwm_output_test.rb +74 -18
- data/test/rtc/ds3231_test.rb +11 -13
- data/test/sensor/dht_test.rb +1 -1
- data/test/sensor/ds18b20_test.rb +4 -8
- data/test/spi/bus_test.rb +7 -7
- data/test/spi/input_register_test.rb +15 -15
- data/test/spi/output_register_test.rb +10 -28
- data/test/spi/peripheral_multi_pin_test.rb +53 -0
- data/test/spi/peripheral_single_pin_test.rb +48 -0
- data/test/test_helper.rb +36 -33
- data/tutorial/02-button/button.rb +5 -4
- data/tutorial/03-potentiometer/potentiometer.rb +9 -5
- data/tutorial/04-pwm_led/pwm_led.rb +14 -16
- data/tutorial/05-rgb_led/rgb_led.rb +6 -6
- data/tutorial/05-rgb_led/rgb_mapping.rb +11 -11
- data/vendor/board-maps/BoardMap.h +416 -56
- data/vendor/board-maps/lib/header_parser.rb +12 -2
- data/vendor/board-maps/yaml/ADAFRUIT_CAMERA_ESP32S3.yml +2 -2
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32C6.yml +15 -0
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32_V2.yml +1 -1
- data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_RP2040_ADALOGGER.yml +44 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32C3.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S2.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_N4R2.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_NOPSRAM.yml +1 -0
- data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32_PICO.yml +1 -0
- data/vendor/board-maps/yaml/AMKEN_BB.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_ES.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_REVELOP.yml +48 -0
- data/vendor/board-maps/yaml/AMKEN_REVELOP_PLUS.yml +48 -0
- data/vendor/board-maps/yaml/ASL_CAN_X2.yml +41 -0
- data/vendor/board-maps/yaml/BLING.yml +25 -0
- data/vendor/board-maps/yaml/BPI_LEAF_S3.yml +1 -0
- data/vendor/board-maps/yaml/BRIDGETEK_IDM2040_7A.yml +48 -0
- data/vendor/board-maps/yaml/Bee_Motion_Mini.yml +13 -1
- data/vendor/board-maps/yaml/Breadstick_Raspberry.yml +31 -0
- data/vendor/board-maps/yaml/DFROBOT_BEETLE_ESP32C6.yml +8 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32C6.yml +20 -0
- data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_ESP32.yml +46 -0
- data/vendor/board-maps/yaml/DPTECHNICS_WALTER.yml +39 -0
- data/vendor/board-maps/yaml/ELECROW_CROWPANEL_7.yml +8 -0
- data/vendor/board-maps/yaml/ESP32C2_DEV.yml +12 -0
- data/vendor/board-maps/yaml/ESP32C3_DEVKIT_LIPO.yml +14 -0
- data/vendor/board-maps/yaml/ESP32C6_DEV.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_EVB.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_QWIIC_POCKET.yml +15 -0
- data/vendor/board-maps/yaml/ESP32C6_THING_PLUS.yml +15 -0
- data/vendor/board-maps/yaml/ESP32H2_DEV.yml +13 -0
- data/vendor/board-maps/yaml/ESP32H2_DEVKIT_LIPO.yml +13 -0
- data/vendor/board-maps/yaml/ESP32S2_DEV.yml +1 -0
- data/vendor/board-maps/yaml/{RMP.yml → ESP32S2_DEVKIT_LIPO.yml} +2 -1
- data/vendor/board-maps/yaml/ESP32S2_DEVKIT_LIPO_USB.yml +44 -0
- data/vendor/board-maps/yaml/ESP32S3_DEVKIT_LIPO.yml +42 -0
- data/vendor/board-maps/yaml/ESP32S3_POWERFEATHER.yml +22 -0
- data/vendor/board-maps/yaml/ESP32_SBC_FABGL.yml +35 -0
- data/vendor/board-maps/yaml/EVN_ALPHA.yml +48 -0
- data/vendor/board-maps/yaml/FEATHERS3NEO.yml +32 -0
- data/vendor/board-maps/yaml/GEEKBLE_ESP32C3.yml +14 -0
- data/vendor/board-maps/yaml/HELTEC_CAPSULE_SENSOR_V3.yml +43 -0
- data/vendor/board-maps/yaml/HELTEC_WIFI_LORA_32_V3.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_BRIDGE.yml +8 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_MINI_SHELL.yml +13 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_PAPER.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_SHELL_V3.yml +42 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_STICK_LITE_V3.yml +30 -0
- data/vendor/board-maps/yaml/HELTEC_WIRELESS_TRACKER.yml +41 -0
- data/vendor/board-maps/yaml/HT_DE01.yml +42 -0
- data/vendor/board-maps/yaml/IMBRIOS_LOGSENS_V1P1.yml +1 -1
- data/vendor/board-maps/yaml/LILYGO_T3S3_LR1121.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1262.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1276.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1278.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280.yml +9 -0
- data/vendor/board-maps/yaml/LILYGO_T3S3_SX1280PA.yml +8 -0
- data/vendor/board-maps/yaml/LILYGO_T_ETH_LITE.yml +21 -0
- data/vendor/board-maps/yaml/LOLIN_C3_PICO.yml +14 -0
- data/vendor/board-maps/yaml/LOLIN_S3.yml +1 -0
- data/vendor/board-maps/yaml/LOLIN_S3_MINI_PRO.yml +40 -0
- data/vendor/board-maps/yaml/Lion_Bit_Dev_Board.yml +0 -2
- data/vendor/board-maps/yaml/LoPy.yml +1 -0
- data/vendor/board-maps/yaml/LoPy4.yml +1 -0
- data/vendor/board-maps/yaml/M5STACK_CAPSULE.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_CARDPUTER.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_DIAL.yml +8 -0
- data/vendor/board-maps/yaml/M5STACK_FIRE.yml +0 -1
- data/vendor/board-maps/yaml/M5STACK_NANOC6.yml +17 -0
- data/vendor/board-maps/yaml/M5STACK_PAPER.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_POE_CAM.yml +5 -0
- data/vendor/board-maps/yaml/M5STACK_STAMP_C3.yml +13 -0
- data/vendor/board-maps/yaml/M5STACK_STAMP_S3.yml +4 -0
- data/vendor/board-maps/yaml/{M5Stick_C.yml → M5STACK_STICKC.yml} +0 -1
- data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_STICKC_PLUS2.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_TOUGH.yml +9 -0
- data/vendor/board-maps/yaml/M5STACK_UNIT_CAM.yml +10 -0
- data/vendor/board-maps/yaml/M5STACK_UNIT_CAMS3.yml +4 -0
- data/vendor/board-maps/yaml/M5Stack_ATOM.yml +0 -1
- data/vendor/board-maps/yaml/MAKERGO_C3_SUPERMINI.yml +14 -0
- data/vendor/board-maps/yaml/MARBLE_PICO.yml +48 -0
- data/vendor/board-maps/yaml/METEHOCA_AKANA_R1.yml +46 -0
- data/vendor/board-maps/yaml/NAMINO_BIANCO.yml +13 -0
- data/vendor/board-maps/yaml/NEBULAS3.yml +0 -1
- data/vendor/board-maps/yaml/NEWSAN_ARCHI.yml +48 -0
- data/vendor/board-maps/yaml/NOLOGO_ESP32C3_SUPER_MINI.yml +14 -0
- data/vendor/board-maps/yaml/NOLOGO_ESP32S3_PICO.yml +12 -0
- data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_16MB.yml +48 -0
- data/vendor/board-maps/yaml/OLIMEX_RP2040_PICO30_2MB.yml +48 -0
- data/vendor/board-maps/yaml/OPTA_ANALOG.yml +7 -0
- data/vendor/board-maps/yaml/OPTA_DIGITAL.yml +5 -0
- data/vendor/board-maps/yaml/PINTRONIX_PINMAX.yml +42 -0
- data/vendor/board-maps/yaml/PYCOM_GPY.yml +1 -0
- data/vendor/board-maps/yaml/REDPILL_ESP32S3.yml +0 -1
- data/vendor/board-maps/yaml/SENSEBOX_MCU_ESP32S2.yml +12 -0
- data/vendor/board-maps/yaml/SPARKFUN_MICROMOD_RP2040.yml +48 -0
- data/vendor/board-maps/yaml/SPARKFUN_PRO_MICRO_ESP32C3.yml +24 -0
- data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER.yml +31 -0
- data/vendor/board-maps/yaml/THINGPULSE_EPULSE_FEATHER_C6.yml +15 -0
- data/vendor/board-maps/yaml/TINYC6.yml +25 -0
- data/vendor/board-maps/yaml/UPESY_EDU_ESP32.yml +28 -0
- data/vendor/board-maps/yaml/UPESY_ESP32C3_BASIC.yml +13 -0
- data/vendor/board-maps/yaml/UPESY_ESP32C3_MINI.yml +12 -0
- data/vendor/board-maps/yaml/UPESY_ESP32S3_BASIC.yml +42 -0
- data/vendor/board-maps/yaml/VIRALINK_GATE32_01.yml +6 -0
- data/vendor/board-maps/yaml/VIRALINK_GATE32_11.yml +7 -0
- data/vendor/board-maps/yaml/WAVESHARE_ESP32S3_TOUCH_LCD_128.yml +8 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_MATRIX.yml +48 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ONE.yml +1 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_PIZERO.yml +47 -0
- data/vendor/board-maps/yaml/WAVESHARE_RP2040_ZERO.yml +1 -0
- data/vendor/board-maps/yaml/WEACT_STUDIO_ESP32C3.yml +14 -0
- data/vendor/board-maps/yaml/WIPY3.yml +1 -0
- data/vendor/board-maps/yaml/WT32_SC01_PLUS.yml +7 -0
- data/vendor/board-maps/yaml/WiFiduinoV2.yml +1 -0
- data/vendor/board-maps/yaml/XIAO_ESP32C3.yml +0 -1
- data/vendor/board-maps/yaml/XIAO_ESP32C6.yml +22 -0
- data/vendor/board-maps/yaml/unphone9.yml +8 -0
- metadata +169 -30
- data/examples/led/apa102_breathe.rb +0 -45
- data/examples/pulse_io/ir_transmitter.rb +0 -55
- data/examples/spi/ssd_through_register.rb +0 -40
- data/examples/uart/bit_bang_read.rb +0 -16
- data/examples/uart/bit_bang_write.rb +0 -16
- data/lib/denko/analog_io/sensor.rb +0 -6
- data/lib/denko/sensor/virtual.rb +0 -42
- data/src/lib/DenkoIROutESP.cpp +0 -26
- data/vendor/board-maps/yaml/STAMP_S3.yml +0 -8
- /data/vendor/board-maps/yaml/{BRIDGETEK_IDM2040-7A.yml → BRIDGETEK_IDM2040_43A.yml} +0 -0
- /data/vendor/board-maps/yaml/{heltec_wifi_32_lora_V3.yml → HELTEC_WIRELESS_STICK_V3.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stack_Core_ESP32.yml → M5STACK_CORE.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stamp_Pico.yml → M5STACK_STAMP_PICO.yml} +0 -0
- /data/vendor/board-maps/yaml/{M5Stack-Timer-CAM.yml → M5STACK_TIMER_CAM.yml} +0 -0
data/examples/sensor/bme280.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# BME280 sensor over I2C, for temperature, pressure and humidity.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
8
|
board = Denko::Board.new(Denko::Connection::Serial.new)
|
8
|
-
bus
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
10
|
|
10
11
|
sensor = Denko::Sensor::BME280.new(bus: bus) # address: 0x76 default
|
11
12
|
# Use A BMP280 with no humidity instead.
|
12
|
-
# sensor = Denko::Sensor::BMP280.new(bus: bus) # address: 0x76
|
13
|
+
# sensor = Denko::Sensor::BMP280.new(bus: bus) # address: 0x76 default
|
13
14
|
|
14
15
|
# Default reading mode is oneshot ("forced" in datasheet).
|
15
16
|
# sensor.oneshot_mode
|
@@ -28,7 +29,6 @@ sensor = Denko::Sensor::BME280.new(bus: bus) # address: 0x76 default
|
|
28
29
|
# print sensor.config_register_bits
|
29
30
|
|
30
31
|
# Get the shared #print_tph_reading method to print readings neatly.
|
31
|
-
require_relative 'neat_tph_readings'
|
32
32
|
|
33
33
|
# Poll it and print readings.
|
34
34
|
sensor.poll(5) do |reading|
|
data/examples/sensor/bmp180.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# BMP180 sensor over I2C, for temperature and pressure.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
board
|
8
|
-
bus
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
10
|
sensor = Denko::Sensor::BMP180.new(bus: bus) # address: 0x77 default
|
10
11
|
|
11
12
|
# Enable oversampling for the pressure sensor only (1,2,4, 8).
|
12
13
|
# sensor.pressure_samples = 8
|
13
14
|
|
14
|
-
#
|
15
|
-
|
15
|
+
# Demonstrate helper methods
|
16
|
+
result = sensor.read
|
17
|
+
puts "Temperature unit helpers: #{sensor.temperature} \xC2\xB0C | #{sensor.temperature_f} \xC2\xB0F | #{sensor.temperature_k} K"
|
18
|
+
puts "Pressure unit helpers: #{sensor.pressure} Pa | #{sensor.pressure_atm.round(6)} atm | #{sensor.pressure_bar.round(6)} bar"
|
19
|
+
puts
|
16
20
|
|
17
21
|
# Poll it and print readings.
|
18
22
|
sensor.poll(5) do |reading|
|
data/examples/sensor/dht.rb
CHANGED
@@ -1,24 +1,29 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# DHT sensor class for DHT 11 and DHT 22 sensors.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
|
8
|
-
dht = Denko::Sensor::DHT.new(pin: 5, board: board)
|
8
|
+
PIN = 5
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
11
|
+
sensor = Denko::Sensor::DHT.new(board: board, pin: PIN)
|
12
|
+
|
13
|
+
sensor.read
|
14
|
+
if sensor.temperature
|
15
|
+
puts "Temperature unit helpers: #{sensor.temperature} \xC2\xB0C | #{sensor.temperature_f} \xC2\xB0F | #{sensor.temperature_k} K"; puts
|
16
|
+
else
|
17
|
+
puts "ERROR: Sensor not connected... Quitting..."
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
# Don't try to read it again too quickly.
|
22
|
+
sleep(1)
|
23
|
+
|
24
|
+
# Poll it and print readings.
|
25
|
+
sensor.poll(5) do |reading|
|
26
|
+
print_tph_reading(reading)
|
20
27
|
end
|
21
28
|
|
22
|
-
# Read it every 5 seconds.
|
23
|
-
dht.poll(5)
|
24
29
|
sleep
|
data/examples/sensor/ds18b20.rb
CHANGED
@@ -4,31 +4,22 @@
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
6
|
|
7
|
-
|
8
|
-
bus = Denko::OneWire::Bus.new(pin:4, board: board)
|
7
|
+
PIN = 4
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
if bus.parasite_power
|
13
|
-
puts "Parasite power detected..."; puts
|
14
|
-
end
|
9
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
10
|
+
bus = Denko::OneWire::Bus.new(board: board, pin: PIN)
|
15
11
|
|
16
|
-
|
17
|
-
if bus.device_present?
|
18
|
-
puts "Devices present on bus..."; puts
|
19
|
-
else
|
12
|
+
unless bus.device_present?
|
20
13
|
puts "No devices present on bus... Quitting..."
|
21
14
|
return
|
22
15
|
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
count = bus.found_devices.count
|
28
|
-
puts "Found #{count} device#{'s' if count > 1} on the bus:"
|
29
|
-
puts bus.found_devices.inspect; puts
|
17
|
+
if bus.parasite_power
|
18
|
+
puts "Parasite power detected..."; puts
|
19
|
+
end
|
30
20
|
|
31
|
-
#
|
21
|
+
# Search the bus and use results to set up DS18B20 instances.
|
22
|
+
bus.search
|
32
23
|
ds18b20s = []
|
33
24
|
bus.found_devices.each do |d|
|
34
25
|
if d[:class] == Denko::Sensor::DS18B20
|
@@ -36,7 +27,15 @@ bus.found_devices.each do |d|
|
|
36
27
|
end
|
37
28
|
end
|
38
29
|
|
39
|
-
|
30
|
+
if ds18b20s.empty?
|
31
|
+
puts "No DS18B20 sensors found on the bus... Quitting...";
|
32
|
+
else
|
33
|
+
puts "Found DS18B20 sensors with these serials:"
|
34
|
+
puts ds18b20s.map { |d| d.serial_number }
|
35
|
+
puts
|
36
|
+
end
|
37
|
+
|
38
|
+
# Format a reading for printing on a line.
|
40
39
|
def print_reading(reading, sensor)
|
41
40
|
print "#{Time.now.strftime '%Y-%m-%d %H:%M:%S'} - "
|
42
41
|
print "Serial(HEX): #{sensor.serial_number} | Res: #{sensor.resolution} bits | "
|
@@ -44,8 +43,8 @@ def print_reading(reading, sensor)
|
|
44
43
|
if reading[:crc_error]
|
45
44
|
puts "CRC check failed for this reading!"
|
46
45
|
else
|
47
|
-
|
48
|
-
puts "
|
46
|
+
fahrenheit = (reading[:temperature] * 1.8 + 32).round(1)
|
47
|
+
puts "#{reading[:temperature]} \xC2\xB0C | #{fahrenheit} \xC2\xB0F"
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -13,8 +13,10 @@
|
|
13
13
|
require 'bundler/setup'
|
14
14
|
require 'denko'
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
PIN = 8
|
17
|
+
|
18
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
19
|
+
sensor = Denko::Sensor::GenericPIR.new(board: board, pin: PIN)
|
18
20
|
|
19
21
|
sensor.on_motion_start { print "Motion detected! \r" }
|
20
22
|
sensor.on_motion_stop { print "No motion detected... \r" }
|
data/examples/sensor/hcsr04.rb
CHANGED
@@ -4,10 +4,13 @@
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
6
|
|
7
|
+
TRIGGER_PIN = 6
|
8
|
+
ECHO_PIN = 7
|
9
|
+
|
7
10
|
board = Denko::Board.new(Denko::Connection::Serial.new)
|
8
|
-
hcsr04 = Denko::Sensor::HCSR04.new(board: board, pins: {trigger:
|
11
|
+
hcsr04 = Denko::Sensor::HCSR04.new(board: board, pins: {trigger: TRIGGER_PIN, echo: ECHO_PIN})
|
9
12
|
|
10
|
-
hcsr04.poll(0.
|
13
|
+
hcsr04.poll(0.50) do |distance|
|
11
14
|
puts "Distance: #{distance} mm"
|
12
15
|
end
|
13
16
|
|
data/examples/sensor/htu21d.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# HTU21D sensor over I2C, for temperature and humidity.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
board
|
8
|
-
bus
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
10
|
htu21d = Denko::Sensor::HTU21D.new(bus: bus) # address: 0x40 default
|
10
11
|
|
11
12
|
# Get and set heater state.
|
@@ -30,25 +31,13 @@ puts "Temperature resolution: #{htu21d.resolution[:temperature]} bits"
|
|
30
31
|
puts "Humidity resolution: #{htu21d.resolution[:humidity]} bits"
|
31
32
|
puts
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
# The HTU21D class doesn't directly implement polling methods either.
|
36
|
-
#
|
37
|
-
puts "Direct Temperature: #{htu21d.read_temperature.round(3)} \xC2\xB0C"
|
38
|
-
puts "Direct Humidity: #{htu21d.read_humidity.round(3)} %"
|
39
|
-
puts
|
40
|
-
|
41
|
-
# The last read state can be accessed through sub-objects or [].
|
42
|
-
puts "Last Temperature: #{htu21d.temperature.fahrenheit.round(3)} \xC2\xB0F"
|
43
|
-
puts "Last Humidity: #{htu21d[:humidity].round(3)} %"
|
34
|
+
htu21d.read
|
35
|
+
puts "Temperature unit helpers: #{htu21d.temperature} \xC2\xB0C | #{htu21d.temperature_f} \xC2\xB0F | #{htu21d.temperature_k} K"
|
44
36
|
puts
|
45
37
|
|
46
|
-
# Poll
|
47
|
-
htu21d.
|
48
|
-
|
49
|
-
end
|
50
|
-
htu21d.humidity.poll(4) do |value|
|
51
|
-
puts "Sub-Object Humidity: #{value.round(3)} %"
|
38
|
+
# Poll it and print readings.
|
39
|
+
htu21d.poll(5) do |reading|
|
40
|
+
print_tph_reading(reading)
|
52
41
|
end
|
53
42
|
|
54
43
|
sleep
|
data/examples/sensor/htu31d.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# HTU31D sensor over I2C, for temperature and humidity.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
board
|
8
|
-
bus
|
9
|
-
sensor = Denko::Sensor::HTU31D.new(bus: bus)
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
10
|
+
sensor = Denko::Sensor::HTU31D.new(bus: bus) # address: 0x40 default
|
10
11
|
|
11
12
|
# Get and set heater state.
|
12
13
|
sensor.heater_on
|
@@ -22,12 +23,9 @@ puts
|
|
22
23
|
|
23
24
|
# Resolution goes from 0..3 separately for temperature and humidity. See datasheet.
|
24
25
|
sensor.temperature_resolution = 3
|
25
|
-
sensor.humidity_resolution
|
26
|
-
|
27
|
-
# Get the shared #print_tph_reading method to print readings neatly.
|
28
|
-
require_relative 'neat_tph_readings'
|
26
|
+
sensor.humidity_resolution = 3
|
29
27
|
|
30
|
-
#
|
28
|
+
# Poll it and print readings.
|
31
29
|
sensor.poll(5) do |reading|
|
32
30
|
print_tph_reading(reading)
|
33
31
|
end
|
@@ -3,24 +3,30 @@
|
|
3
3
|
# Give a hash with readings as float values and it prints them neatly.
|
4
4
|
#
|
5
5
|
def print_tph_reading(reading)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
elements = []
|
7
|
+
|
9
8
|
# Temperature
|
10
|
-
|
11
|
-
|
9
|
+
if reading[:temperature]
|
10
|
+
formatted_temp = reading[:temperature].to_f.round(2).to_s.ljust(5, '0')
|
11
|
+
elements << "Temperature: #{formatted_temp} \xC2\xB0C"
|
12
|
+
end
|
12
13
|
|
13
14
|
# Pressure
|
14
15
|
if reading[:pressure]
|
15
|
-
formatted_pressure =
|
16
|
-
|
16
|
+
formatted_pressure = reading[:pressure].round(2).to_s.ljust(7, '0')
|
17
|
+
elements << "Pressure: #{formatted_pressure} Pa"
|
17
18
|
end
|
18
19
|
|
19
20
|
# Humidity
|
20
21
|
if reading[:humidity]
|
21
22
|
formatted_humidity = reading[:humidity].round(2).to_s.ljust(5, '0')
|
22
|
-
|
23
|
+
elements << "Humidity: #{formatted_humidity} %"
|
23
24
|
end
|
25
|
+
|
26
|
+
return if elements.empty?
|
27
|
+
|
28
|
+
# Time
|
29
|
+
print "#{Time.now.strftime '%Y-%m-%d %H:%M:%S'} - "
|
24
30
|
|
25
|
-
puts
|
31
|
+
puts elements.join(" | ")
|
26
32
|
end
|
data/examples/sensor/qmp6988.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
board
|
8
|
-
bus
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
10
|
sensor = Denko::Sensor::QMP6988.new(bus: bus) # address: 0x70 default
|
10
11
|
|
11
12
|
# Verify chip_id.
|
@@ -25,8 +26,8 @@ puts
|
|
25
26
|
#
|
26
27
|
# High accuracy settings from datasheet, with IIR of 2.
|
27
28
|
sensor.temperature_samples = 2
|
28
|
-
sensor.pressure_samples
|
29
|
-
sensor.iir_coefficient
|
29
|
+
sensor.pressure_samples = 16
|
30
|
+
sensor.iir_coefficient = 2
|
30
31
|
|
31
32
|
#
|
32
33
|
# Change mode (default: forced_mode)
|
@@ -42,9 +43,6 @@ sensor.continuous_mode
|
|
42
43
|
#
|
43
44
|
# sensor.standby_time = 500
|
44
45
|
|
45
|
-
# Get the shared #print_tph_reading method to print readings neatly.
|
46
|
-
require_relative 'neat_tph_readings'
|
47
|
-
|
48
46
|
# Poll it and print readings.
|
49
47
|
sensor.poll(5) do |reading|
|
50
48
|
print_tph_reading(reading)
|
data/examples/sensor/rcwl9620.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# RCWL-9620 sensor over I2C to measure distance.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
6
|
|
7
|
-
board
|
8
|
-
bus
|
7
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
8
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
9
|
sensor = Denko::Sensor::RCWL9620.new(bus: bus) # address: 0x57 default
|
10
10
|
|
11
11
|
sensor.poll(1) do |distance|
|
data/examples/sensor/sht3x.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# SHT30/31/35 sensor over I2C, for temperature and humidity.
|
3
3
|
#
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'denko'
|
6
|
+
require_relative 'neat_tph_readings'
|
6
7
|
|
7
|
-
board
|
8
|
-
bus
|
8
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
9
|
+
bus = Denko::I2C::Bus.new(board: board)
|
9
10
|
sensor = Denko::Sensor::SHT3X.new(bus: bus) # address: 0x44 default
|
10
11
|
|
11
12
|
# Heater control
|
@@ -23,9 +24,6 @@ puts
|
|
23
24
|
# Set repeatability= :low, :medium or :high (default). See datasheet for details.
|
24
25
|
sensor.repeatability = :high
|
25
26
|
|
26
|
-
# Get the shared #print_tph_reading method to print readings neatly.
|
27
|
-
require_relative 'neat_tph_readings'
|
28
|
-
|
29
27
|
# Poll it and print readings.
|
30
28
|
sensor.poll(5) do |reading|
|
31
29
|
print_tph_reading(reading)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'denko'
|
3
|
+
|
4
|
+
SPI_BIT_BANG_PINS = { clock: 13, input: 12, output: 11 }
|
5
|
+
SELECT_PIN = 10
|
6
|
+
|
7
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
8
|
+
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
9
|
+
|
10
|
+
# Methods so results print neatly. SPI transfers don't block main thread.
|
11
|
+
def stop_waiting
|
12
|
+
$waiting = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def wait_for_read
|
16
|
+
$waiting = true
|
17
|
+
sleep 0.001 while $waiting
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a simple test component class.
|
21
|
+
class SPITester
|
22
|
+
include Denko::SPI::Peripheral::SinglePin
|
23
|
+
end
|
24
|
+
spi_tester = SPITester.new(bus: bus, pin: SELECT_PIN)
|
25
|
+
|
26
|
+
spi_tester.add_callback do |rx_bytes|
|
27
|
+
# If MOSI and MISO are connected this should match TEST_DATA.
|
28
|
+
# If not, all bytes should be 255.
|
29
|
+
puts "Result : #{rx_bytes.inspect}"
|
30
|
+
stop_waiting
|
31
|
+
end
|
32
|
+
|
33
|
+
TEST_DATA = [0, 1, 2, 3, 4, 5, 6, 7]
|
34
|
+
|
35
|
+
# Send and receive same data.
|
36
|
+
puts "Tx 8 / Rx 8 : #{TEST_DATA.inspect}"
|
37
|
+
spi_tester.spi_transfer(write: TEST_DATA, read: 8)
|
38
|
+
wait_for_read
|
39
|
+
|
40
|
+
puts "Tx 8 / Rx 12: #{TEST_DATA.inspect}"
|
41
|
+
spi_tester.spi_transfer(write: TEST_DATA, read: 12)
|
42
|
+
wait_for_read
|
43
|
+
|
44
|
+
puts "Tx 8 / Rx 4 : #{TEST_DATA.inspect}"
|
45
|
+
spi_tester.spi_transfer(write: TEST_DATA, read: 4)
|
46
|
+
wait_for_read
|
@@ -1,6 +1,5 @@
|
|
1
1
|
#
|
2
|
-
#
|
3
|
-
# Can be used over either a bit bang or hardware SPI interface.
|
2
|
+
# Button connected through input shift register (CD4021B).
|
4
3
|
#
|
5
4
|
require 'bundler/setup'
|
6
5
|
require 'denko'
|
@@ -13,16 +12,7 @@ REGISTER_SELECT_PIN = 9
|
|
13
12
|
BUTTON_PIN = 0
|
14
13
|
|
15
14
|
board = Denko::Board.new(Denko::Connection::Serial.new)
|
16
|
-
|
17
|
-
# 1-way (input) bit bang SPI interface on any pins (slower, but flexible).
|
18
|
-
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
19
|
-
|
20
|
-
# Use the default hardware SPI bus (faster, but predetermined pins).
|
21
|
-
# bus = Denko::SPI::Bus.new(board: board)
|
22
|
-
|
23
|
-
# Show the hardware SPI pins to aid connection.
|
24
|
-
# MOSI = output | MISO = input | SCK = clock
|
25
|
-
# puts board.map.select { |name, number| [:MOSI, :MISO, :SCK].include?(name) }
|
15
|
+
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
26
16
|
|
27
17
|
# InputRegister needs a bus and its select pin. The CD4021 likes SPI mode 2.
|
28
18
|
# Other options and their defaults:
|
@@ -33,18 +23,18 @@ bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
|
33
23
|
#
|
34
24
|
register = Denko::SPI::InputRegister.new(bus: bus, pin: REGISTER_SELECT_PIN, spi_mode: 2)
|
35
25
|
|
36
|
-
# InputRegister
|
37
|
-
#
|
26
|
+
# InputRegister is a BoardProxy, so DigitalInput components can can use
|
27
|
+
# it in place of a board. Use it with a Button instance.
|
38
28
|
#
|
39
|
-
# button starts listening automatically, which
|
40
|
-
#
|
41
|
-
#
|
29
|
+
# button starts listening automatically, which tells register to start listening.
|
30
|
+
# On Denko::Board, InputRegisters listen with an 8ms interval by default, compared
|
31
|
+
# to 1ms default for a Button directly connected to a Board.
|
42
32
|
#
|
43
|
-
button = Denko::DigitalIO::Button.new(pin:
|
33
|
+
button = Denko::DigitalIO::Button.new(pin: BUTTON_PIN, board: register)
|
44
34
|
|
45
35
|
# Button callbacks.
|
46
36
|
button.down { puts "Button pressed" }
|
47
37
|
button.up { puts "Button released" }
|
48
38
|
|
49
|
-
#
|
39
|
+
# Keep main thread alive.
|
50
40
|
sleep
|
@@ -12,17 +12,10 @@ REGISTER_SELECT_PIN = 10
|
|
12
12
|
# LED pin (on register parallel outputs)
|
13
13
|
LED_PIN = 0
|
14
14
|
|
15
|
+
# Works on hardware or bit-bang SPI.
|
15
16
|
board = Denko::Board.new(Denko::Connection::Serial.new)
|
16
|
-
|
17
|
-
# 1-way (output) bit bang SPI interface on any pins (slower, but flexible).
|
18
|
-
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
19
|
-
|
20
|
-
# Use the default hardware SPI bus (faster, but predetermined pins).
|
21
17
|
# bus = Denko::SPI::Bus.new(board: board)
|
22
|
-
|
23
|
-
# Show the hardware SPI pins to aid connection.
|
24
|
-
# MOSI = output | MISO = input | SCK = clock
|
25
|
-
# puts board.map.select { |name, number| [:MOSI, :MISO, :SCK].include?(name) }
|
18
|
+
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
26
19
|
|
27
20
|
# OutputRegister needs a bus and its select pin.
|
28
21
|
# Other options and their defaults:
|
@@ -30,19 +23,18 @@ bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
|
30
23
|
# spi_frequency: 1000000 - Only affects hardware SPI interfaces
|
31
24
|
# spi_mode: 0
|
32
25
|
# spi_bit_order: :msbfirst
|
33
|
-
# write_delay: 0.001 - How long to buffer writes, in seconds
|
34
|
-
# buffer_writes: true - Wait for write_delay before writing whole register state.
|
35
|
-
# Makes proxied components write pseudo-parallelly.
|
36
26
|
#
|
37
27
|
register = Denko::SPI::OutputRegister.new(bus: bus, pin: REGISTER_SELECT_PIN)
|
38
28
|
|
39
|
-
#
|
40
|
-
register.
|
29
|
+
# Turn the LED on by setting the corresponding register bit to 1, then writing to it.
|
30
|
+
register.bit_set(LED_PIN, 1)
|
31
|
+
register.write
|
32
|
+
sleep 2
|
41
33
|
|
42
|
-
# OutputRegister
|
43
|
-
#
|
34
|
+
# OutputRegister is a BoardProxy, so DigitalOutput components can use
|
35
|
+
# it in place of a board. Use it with an LED instance.
|
44
36
|
#
|
45
|
-
led = Denko::LED.new(board: register, pin:
|
37
|
+
led = Denko::LED.new(board: register, pin: LED_PIN)
|
46
38
|
|
47
39
|
# Blink the LED and sleep the main thread.
|
48
40
|
led.blink 0.5
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# SevenSegment LED driven though a pair of daisy chained OutputRegisters
|
3
|
+
# (74HC595), with some segments on each register.
|
4
|
+
#
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'denko'
|
7
|
+
|
8
|
+
# SPI pins (on board)
|
9
|
+
SPI_BIT_BANG_PINS = { clock: 13, output: 11 }
|
10
|
+
REGISTER_SELECT_PIN = 10
|
11
|
+
|
12
|
+
# SevenSegment pins (on registers' parallel outputs)
|
13
|
+
SEVEN_SEGMENT_PINS = { cathode: 14, a: 10, b: 9, c: 4, d: 2, e: 1, f: 12, g: 13 }
|
14
|
+
|
15
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
16
|
+
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
17
|
+
|
18
|
+
# Model as one 2-byte (16-bit) OutputRegister, since they're daisy chained.
|
19
|
+
# Bit numbering starts at the first register, so bit 0 of the second register
|
20
|
+
# is bit 8 of the OutputRegister instance.
|
21
|
+
register = Denko::SPI::OutputRegister.new(bus: bus, pin: REGISTER_SELECT_PIN, bytes: 2)
|
22
|
+
ssd = Denko::LED::SevenSegment.new(board: register, pins: SEVEN_SEGMENT_PINS)
|
23
|
+
|
24
|
+
# Turn off the ssd on exit.
|
25
|
+
trap("SIGINT") { exit !ssd.off }
|
26
|
+
|
27
|
+
# Type a character and press Enter to show it on the SevenSegment LED.
|
28
|
+
loop { ssd.display(gets.chomp) }
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# 2 SPI registers (74HC595 and CD4021B) on the same bus, both acting as
|
3
|
+
# BoardProxies for their Subcomponents.
|
4
4
|
#
|
5
5
|
require 'bundler/setup'
|
6
6
|
require 'denko'
|
@@ -11,36 +11,30 @@ OUT_REGISTER_SELECT = 10
|
|
11
11
|
IN_REGISTER_SELECT = 9
|
12
12
|
|
13
13
|
# LED and Button pins (on their respective registers' parallel pins)
|
14
|
-
LED_PIN
|
15
|
-
BUTTON_PIN
|
14
|
+
LED_PIN = 0
|
15
|
+
BUTTON_PIN = 0
|
16
16
|
|
17
|
-
board
|
18
|
-
|
19
|
-
# 2-way bit bang SPI bus (slower, but use any pins).
|
20
|
-
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
21
|
-
|
22
|
-
# Use the default hardware SPI bus (faster, but predetermined pins).
|
23
|
-
# bus = Denko::SPI::Bus.new(board: board)
|
24
|
-
|
25
|
-
# Show the hardware SPI pins to aid connection.
|
26
|
-
# MOSI = output | MISO = input | SCK = clock
|
27
|
-
# puts board.map.select { |name, number| [:MOSI, :MISO, :SCK].include?(name) }
|
28
|
-
|
29
|
-
# OutputRegister needs a bus and its select pin.
|
17
|
+
board = Denko::Board.new(Denko::Connection::Serial.new)
|
18
|
+
bus = Denko::SPI::BitBang.new(board: board, pins: SPI_BIT_BANG_PINS)
|
30
19
|
out_register = Denko::SPI::OutputRegister.new(bus: bus, pin: OUT_REGISTER_SELECT)
|
31
|
-
|
32
|
-
# InputRegister needs a bus and its select pin. The CD4021 likes SPI mode 2.
|
33
|
-
in_register = Denko::SPI::InputRegister.new(bus: bus, pin: IN_REGISTER_SELECT, spi_mode: 2)
|
20
|
+
in_register = Denko::SPI::InputRegister.new(bus: bus, pin: IN_REGISTER_SELECT, spi_mode: 2)
|
34
21
|
|
35
22
|
# LED connected to the output register.
|
36
|
-
led = Denko::LED.new(board: out_register, pin: LED_PIN)
|
23
|
+
led = Denko::LED.new(board: out_register, pin: LED_PIN)
|
37
24
|
|
38
25
|
# Button connected to the input register.
|
39
26
|
button = Denko::DigitalIO::Button.new(board: in_register, pin: BUTTON_PIN)
|
40
27
|
|
41
28
|
# Button callbacks.
|
42
|
-
button.down
|
43
|
-
|
29
|
+
button.down do
|
30
|
+
led.on
|
31
|
+
puts "Button pressed"
|
32
|
+
end
|
33
|
+
|
34
|
+
button.up do
|
35
|
+
led.off
|
36
|
+
puts "Button released"
|
37
|
+
end
|
44
38
|
|
45
|
-
#
|
39
|
+
# Keep main thread alive.
|
46
40
|
sleep
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Bit-bang UART is only used on the Arduino UNO / ATmega328p, because it has no
|
3
|
+
# extra hardware UARTs. This also makes a self-loopback test impossible. Connect a
|
4
|
+
# second board (Arduino Mega) and use its UART1 to verify bit-bang works on the Uno.
|
5
|
+
#
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'denko'
|
8
|
+
|
9
|
+
uno = Denko::Board.new(Denko::Connection::Serial.new(device: "/dev/cu.usbserial-1450"))
|
10
|
+
mega = Denko::Board.new(Denko::Connection::Serial.new(device: "/dev/cu.usbmodem14101"))
|
11
|
+
|
12
|
+
mega_uart1 = Denko::UART::Hardware.new(board: mega, index: 1, baud: 31250)
|
13
|
+
uno_bb_uart = Denko::UART::BitBang.new(board: uno, pins: { rx:10, tx:11 }, baud: 31250)
|
14
|
+
|
15
|
+
# Write to Uno, read from Mega
|
16
|
+
uno_bb_uart.write("Hello World!\n")
|
17
|
+
sleep 0.5
|
18
|
+
line = mega_uart1.gets
|
19
|
+
puts "Mega received from Uno: #{line}"
|
20
|
+
|
21
|
+
# Write to Uno, read from Mega
|
22
|
+
mega_uart1.write("Goodbye World!\n")
|
23
|
+
sleep 0.5
|
24
|
+
line = uno_bb_uart.gets
|
25
|
+
puts "Uno received from Mega: #{line}"
|