[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...<
> <
> <> <
> https://github.com/jcw/jeemon <
> <
> **Links** http://jeelabs.org <
> &|Inside JeeMon |2009/04/14|http://jeelabs.org/2009/04/14/inside-jeemon/%|%%|% |& &|Sensor data coming in |2009/08/25|http://jeelabs.org/2009/08/25/sensor-data-coming-in/%|%%|% |& &|An OOK Scope |2010/04/13| http://jeelabs.org/2010/04/13/an-ook-scope/%|%%|% |& &|Improved OOK Scope |2010/04/17| http://jeelabs.org/2010/04/17/improved-ook-scope/%|%%|% |& &|Oven temperature plot |2010/05/14| http://jeelabs.org/2010/05/14/oven-temperature-plot/%|%%|% |& Mid 2011: JeeMon evolved to version 1.5 &|Playing with indentation |2011/09/09| http://jeelabs.org/2011/09/09/playing-with-indentation/%|%%|% |& &|RFM12B Command Calculator|2011/09/18| http://jeelabs.org/2011/09/18/rfm12b-command-calculator/%|%%|% |& &|Hacking around in software|2011/09/24| http://jeelabs.org/2011/09/24/hacking-around-in-software/%|%%|% |& &|JeeMon? JeeBus? JeeRev? |2011/11/22|http://jeelabs.org/2011/11/22/jeemon-jeebus-jeerev/%|%%|% |& &|What’s in the yellow box? |2011/11/23|http://jeelabs.org/2011/11/23/whats-in-the-yellow-box/%|%%|% |& &|JeeRev sits under the hood|2011/11/24|http://jeelabs.org/2011/11/24/jeerev-sits-under-the-hood/%|%%|% |& &|JeeMon for early birds |2011/11/25|http://jeelabs.org/2011/11/25/jeemon-for-early-birds/%|%%|% |& **Playing with JeeMon** 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:<
> [flotChart]<
> 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); }); } **JeeMon and Arduino, a minimum example** This code is a light version of: * An OOK Scope * Oven temperature plot (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 <> [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 } } <
> [jeemon1] **JeeMon and BLT (RBC)** 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 <> [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 } } <> Hardware | HTML