JM Nov-16-2011 Some links to jcw's technical weblog, Tcl related in a very interesting way...
an inspiring site, to learn, to experiment, to share...
Inside JeeMon | 2009/04/14 | <link> |
Sensor data coming in | 2009/08/25 | <link> |
An OOK Scope | 2010/04/13 | <link> |
Improved OOK Scope | 2010/04/17 | <link> |
Oven temperature plot | 2010/05/14 | <link> |
Mid 2011: JeeMon evolved to version 1.5
Playing with indentation | 2011/09/09 | <link> |
RFM12B Command Calculator | 2011/09/18 | <link> |
Hacking around in software | 2011/09/24 | <link> |
JeeMon? JeeBus? JeeRev? | 2011/11/22 | <link> |
What’s in the yellow box? | 2011/11/23 | <link> |
JeeRev sits under the hood | 2011/11/24 | <link> |
JeeMon for early birds | 2011/11/25 | <link> |
As I don't have any hardware to collect data, I had to replace the following part on /examples/graph-demo/main.tcl, in order to get the flot chart displayed:
Instead of this:
variable js { var options = { lines: { show: true }, points: { show: true }, xaxis: { mode: "time" }, legend: { position: "nw", margin: 3 }, shadowSize: 0, grid: { borderWidth: 1, borderColor: "#bbbbbb" }, series: { lines: { lineWidth: 1 }, points: { radius: 0.5 }, } }; $.getJSON('data.json', function(data) { $.plot($("#placeholder"), data, options); }); }
I used this:
variable js { var options = { lines: { show: true }, points: { show: true }, xaxis: { mode: "time" }, legend: { position: "nw", margin: 3 }, shadowSize: 0, grid: { borderWidth: 1, borderColor: "#bbbbbb" }, series: { lines: { lineWidth: 1 }, points: { radius: 0.5 }, } }; $(function () { var d1 = []; for (var i = 0; i < 14; i += 0.5) d1.push([i, Math.sin(i)]); var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]]; // a null signifies separate line segments var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]]; $.plot($("#placeholder"), [ d1, d2, d3 ],options); }); }
This code is a light version of:
(link above)
Arduino Code:
...place holder (just a for loop from 0 to 5, with a 1 sec delay in between each Serial.println)
main.tcl:
Jm doc "JeeMon and Arduino - a minimum example" package require Tk proc APP.READY {} { # Called once during application startup. wm title . "Select device" ttk::treeview .all -columns {1 2} -show headings .all heading 1 -text "USB ID" .all heading 2 -text "Device" .all column 1 -width 130 -stretch 0 .all column 2 -width 250 set count 0 foreach {id dev} [lsort -stride 2 [SysDep listSerialPorts]] { puts "$id,$dev" .all insert {} end -values [list $id $dev] incr count } pack .all -expand 1 -fill both bind .all <<TreeviewSelect>> [namespace which OokScope] if {$count == 0} { wm withdraw . tk_messageBox -type ok -message "No FTDI devices found." exit } update after 2000 # nothing to choose, save right away if {$count == 1} { .all selection set [.all identify item 1 1] } } proc OokScope {} { set item [lindex [.all selection] 0] if {$item ne ""} { set devname [lindex [.all item $item -values] 0] wm withdraw . puts "connected to: $devname" set conn [Interfaces serial connect $devname 9600] oo::objdefine $conn { # override connection to collect and display a histogram method setup {} { variable start [clock seconds] lastx 0 lasty 300 # create the GUI window set w .ookScope toplevel $w canvas $w.c -width 600 -height 300 pack $w.c } method OnReadable {} { variable start variable lastx variable lasty # called whenever data is available to process the individual raw bytes my variable fd w count minWidth maxWidth inbuf minPulses maxPulses series foreach val [split [read $fd] "\n"] { puts $val set x [expr {([clock seconds]-$start) * 10}] if {$val == ""} {set val 0} set y [expr {300 - ($val*50)}] .ookScope.c create line $lastx $lasty $x $y -width 2 set lastx $x set lasty $y } } } $conn setup } }
I just had to copy rbc0.1.kit to kit/lib/rbc0.1 as explained on section "Starkit for Tclkit 8.4, 8.5 and 8.6 (Linux-x86 and Win32-x86)" on Refactored BLT Components
Arduino:
void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { float x; char texto[10]; for (long i=0;i<361;i=i+5) { x = sin((i*3.14)/180); dtostrf(x,5,2,texto); Serial.print(i); Serial.print(" "); Serial.println(texto); delay(1000); } }
Tcl Side:
Jm doc "JeeMon and BLT" package require Tk source kit/lib/rbc0.1/rbc0.1.kit package require rbc proc APP.READY {} { # Called once during application startup. wm title . "Select device" ttk::treeview .all -columns {1 2} -show headings .all heading 1 -text "USB ID" .all heading 2 -text "Device" .all column 1 -width 130 -stretch 0 .all column 2 -width 250 set count 0 foreach {id dev} [lsort -stride 2 [SysDep listSerialPorts]] { puts "$id,$dev" .all insert {} end -values [list $id $dev] incr count } pack .all -expand 1 -fill both bind .all <<TreeviewSelect>> [namespace which OokScope] if {$count == 0} { wm withdraw . tk_messageBox -type ok -message "No FTDI devices found." exit } #update #after 2000 # nothing to choose, save right away if {$count == 1} { .all selection set [.all identify item 1 1] } } proc OokScope {} { set item [lindex [.all selection] 0] if {$item ne ""} { set devname [lindex [.all item $item -values] 0] wm withdraw . puts "connected to: $devname" set conn [Interfaces serial connect $devname 9600] oo::objdefine $conn { # override connection to collect and display a histogram method setup {} { variable start [clock seconds] lastx 0 lasty 300 variable Hz 200 variable xvec variable y1vec rbc::vector create xvec($Hz) y1vec($Hz) # fill xvec with 0 .. $Hz-1 # xvec seq 0 [expr {$Hz - 1}] # y1vec seq 0 [expr {$Hz - 1}] # create the GUI window set w .ookScope toplevel $w canvas $w.c -width 600 -height 300 rbc::stripchart $w.s1 -height 2i -width 8i -bufferelements no $w.s1 element create line1 -xdata xvec -ydata y1vec -symbol none -color red pack $w.c $w.s1 } method OnReadable {} { variable start variable lastx variable lasty variable xvec variable y1vec # called whenever data is available to process the individual raw bytes my variable fd w count minWidth maxWidth inbuf minPulses maxPulses series if {[regexp {^.+ (.+)$} [gets $fd] -> val]} { #puts $msg #flush $fd puts ">>> $val" set x [expr {([clock seconds]-$start)}] set xvec(++end) $x if {$val != ""} { set y [expr {150 - ($val*30)}] puts "coord: $lastx $lasty $x $y" .ookScope.c create line $lastx $lasty $x $y -width 2 set lastx $x set lasty $y set y1vec(++end) $y } } } } $conn setup } }