Sha256: e59885a3dd23de67fbf38cd7b12023eecc87949e7b55704a7a7c09078e8e1382

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

#
# Example using one board's UART as the transport for a second board, also running Denko.
#
# For this example, board1 (direct) is an Arduino Mega. board2 (passthrough) is an Uno,
# running Denko, with its UART pins (0, 1) connected to the Mega's UART1 pins (18, 19)
#
# This isn't 100% reliable. The Rx buffer on the direct board is periodically read, so
# it can potentially overflow, causing data sent from the passthrough board to be lost.
# Eventually flow control data will be lost and the host will stop sending altogether.
#
# Use at your own risk, but for the best possible performance:
#  1) Avoid long running commands on the direct board (eg. IR transmission, HTU21D).
#     These block the CPU enough that the Rx buffer won't be read in time to avoid overflow.
#  2) Use the lowest practical baud rate on the passthrough board. 19200 is used here, so
#     the direct board's Rx buffer takes 6x the time to fill, compared to 115200 baud.
#
require 'bundler/setup'
require 'denko'

board1 = Denko::Board.new(Denko::Connection::Serial.new)

uart = Denko::UART::Hardware.new(board: board1, index: 1)
board2 = Denko::Board.new(Denko::Connection::BoardUART.new(uart, baud: 19200))

led1 = Denko::LED.new(board: board1, pin: 13)
led1.blink(0.02)

led2 = Denko::LED.new(board: board2, pin: 13)
led2.blink(0.02)

sensor = Denko::AnalogIO::Input.new(board: board1, pin: :A0)
sensor.listen(4)

sleep

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
denko-0.13.6 examples/uart/board_passthrough.rb
denko-0.13.5 examples/uart/board_passthrough.rb
denko-0.13.4 examples/uart/board_passthrough.rb
denko-0.13.3 examples/uart/board_passthrough.rb
denko-0.13.2 examples/uart/board_passthrough.rb
denko-0.13.1 examples/uart/board_passthrough.rb
denko-0.13.0 examples/uart/board_passthrough.rb