Scott Hanselman

Teaching coding from the Metal Up or from the Glass Back?

January 6, '17 Comments [27] Posted in Musings
Sponsored By
* Stock photo by WOCInTech Chat used under CC

Maria on my team and I have been pairing (working in code and stuff together) occasionally in order to improve our coding and tech skills. We all have gaps and it's a good idea to go over the "digital fundamentals" every once in a while to make sure you've got things straight. (Follow up post on this topic tomorrow.)

As we were whiteboarding and learning and alternating teaching each other (the best way to make sure you know a topic is to teach it to another person) I was getting the impression that, well, we weren't feeling each other's style.

Now, before we get started, yes, this is a "there's two kinds of people in this world" post. But this isn't age, background, or gender related from what I can tell. I just think folks are wired a certain way.  Yes, this a post about generalities.

Here's the idea. Just like there are kinesthetic learners and auditory learners and people who learn by repetition, in the computer world I think that some folks learn from the metal up and some folks learn from the glass back.

Learning from Metal Up

Computer Science instruction starts from the metal, most often. The computer's silicon is the metal. You start there and move up. You learn about CPUs, registers, you may learn Assembly or C, then move your way up over the years to a higher level language like Python or Java. Only then will you think about Web APIs and JSON.

You don't learn anything about user interaction or user empathy. You don't learn about shipping updates or test driven development. You learn about algorithms and Turing. You build compilers and abstract syntax trees and frankly, you don't build anything useful from a human perspective. I wrote a file system driver in Minix. I created new languages and built parsers and lexers.

  • When you type cnn.com and press enter, you can pretty much tell what happens from the address bar all the way down to electrons. AND YOU LOVE IT.
  • You feel like you own the whole stack and you understand computers like your mechanic friends understand internal combustion engines.
  • You'll open the hood of a car and look around before you drive it.
  • You'll open up a decompiler and start poking around to learn.
  • When you learn something new, you want to open it up and see what makes it tick. You want to see how it relates to what you already know.
  • If you need to understand the implementation details then an abstraction is leaking.
  • You know you will be successful because you can have a FEEL for the whole system from the computer science perspective.

Are you this person? Were you wired this way or did you learn it? If you teach this way AND it lines up with how your students learn, everyone will be successful.

Learning from the Glass Back

Learning to code instruction starts from the monitor, most often. Or even the user's eyeballs. What will they experience? Let's start with a web page and move deeper towards the backend from there.

You draw user interfaces and talk about user stories and what it looks like on the screen. You know the CPU is there and how it works but CPU internals don't light you up. If you wanted to learn more you know it's out there on YouTube or Wikipedia. But right now you want to build an application for PEOPLE an the nuts and bolts are less important. 

  • When this person types cnn.com and presses enter they know what to expect and the intermediate steps are an implementation detail.
  • You feel like you own the whole experience and you understand people and what they want from the computer.
  • You want to drive a car around a while and get a feel for it before you pop the hood.
  • You'll open F12 tools and start poking around to learn.
  • When you learn something new, you want to see examples of how it's used in the real world so you can build upon them.
  • If you need to understand the implementation details then someone in another department didn't do their job.
  • You know you will be successful because you can have a FEEL for the whole system from the user's perspective.

Are you this person? Were you wired this way or did you learn it? If you teach this way AND it lines up with how your students learn, everyone will be successful.

    Conclusion

    Everyone is different and everyone learns differently. When teaching folks to code you need to be aware of not only their goals, but also their learning style. Be ware of their classical learning style AND the way they think about computers and technology.

    My personal internal bias sometimes has me asking "HOW DO YOU NOT WANT TO KNOW ABOUT THE TOASTER INTERNALS?!?!" But that not only doesn't ship the product, it minimizes the way that others learn and what their educational goals are.

    I want to take apart the toaster. That's OK. But someone else is more interested in getting the toast to make a BLT. And that's OK.

    * Stock photo by WOCInTech Chat used under CC


    Sponsor: Big thanks to Telerik! They recently published a comprehensive whitepaper on The State of C#, discussing the history of C#, what’s new in C# 7 and whether C# is the top tech to know. Check it out!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Exploring the Tessel 2 IoT and robotics development board

    December 27, '16 Comments [10] Posted in Hardware
    Sponsored By

    13841-01I'm still on vacation and still on the mend from surgery. I'm continuing to play around with IoT devices on my staycation. Last week I looked at these devices:

    Today I'm messing with the Tessel 2. You can buy it from SparkFun for the next few weeks for US$40. The  Tessel is pretty cool as a tiny device because it includes WiFi on the board as well as two USB ports AND on-board Ethernet. It includes a two custom "module" ports where you can pop in 10-pin modules like Accelerometers, Climate sensors, IR and more. There's also community-created Tessel modules for things like Color Sensing and Motion.

    Tessel is programmable in JavaScript and runs Node. Here's the tech specs:

    • 580MHz Mediatek MT7620n
    • Linux built on OpenWRT
    • 802.11bgn WiFi
    • WEP, WPA, WPA2-PSK, WPA2-Enterprise
    • 64MB DDR2 RAM
    • 32MB Flash
    • 16 pins GPIO, 7 of which support analog in
    • 2 USB 2.0 ports with per-port power switching

    Tessel isn't a company, it's a open source project! They are on Twitter at @tesselproject and on GitHub here https://github.com/tessel.

    NOTE: Some users - including me - have had issues with some Windows machines not recognizing the Tessel 2 over USB. I spent some time exploring this thread on their support site and had to update its firmware but I haven't had issues since.

    Once you've plugged your Tessel in, you talk to it with their node based "t2" command line:

    >t2 list
    INFO Searching for nearby Tessels...
    USB Tessel-02A3226BCFA3
    LAN Tessel-02A3226BCFA3

    It's built on OpenWRT and you can even SSH into it if you want. I haven't needed to though as I just want to write JavaScript and push  projects to it. It's nice to know that you CAN get to the low-level stuff I you need to, though.

    For example, here's a basic "blink an LED" bit of code:

    // Import the interface to Tessel hardware
    var tessel = require('tessel');
    
    // Turn one of the LEDs on to start.
    tessel.led[2].on();
    
    // Blink!
    setInterval(function () {
      tessel.led[2].toggle();
      tessel.led[3].toggle();
    }, 600);
    
    console.log("I'm blinking! (Press CTRL + C to stop)");

    The programming model is very familiar, and they've abstracted away the complexities of most of the hardware. Here's a GPS example:

    var tessel = require('tessel');
    var gpsLib = require('gps-a2235h');

    var gps = gpsLib.use(tessel.port['A']);

    // Wait until the module is connected
    gps.on('ready', function () {
    console.log('GPS module powered and ready. Waiting for satellites...');
    // Emit coordinates when we get a coordinate fix
    gps.on('coordinates', function (coords) {
    console.log('Lat:', coords.lat, '\tLon:', coords.lon, '\tTimestamp:', coords.timestamp);
    });

    // Emit altitude when we get an altitude fix
    gps.on('altitude', function (alt) {
    console.log('Got an altitude of', alt.alt, 'meters (timestamp: ' + alt.timestamp + ')');
    });

    // Emitted when we have information about a fix on satellites
    gps.on('fix', function (data) {
    console.log(data.numSat, 'fixed.');
    });

    gps.on('dropped', function(){
    // we dropped the gps signal
    console.log("gps signal dropped");
    });
    });

    gps.on('error', function(err){
    console.log("got this error", err);
    });

    Of course, since it's using node and it has great Wifi or wired, the Tessel can also be a web server! Here we return the image from a USB camera.

    var av = require('tessel-av');
    var os = require('os');
    var http = require('http');
    var port = 8000;
    var camera = new av.Camera();

    http.createServer((request, response) => {
    response.writeHead(200, { 'Content-Type': 'image/jpg' });

    camera.capture().pipe(response);

    }).listen(port, () => console.log(`http://${os.hostname()}.local:${port}`));

    I'll make a Hello World webserver:

    var tessel = require('tessel');
    var http = require('http');
    
    var server = http.createServer(function (request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello from Tessel!\n");
    });
    server.listen(8080);
    console.log("Server running at http://192.168.1.101:8080/");
    

    Then push the code to the Tessel like this:

    >t2 push index.js
    INFO Looking for your Tessel...
    INFO Connected to Tessel-02A3226BCFA3.
    INFO Building project.
    INFO Writing project to Flash on Tessel-02A3226BCFA3 (3.072 kB)...
    INFO Deployed.
    INFO Your Tessel may now be untethered.
    INFO The application will run whenever Tessel boots up.
    INFO To remove this application, use "t2 erase".
    INFO Running index.js...

    Where is my Tessel on my network?

    >t2 wifi
    INFO Looking for your Tessel...
    INFO Connected to Tessel-02A3226BCFA3.
    INFO Connected to "HANSELMAN"
    INFO IP Address: 192.168.0.147
    INFO Signal Strength: (33/70)
    INFO Bitrate: 29mbps

    Now I'll hit the webserver and there it is!

    image

    There's a lot of cool community work happening around Tessel.  You can get involved with the Tessel community if you're interested:

    • Join us on Slack — Collaboration and real time discussions (Recommended! - ask your questions here).
    • Tessel Forums — General discussion and support by the Tessel community.
    • tessel.hackster.io — Community-submitted projects made with Tessel.
    • tessel.io/community — Join a Tessel meetup near you! Meetups happen around the world and are the easiest way to play with hardware in person.
    • #tessel on Freenode — IRC channel for development questions and live help.
    • Stack Overflow — Technical questions about using Tessel

    Sponsor: Big thanks to Telerik! They recently published a comprehensive whitepaper on The State of C#, discussing the history of C#, what’s new in C# 7 and whether C# is the top tech to know. Check it out!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Connecting my Particle Photon Internet of Things device to the Azure IoT Hub

    December 20, '16 Comments [1] Posted in Azure | Hardware
    Sponsored By

    Particle Photon connected to the cloudMy vacation continues. Yesterday I had shoulder surgery (adhesive capsulitis release) so today I'm messing around with Azure IoT Hub. I had some devices on my desk - some of which I had never really gotten around to exploring - and I thought I'd see if I could accomplish something.

    I've got a Particle Photon here, as well as a Tessel 2, a LattePanda, Funduino, and Onion Omega. A few days ago I was able to get the Onion Omega to show my blood sugar on a small OLED screen, which was cool. Tonight I'm going to try to hook the Particle Photon up to the Azure IoT hub for monitoring.

    The Photon is a tiny little device with Wi-Fi built-in. It's super easy to setup and it has a cloud-based IDE with tons of examples written in C and Node.js for you to use. Particle Photon also has a node.js based command line. From there you can list out your Photons, see their available functions, and even call functions over the internet! A hacker's delight, to be sure.

    Here's a standard "blink an LED" Hello world on a Photon. This one creates a cloud function called "led" and binds it to the "ledToggle" method. Those cloud methods take a string, so there's no enum for the on/off command.

    int led1 = D0;
    int led2 = D7;
    void setup() {
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    Spark.function("led",ledToggle);
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    }

    void loop() {
    }

    int ledToggle(String command) {
    if (command=="on") {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    return 1;
    }
    else if (command=="off") {
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    return 0;
    }
    else {
    return -1;
    }
    }

    From the command line I can use the Particle command line interface (CLI) to enumerate my devices:

    C:\Users\scott>particle list
    hansel_photon [390039000647xxxxxxxxxxx] (Photon) is online
    Functions:
    int led(String args)

    See how it doesn't just enumerate devices, but also cloud methods that hang off devices? LOVE THIS.

    I can get a secret API Key from the Particle Photon's cloud based Console. Then using my Device ID and auth token I can call the method...with an HTTP request! How much easier could this be?

    C:\Users\scott\>curl https://api.particle.io/v1/devices/390039000647xxxxxxxxx/led -d access_token=31fa2e6f --insecure -d arg="on"
    {
    "id": "390039000647xxxxxxxxx",
    "last_app": "",
    "connected": true,
    "return_value": 1
    }

    At this moment the LED on the Particle Photon turns on. I'm going to change the code a little and add some telemetry using the Particle's online code editor.

    Editing Particle Photon Code online

    They've got a great online code editor, but I could also edit and compile the code locally:

    C:\Users\scott\Desktop>particle compile photon webconnected.ino

    Compiling code for photon

    Including:
    webconnected.ino
    attempting to compile firmware
    downloading binary from: /v1/binaries/5858b74667ddf87fb2a2df8f
    saving to: photon_firmware_1482209089877.bin
    Memory use:
    text data bss dec hex filename
    6156 12 1488 7656 1de8
    Compile succeeded.
    Saved firmware to: C:\Users\scott\Desktop\photon_firmware_1482209089877.bin

    I'll change the code to announce an "Event" when I turn on the LED.

    if (command=="on") {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);

    String data = "Amazing! Some Data would be here! The light is on.";
    Particle.publish("ledBlinked", data);

    return 1;
    }

    I can head back over to the http://console.particle.io and see these events live on the web:

    Particle Photon's have great online charts

    Particle also supports integration with Google Cloud and Azure IoT Hub. Azure IoT Hub allows you to manage billions of devices and all their many billions of events. I just have a few, but we all have to start somewhere. ;)

    I created a free Azure IoT Hub in my Azure Account...

    Azure IoT Hub has charts and graphs built in

    And made a shared access policy for my Particle Devices.

    Be sure to set all the Access Policy Permissions you need

    Then I told Particle about Azure in their Integrations system.

    Particle has Azure IoT Hub integration built in

    The Azure IoT SDKS on GitHub at https://github.com/Azure/azure-iot-sdks/releases have both a Windows-based Azure IoT Explorer and a command-line one called IoT Hub Explorer.

    I logged in to the IoT Hub Explorer using the connection string from the Azure Portal:

    iothub-explorer login "HostName=HanselIoT.azure-devices.net;SharedAccessKeyName=particle-iot-hub;SharedAccessKey=rdWUVMXs="

    Then I'll run "iothub-explorer monitor-events" passing in the device ID and the connection string for the shared access policy. Monitor-events is cool because it'll hang and just output the events as they're flowing through the whole system.

    IoTHub-Explorer monitor-events command line

    So I'm able to call methods on the Particle using their cloud, and monitor events from within Azure IoT Hub. I can explore diagnostics data and query huge amounts of device-to-cloud data that would potentially flow in from my hardware devices.

    The IoT Hub Limits are very generous for free/hobbyist users as we learn to develop. I haven't paid anything yet. However, it can scale to thousands of messages a second per unit! That means millions of messages a second if you need it.

    I can definitely see how the the value an IoT Hub solution like this would add up quickly after you've got more than one device. Text files don't really scale. Even if I just IoT'ed up my house, it would be nice to have all that data flowing into a single hub I could manage and query securely.


    Sponsor: Big thanks to Telerik! They recently published a comprehensive whitepaper on The State of C#, discussing the history of C#, what’s new in C# 7 and whether C# is the top tech to know. Check it out!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Free Intermediate ASP.NET Core 1.0 Training on Microsoft Virtual Academy

    December 20, '16 Comments [3] Posted in ASP.NET
    Sponsored By

    At the end of October I announced that Maria from my team and I published a Microsoft Virtual Academy on ASP.NET Core. This Free ASP.NET Core 1.0 Training is up on Microsoft Virtual Academy now for you to watch and enjoy! I hope you like it, we worked very hard to bring it to you.

    Again, start with Introduction to ASP.NET Core 1.0, and explore this new technology even further in Intermediate ASP.NET Core 1.0.

    Intermediate ASP.NET Core 1.0

    Intermediate ASP.NET Core 1.0

    We've just launched Day 2, the Intermediate day. If the first is 100 level, this is 200 level. In this day, Jeff Fritz and I build on what we learned with Maria in Day 1. We're also joined by Rowan Miller and Maria later in the day as we explore topics like:

    • Tag Helpers
    • Authentication
    • Custom Middleware
    • Dependency Injection
    • Web APIs
    • Single Page Apps
    • Entity Framework Core and Database Access
    • Publishing and Deployment

    In a few weeks (maybe sooner) we'll publish Day 3 which we'll do exclusively on Macs and Linux machines. We'll talk about Cross-Platform concerns and Containers.

    NOTE: There's a LOT of quality free courseware for learning .NET Core and ASP.NET Core. We've put the best at http://asp.net/free-courses and I encourage you to check them out!

    Also, please help me out by adding a few stars there under Ratings. We're new. ;)


    Sponsor: Do you deploy the same application multiple times for each of your end customers? The team at Octopus have taken the pain out of multi-tenant deployments. Check out their latest 3.4 release

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Playing with an Onion Omega IoT device to show live Blood Sugar on an OLED screen

    December 14, '16 Comments [6] Posted in Hardware | Open Source
    Sponsored By

    arduino_lb3dg8I've been playing with IoT stuff on my vacation. Today I'm looking at an Onion Omega. This is a US$19 computer that you can program with Python, Node.js, or C/C++. There's a current IndieGogo happening for the Onion Omega2 for $5. That's a $5 Linux computer with Wi-Fi. Realistically you'd want to spend more and get expansion docks, chargers, batteries, etc, but you get the idea. I got the original Omega along with the bluetooth dongle, Arduino compatible base, tiny OLED screen. A ton of stuff to play with for less than $100.

    Note that I am not affiliated with Onion at all and I paid for it with my own money, to use for fun.

    One of the most striking things about the Onion Omega line is how polished it is. There's lots of tiny Linux Machines that basically drop you at the command line and say "OK, SSH in and here's root." The Onion Omega is far more polished.

    Onion Omega has a very polished Web UI

    The Omega can do that for you, but if you have Bonjour installed (for zeroconf networking) and can SSH in once to setup Wi-Fi, you're able to access this lovely web-based interface.

    Look at all the info about the Omega's memory, networking, device status, and more

    This clean, local web server and useful UI makes the Onion Omega extremely useful as a teaching tool. The Particle line of IoT products has a similarly polished web-interfaces, but while the Onion uses a local web server and app, the Particle Photon uses a cloud-based app that bounces down to a local administrative interface on the device. There's arguments for each, but I remain impressed with how easy it was for me to update the firmware on the Omega and get a new experience. Additionally, I made a few mistakes and "bricked" it and was able - just by following some basic instructions - to totally reflash and reset it to the defaults in just about 10 minutes. Impressive docs for an impressive product.

    image

    Onion Omega based Glucose Display via NightScout

    So it's a cool product, but how quickly can I do something trivial, but useful? Well, I have a NightScout open source diabetes management server with an API that lets me see my blood sugar. The resulting JSON looks like this:

    [  
    {
    "_id":"5851b235b8d1fea108df8b",
    "sgv":135,
    "date":1481748935000,
    "dateString":"2016-12-14T20:55:35.000Z",
    "trend":4,
    "direction":"Flat",
    "device":"share2",
    "type":"sgv"
    }
    ]

    That number under "sgv" (serum glucose value) is 135 mg/dl. That's my blood sugar right now. I could get n values back from the WebAPI and plot a chart, but baby steps. Note also the "direction" for my sugars is "flat." It's not rising nor falling in any major way.

    Let's add the OLED Display to the Onion Omega and show my sugars. Since it's an OpenWRT Linux machine, I can just add Python!

    opkg update
    opkg install python

    Some may (and will) argue that for a small IoT system, Linux is totally overkill. Sure, it likely it. But it's also very productive, fun to prototype with, and functional. Were I to go to market for real, I'd likely use something more hardened.

    As I said, I could SSH into the machine but since the Web UI is so nice, it includes an HTML-based terminal!

    A Terminal built in!

    The Onion Omega includes not just libraries for expansions like the OLED Display, but also command-line utilities. This script clears the display, initializes it, and displays some text. The value of that text will come from my yet-to-be-written python script.

    #!/bin/sh    

    oled-exp -c

    VAR=$(python ./sugar_script.py)

    oled-exp -i
    oled-exp write "$VAR"

    Then in my Python script I could print the value that would be returned into VAR and then printed with the oled-exp command line utility.

    OR, I can bypass the shell script entirely and use the Python Module for this OLED screen directly and do this. Grab the JSON, clean it up because apparently the json library sucks (?), then display it.

    #!/usr/bin/env python                                                                                                        

    from OmegaExpansion import oledExp
    import urllib
    import json

    site="https://hanselmansugars.something/api/v1/entries/sgv.json?count=1"
    jfile=urllib.urlopen(site)
    jsfile=jfile.read()
    jsfile=jsfile.replace("\n","")
    jsfile=jsfile.replace("/","")
    jsfile=jsfile.replace("]","")
    jsfile=jsfile.replace("[","")

    a=json.loads(jsfile)
    sugar=a['sgv']
    direction=a['direction']
    info="\n" + str(sugar)+" mg/dl and "+direction

    oledExp.driverInit()
    oledExp.clear()
    oledExp.write(info)

    Now here's a pic of my live blood sugar on the Onion Omega with the OLED! I could put this to run on a timer and I'm off to the races.

    The OLED Screen says "149 mg/dl and Flat"

    The next step might be to clean up the output, parse the date better, and perhaps even dynamically generate a sparkline and display the graphic on the small B&W OLED Screen.

    Have you used a small Linux IoT device like the Onion Omega?


    Sponsor: Do you deploy the same application multiple times for each of your end customers? The team at Octopus have taken the pain out of multi-tenant deployments. Check out their latest 3.4 release

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.