Updated 2017-11-17 03:41:55 by Jorge

JM 9/7/2017

What is firmata? https://github.com/firmata/protocol

tfirmata is a Tcl implementation of Arduino Firmata:

The original tfirmata did not work for me on Windows7, I suspect there is an endless loop on the tfirmata::open cmd.

The enhanced version (by chw) worked just fine, with the following code as a minimum example:
 console show
 package require tfirmata
 set bd [tfirmata::open COM8]

 $bd mode 13 out

 for {set i 1} {$i <20} {incr i} {
    $bd dset 13 1
    tfirmata::sleep 250
    $bd dset 13 0
    tfirmata::sleep 250
    puts $i
 }
 puts done...

Writing to LCD with I2c module:
with some like this:
 #
 # twi_LCD.tcl
 #
 # Enables TWI pins, and writes a message
 # to LCD with I2C module
 #
 console show
 package require tfirmata

 proc send_data {byte} {
 global bd addr
 set byte [string range $byte end-1 end]
 puts "byte: $byte"
 foreach {n1 n2} [split $byte ""] break
 $bd twiset $addr 0x${n1}5 0x${n1}1 0x${n2}5 0x${n2}1
 }

 set bd [tfirmata::open COM8]
 $bd twiconfig

 set addr 0x27

 $bd twiset $addr 0x34 0x30
 tfirmata::sleep 5
 $bd twiset $addr 0x34 0x30 0x34 0x30 0x24 0x20 0x24 0x20
 $bd twiset $addr 0xc4 0xc0
 $bd twiset $addr 0x04 0x00 0x14 0x10
 $bd twiset $addr 0x04 0x00 0xc4 0xc0
 $bd twiset $addr 0x04 0x00 0x64 0x60

 #
 foreach letter [split "Tcl/Tk & Arduino" ""] {
 binary scan $letter "H2" valor
 send_data $valor
 }

 $bd close