Tuesday, November 22, 2016

LittleBits Summer Event

If you have read my other blog post about LittleBits, you know I am pretty bullish about the kids-maker-movement. I do think LittleBits need more use cases and need to branch our and start making an effort to work with other devices instead of having a closed ecosystem. But kudos to them for developing a nice product that is very kids-friendly and easy to learn.

My 2015 Hackathon project at Microsoft actually had to do with LittleBits and Raspberry Pi 3 running Windows 10 Core, which won the 3rd place in the Teachers/Students/School category. That was actually the highlight of my summer that year. My goal, to whoever was willing to stop and listen at my booth, was to introduce this tool to the Microsoft Store and host kids summer camp to learn about electronics. To me, this is a great way to keep re-use the kits and benefit as much kids as possible without needing the parents to shell out an arm and a leg for LittleBits kits only to have the kids get bored after a week.

Which was why I was super excited to learn that Microsoft Store is now carrying the LittleBits kits at the store.

Maybe somebody was listening and this was the first step to carry out the idea I proposed? One can only hope... :)

Happy Coding!

Tuesday, November 15, 2016

Voice User Interface with Alexa - First Impression

It is so weird when a product works better in real life than from marketing hype. The last time I think this happened was with iPod and iPhone, it was simply something you have to get your hands on in order to appreciate the device. For me, my concern with iPod was the ease of user interface; with iPhone, how a small screen can conduct what a big screen used to do. Obviously both of the products were wildly successful and solved those two questions way ahead of me.

The biggest question on Alexa for me was this:

"Who needs a voice interface when we have virtual reality, Kinect, and a super computer that fits in your palm?" 

I thought it was going to another 10-inch Kindle that sounds ok but quickly goes away. But I think I was wrong about it. Here is the story behind it.

I am a fan of StraTechery, both the blog and Podcast. They were consistently bullish on Amazon, in particular Echo as a device and Alexa as a platform. So I thought, what the heck, I will give it a try. I was surprised at how easy it was to get started, how much Amazon has thrown its resources behind it. Even without a device, you can use EchoSim to simulate an voice controlled device and tied it to the back end.

As I read more about the use case, I think I am gradually beginning to think of it as a valid additional option. Here are what I think they do that is different:

1. You don't always have a phone with you at home, and Echo is precisely a home-based device.
2. It is hands-free, so you can operate it when you are busy with your hands and just want a quick answer. If you pay attention, you will be surprised how many times at home you just want a quick answer without pulling out your phone.
3. It is less tech than a phone. I stare at a computer screen most of the day and a phone screen the rest of the time. I treasure the time I can stay away from it while still getting the information I needed.

But even as I am turning from a non-believer into a curious party, the whole process of building my first app was still prove to be pretty difficult. In particular, I don't understand Amazon Lambda and that was suppose to be the 'easy' option to tie in the voice skill to AWS.

Stay tune for my next blog post about how I eventually was able to build my first "Hello World" app on Alexa.

ps. What does it have to do with Python and Network Engineering? Probably very little besides you can write network and Python-related apps down the line. But hay, all things starts with a little curiosity! :)

Happy Coding!

Tuesday, November 1, 2016

My New Favorite Chrome Extension - Momentum

Chrome extensions are pretty awesome, with Google's announcement for end of support for Chrome Apps, Chrome extensions will have greater importance to the game. 

I discovered Momentum earlier today when I was watching a YouTube video of Google Hangout. When he switch to a new tab, I saw this beautiful page that read "What is Your Main Focus for Today?". Which instinctively I asked myself "What IS my main focus for today?" So I pause the video and went on Google Web Store and found Momentum. 

What was a pleasant surprise is that besides the picture and weather information, you can input your own task items, cross it out, add a new item, etc. All without logging in. 

I enjoyed being reminded of my main focus everyday with inspirational quotes and beautiful images in the background. I hope you do too! 

Happy Coding! :)

Tuesday, October 11, 2016

Combine Facebook API with Twitter Bot

It has been a while since I last looked at Facebook Graph API. I had a small project that would benefit from crawling a Facebook group, here is what I want to do:

1. Crawl a Facebook group for feed periodically.
2. Parse out the Feeds for a particular person.
3. Tweet to me when that happens.

For #1 and #3, I have already done that before with Twython and AWS Lambda in this post. So I just need to figure out how to crawl Facebook group. Here were the steps I took:

1. Create a Facebook App ID and get App secret. This is pretty easy and self-explanatory.

2. Use the Facebook Graph API Page and Documentation to find the right URI to get the feed that you want. This was the most time consuming as Facebook changes access rights from version to version, and there are differences between App Token and User Token. What I finally found was using the User Token for version 2.2 (latest was 2.7) was what I needed.

Here is the curl example. You can get the group ID from going directly to the Facebook group and looking at the URI. The feed limit is just to speed up the response:

○ → curl -i -X GET \

>  "https://graph.facebook.com/v2.2/<facebook group ID>?fields=feed.limit(10)&access_token=<token>" 

3. The user token is only good for about an hour, you can make it a 60 day long term token. Here was the Facebook LInk, but I find this instruction to be much easier. 

4. Now that I have the feed, I just need to parse it out for message, creation time, and other fields that I wanted and fill in what I did before for Twitter bot and upload to Lambda. One thing that I did wrong was previously using update_status which spammed all of my followers, so I switched to direct_message. Here is the code: 

import requests, pprint, json, re, datetime
from twython import Twython
from twython.exceptions import TwythonError

with open('credentials.json') as f:
  credentials = json.loads(f.read())

client = Twython(credentials["consumer_key"],

url = "https://graph.facebook.com/v2.2/<group>?fields=feed.limit(50)&access_token=<long term access token>"

def lambda_handler(event, context):
    r = requests.get(url)
    for i in r.json()['feed']['data']:
        if i['from']['id'] == '<some user ID>':
            if re.search('shirt', i['message']):
                name = (i['from']['name'])
                createdTime = (i['created_time'])
                message = (i['message'])
                text = <your text>
                client.send_direct_message(screen_name="<some user>", text = text)

Thanks for reading. Happy Coding!

Tuesday, October 4, 2016

Google Coder for Raspberry Pi - for Kids and Adults

My wife sent me this link for Coder for Raspberry Pi a while back, but it wasn't until today (after a friendly reminder) that I began to set it up for her and the kid. The project was created by a small team of Googlers in New York, in their own words:

Well, sounds good to me! Set up was a breeze, at least for Mac it was a zip file that you download. Once unzipped, you get a 'CodeSetup' icon that you double click to launch:

It will then ask to start the process, plug in your SD Card, then unplug it when the image is transferred to the SD card.

You can then access the device via 'http://coder.local'. When you access it for the first time, it will ask you to change your password, then re-enter it with the new password.

If you have Raspberry Pi compatible wireless adaptor you can then set up WiFi in the setup menu.

The only additional thing I wanted to change the default 'coder.local' name to something else since I set up one for me, wife, and kid. No problem, this was explained in the FAQ:

Using Multiple Coder on the Network

Awesome, a quick peek shows that it is very visual, any HTML / CSS / JavaScript change you do will immediately reflected on the page. For example, this nice (scary?) looking eyeball that follows your mouse around. :)

I look forward to experiment with this nice project more with wife and kid. Looks like it is a full stack with Node.js in the backend. Not sure at this point.

Oh yeah, if you want to ssh to the Pi, the username is still pi and password is your new password:

MacBook-Air:5_Requests echou$ ssh pi@coder-eric.local
Warning: Permanently added 'coder-eric.local,' (ECDSA) to the list of known hosts.
pi@coder-eric.local's password:
Linux coder-eric 3.18.7+ #756 PREEMPT Wed Feb 18 16:08:51 GMT 2015 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Feb 21 06:27:55 2015
pi@coder-eric ~ $

I had enough time to poke around a little bit, seems like using Node.js (maybe Express) in the backend as webserver:

pi@coder-eric ~/tmp/npm-7237 $ npm --version
pi@coder-eric ~/tmp/npm-7237 $ node --version
pi@coder-eric ~/tmp/npm-7237 $

Here is their Coder GitHub Page if you want to take a look at the actual code.


Tuesday, September 27, 2016

Adafruit Circuit Playground Second Hour

If you have followed last week's post on Adafruit's Circuit Playground, you now have a working communication between your computer and the board. In this example, I would like to establish the communication between my Raspberry Pi over the serial communication to the board. This way I can leverage everything the RasPi has while utilizing the sensors and outputs from the board. 

The package I need is PySerial, which can be installed via 'sudo pip install pyserial'. It is used as the 'serial' package in Python code. 

Here is the objective: 
  1. The Arduino code will print out serial output when either the right or left button is pressed.
  2. When the B key is pressed, the LED light will light up one at a time. 
  3. In the Python code we will send the letter B 9 times then wait for any serial input

Here is the Python code. Python Code. A few notes: 

- Raspberry Pi the serial port is /dev/ttyACM0 and /dev/cu.usbmodem142 on Mac, therefore I comment out the line depending on if I am on the Mac or Raspberry Pi. 
- The character is sent as Bytecode, so chr(0x42) is used for letter 'B'. Here is an ASCII table. 

- Timeout of 1 second is used to gradually light up the LED. 

import serial
import time

#ser = serial.Serial('/dev/ttyACM0', 9600)
ser = serial.Serial('/dev/cu.usbmodem1421', 9600)

# ASCII character 'B'
sendChr = chr(0x42)

# Send character B which turns on light one at a time
for i in range(9):

# Read the input from board
while True:
    message = ser.readline()

Here is the Arduino Code: 

- I am using the Demo code provided by Adafruit:

- Use the library manager to install the Adafruit Circuit Playground Libraries

// Demo program for testing library and board - flip the switch to turn on/off buzzer

#include <Adafruit_CircuitPlayground.h>
#include <Wire.h>
#include <SPI.h>

// we light one pixel at a time, this is our counter
uint8_t pixeln = 0;

byte byteRead;

void setup() {
  //while (!Serial);
  Serial.println("Circuit Playground test!");


void loop() {

  /************* TEST BOTH BUTTONS */
  if (CircuitPlayground.leftButton()) {
    Serial.println("Left button pressed!");
  if (CircuitPlayground.rightButton()) {
    Serial.println("Right button pressed!");

  /************** Read Serial In, 65 DEC ASCII is letter B */
  byteRead = Serial.read();
  if(byteRead == 66) {
    Serial.println("Letter B input, turn on light");
    CircuitPlayground.setPixelColor(pixeln++, CircuitPlayground.colorWheel(25 * pixeln));
    if (pixeln == 11) {
    pixeln = 0;

Another screenshot for the IDE: 

You can also use the serial monitor included with the Arduino IDE to test: 

This is really fun, I cant wait to see all the possibilities when combining the two! 

Tuesday, September 20, 2016

Adafruit Circuit Playground First Hour

The Adafruit Circuit Playground arrive a few days ago. I remember seeing it for the first time at PyCon 2016 when Tony D. had a demo board and I was really impressed by it. Imagine a board not much bigger than a regular US quarter PACKED with sensors.

Here are two quick demos with playing some sound on the board:

Source: https://www.adafruit.com/

  • 10 x mini NeoPixels, each one can display any rainbow color
  • 1 x Motion sensor (LIS3DH triple-axis accelerometer with tap detection, free-fall detection)
  • 1 x Temperature sensor (thermistor)
  • 1 x Light sensor (phototransistor)
  • 1 x Sound sensor (MEMS microphone)
  • 1 x Mini speaker (magnetic buzzer)
  • 2 x Push buttons, left and right
  • 1 x Slide switch
  • 8 x alligator-clip friendly input/output pins
    Includes I2C, UART, and 4 pins that can do analog inputs/PWM output
  • All 8 pads can act as capacitive touch inputs
  • Green "ON" LED so you know its powered
  • Red "#13" LED for basic blinking
  • Reset button

No soldering required, just plug it in, setup and off you go with your prototype!

I just had some time to play with it enough to set up the environment and get a few program going. Below are some useful links and screenshots. I was able to go thru the two sound tutorials:

1. Get the latest Arduino software.
2. Here is the Adafruit Getting Started with Circuit Playground instructions.
3. Circuit Playground Intro
4. Make sure you can see the serial port:

MacBook-Air:~ echou$ ls /dev/cu*
/dev/cu.Bluetooth-Incoming-Port    /dev/cu.usbmodem1411

MacBook-Air:~ echou$ 

5. Setup screenshots:

6. I was able to get to these three tutorials:

- Playground Speaker

- Circuit Playground Library:

- The sound of music:

The only thing that I found for the sound of music tutorial is that extra library is needed besides pitches.h: 

I am really looking forward to tinker with it more, the idea really is to integrate this with Raspberry Pi and Python to make some interesting project! 

Happy Coding!