This Week I Learned - 2017 Week 08

Last week post or the whole series.

Interesting week where your body is giving up on you. Not only adequate and timely sleep is important, it's also crucial for you to keep alert, especially when riding a bike.

#1 Git merge vs. rebase. While I'm almost doing it on daily basis, yet I can can learn a few tricks from time to time. First, is to rebase local commits before commit. One of the mistake I did with another teammate while working on a topic branch is that we `git pull` instead of `git pull --rebase` before committing to the topic branch. Alternatively, we can rebase from remote topic branch before committing. Second, is that I always rebase from `master` branch but always have to resolve a lot of merge conflicts. Instead of rebasing, maybe I should merge instead?
$ git checkout branchX
$ git merge master
$ git rebase -i @{u} # @{u} stands for upstream
$ git push origin branchX

#2 Laura Vanderkam on gaining control of your free time. The key to time management is to focus on the priority. If you don't have time for something, then something is not a priority. If someone willing to pay you 100k for that task, then you will find time to do that task! In short, lacking time is not the actual reason, but you just don't want to do it. You are procrastinating.


How to find those priority items? Start with the end in mind. List down 3 to 5 items. Imagine writing your own performance review for next year for either personal or professional. Foresee what great things you're expecting. Now you've a list of items, how do you manage it?

Friday afternoon (is a low opportunity cost, you don't have to give up a lot). Make three categories, career, relationship, and self. Put two or three items into the three categories and plan these items for the next week. Normally, things aren't always proceed with what we planned.

168 hours. This is equivalent to 24 hours times 7 days. Typical breakdown of the hours spent per week for me are:
  • Work plus travel : 10 hours / day, 50 hours / week
  • Sleep: 8 hours / day, 56 hours / week
  • Total hours left: 168 - 106 = 62 hours / week, 8.8 hours / day
62 hours?! What was I doing all these years?

Having awareness is a key step for moving forward. The question right now is what can you do with those 62 hours? Schedule your items according to these 62 hours. Develop a system accordingly. Easy right? No, we're not busy, Sometimes, we're just plain lazy.

#3 Browsing through MSP430 Q&A in StackExchange's Electronic Engineering forum. Some interesting selected questions.
#4 ARM Cortex-M4. Another interesting microcontrollers which support 32-bit processing capability and quite a few number of brands to choose from. TI MSP432 LaunchPad and STM32 F4 Discovery Kit caught my attention. I prefer the later due to the embedded 2.4" QVGA TFT LCD screen. Will proceed with this microcontrollers once I've done enough with my MSP430.

#5 Dual in-line package (DIP) is one of the packaging types of integrated circuit. When switching different processor from the microcontrollers board, you will need a DIP extraction tool, the professional one. Due to budget constraint, I bought the cheapest I can find, roughly around MYR7.

#6 Buying a TV? The Cnet TV buying guide is best I've read so far. I was surprised to learn some of my generalizations regarding TV were far off. In short, at least 40 inches LED LCD TV with local dimming, full-array LED backlights, and dumb TV. Unfortunately, the recommended brand, TCL is not available in MY. Something interesting and coincident. While going through my photos, I've noticed I've took the same TV model at the same day at two different years. Maybe it's a sign for me to get that TV instead?

This Week I Learned - 2017 Week 07

Last week post or the whole series.

When come to getting new stuff, I really should have a one-item policy. For example, if I'm going to get a new bag, either I sell off the existing bag or donate it out. Otherwise, no point having two bags where you only going to use one. Not only is wasteful, it's also a hassle to store it and clean it as well. Something for me ponder upon when I'm thinking of getting any new stuff.

#1 Six modern keys to wealth. HN user, monodeldiablo describes six possible ways for anyone to accumulate wealth. In essence, you should be competent (both book smart and street smart), persistent (perseverance), and extraordinary lucky (right place, right time, and right people).

Developers are generally book smart but always having difficulties to monetize their projects or technical ability (turn it into a business). The most recent example is JWE, the author and maintainer for GNU Octave is looking for job after 25 years of maintaining the software (I think he is doing a great job since he have been doing it for 25 years but having some financial difficulties these few years). I've made a small contribution to him and being a FSF associate member can help too (just make a note in your monthly contribution). Expect some blog posts on GNU Octave in coming future.

#2 Coroutines in Perl? Use Coro module. More on asynchronous programming in Perl in coming posts. Busy week and I can't seem to allocate any time to look into this. So many things to follow up and so little time.

#3 Prioritize! Prioritize! This reminds me of Stephen Covey's four quadrants approach (similar to The Eisenhower Method) of prioritizing to-do list and time management.

#4 theXeffect subreddit. Fundamental approach to build habits and prevent procrastination. Also known as the "Seinfeld Strategy". Following Bombjoke advice, the steps as follow.
  • Buy a pack of index card. Get the one from Daiso with 5mm grid.
  • Start with Boléro by Maurice Ravel as your background music.
  • Pick a daily habit you want to develop. May I recommend meditation?
  • Write the reasons on why you want to develop the habit on the back of the card.
  • Start now. Do the habit. Once done, mark a big 'X' on the box. If you fail, mark a big 'O'.
  • Continue for 66 days or 2 months. A habit is formed after that period.
The index card by hardcase00 shown below is a good example to illustrate the steps mentioned. Look closely at the card. In order to continue the streak, he have different minimum meditation time ranging from 5 seconds till 15 minutes. Set your goal so low and easy that you don't have any excuses of not doing it. Remember the main purpose is not to focus on how long you can meditate but to develop a habit of daily meditation.



#5 Software developers who started after 35. I have mixed feeling about this. Is good that anyone who are diligent enough can pick up software development skill but Peter Norvig's post on teaching yourself programming in ten years reminded me otherwise. Well, it depends on how you see software development itself. Is it a tool for your to achieve your goal? Or a skill you wish to gain and master? Different people have different motivations.

#6 Is PostgreSQL good enough? (via HN) By far, best written technical post I've read this year. Sad about the font size though. Seriously, who read at such small font size? I've seen quite a few systems which can benefit greatly if they switch to PostgreSQL instead of MySQL. MySQL, being popular and easy to learn doesn't means that it's suitable for all scenarios.There are other requirements where PostgreSQL fits, for example, PostGIS. For a comparison between two to programming languages, MySQL is like dynamic-typed programming language and PostgreSQL is like static-typed programming language. If I'm going to develop any intranet web application which involves critical financial information, my first choice is definitely PostgreSQL.

#7 Goals are for Losers. Passion is Overrated. Provocative opinion but make sense. You need to implement a system or habit to achieve what you want in life. Not passions or goals. Example from the slide is losing 10kg is a goal but eating the right way is a system. To increase the success of what you want in life, use a system approach to acquire more skills which can increase your odd. Summary of this appraoch. Item #4 is also another good example of systematic approach increasing the success rate of what you want to achieve in life.

This Week I Learned - 2017 Week 06

Last week post or the whole series.

Slow week. Just back from holiday and my aging brain is slowly picking up the pending tasks on hand. Not a productive week.

Changing my approach to handle to-do list when comes to own personal project. Have an idea or looking at a procastinated long list, just get something up. Don't care it's not working, even a simple "Hello World!" is good enough. Once it's up, you will have to tendency to do something about it later or in future. It's basically just moving an item from a to-do list to another form of to-do list. Nevertheless, something get started somehow. Best to keep the momentum going.

#1 MSP 430 Competitive Benchmarking (SLAA205C, PDF). Is an old (2009) benchmarking results comparing MSP430 (MSP430F5439) against several other microncontrollers. For more up-to-date results, see the report from EEMBC. CPU is not just the main factor, sometimes, power consumption is an important deciding criteria. Top 5 most efficient microcontrollers according to ULPBench.

#2 The answer is seven. When end result have higher social values over hardworks (you can trace it back to financial reason), do we still care crap about the effort? People always looking for shortcuts in life. Some would prefer to call this being smart and efficient where the goal is to spend minimum efforts to obtain maximum output. Have you encounter student who tried to contest the exam result when he put little efforts? There exists a group of people who are lazy and entitied. Well, laziness is virtue right?

#3 Reverse-Engineering work on the TL-WR703N 150M 802.11n Wi-Fi Router. Interesting works on TL-WR730N which was used as a cheapest embedded GNU/Linux platform (OpenWrt). However, it's quite hard to find this in MY anymore but there is another model which superseded it, TL-MR3020. Alternative choices includes GL-MT300N and Nexx WT3020. I was considering getting one but hold that thought because I'm not sure what to do with it. My Raspberry Pi and Beagleboard still collecting dust.

#4 Ceriatone. Surprising good (from the YouTube reviews) and "affordable" (compare to those established amp makers) guitar tube amp board kits from MY. See TubeDepotTV if you want to find out how to assembly your own guitar tube.

While we're on guitar. Thinking of getting a Squier? Watch Squier Roundup: A look at six Squier guitars from worst to first. Which Squier then? Anything over MYR1000 should be a good choice. To be more specific, skip all Affinity or Bullet series and those made in China.

#5 Box Breathing via HN. The steps is quite straight forward, inhale, stop, exhale, and stop. Just four steps with different duration for these four steps. There are several other breathing techniques as well like The Stimulating Breath4-7-8 Breath, and Breath Counting. I've tried different Android app, so far, Breathe (similar to the Box Breathing site) works for me.

This Week I Learned - 2017 Week 05

Last week post or whole series.

Always an interesting CNY holidays. The flood was not as worse as it seems. The weather is good and the air, seems cleaner. I've managed to get some good rest and deep sleep (more on this in #4).

#1 Canonical have launch Ubuntu tutorials, a step-by-step guideline for setting up development or devops related activities. I was surprise that they started the tutorial using Intel Joule 570x (their answer to IoT?) as the reference hardware. With a price tag of USD 369, I failed to see how this development kit is going to gain any traction when compare to Raspberry Pi. Maybe the target audience is not the Maker community but the industry?

#2 I've bought TI MSP430 development kit to learn more about embedded programming. So far,, the only thing I learned is microcontroller or MCU is "computer on a chip" or also known as System on a chip (SoC). Compare to the Arduino, Raspberry Pi, or Beageboard, it's way more low-level and cheaper. Once I've done with this, the next SoC that I will get is the ESP32, the successor to ever popular ESP8266. For the time being, the next step is introductory write-up on the hardware, setup the development board, testing the serial communication, go through the tutorials, and follow these four things to do with new microcontrollers.

I've noticed that there is this M430F1612 chip (square shape) on the launchpad. Feature-wise, it's similar to MSP430G2553 (rectangular shape) but was used for debugging purpose via JTAG from our computer.

I was thinking on getting more MSP430G2553 and stumbled upon this site, FindChip, which can search through all the popular electronic parts resellers. Note that the search links does contains affiliate links. But is a good way to find available stock and prices in one place.

#3 Are we over-dramatize our life or why people need drama in their life? Sometimes, no news is good news. If you ever complain about boring and simple life, you've been trying to mold your life according to a fairy tale. Follow your dream is such a clichéd pieces of advice. Too abstract and too vague. Be more specific, for example, stay healthy by exercising for 30 minutes on 5 days a week.

#4 Interesting idea on restricting exposure of lights can affect your sleep patterns. I've been living in the city for many years and my exposure and computing usage (you brain is kept active and Melatonin production is delayed) have somehow affecting my sleep cycle and thus my health. Maybe I should switch to something like Philips Hue Bulb? Need to readjust my time and remember, bedroom is for sleeping. Is okay to have TV in the room, just for the sake of white noise. Maybe because there is a healthier life without Internet. Remember, there is way to get you hook on an app or site. Off course, there is antidote to that as well.

#5 "Short answer, It doesn't. Long answer, It does not." Regardless the context of the discussion, the comment is both humourous and fscking brilliant. There is a similar saying as well. "To make it short, is a long story". Maybe we should invest our time in writing? While we on writing, be careful when you use the pharase "duly noted". It usually means "heard and ignored" in a sarcastic way or if you add an extran 'l', it becomes "dully" noted, which means you "barely" acknolwdge. To prevent unnecessary misunderstanding, replace it with "Got it, thanks!" (informal) or "Noted, and thanks!" (format).

MSP430 - Serial Communication Monitoring

Follow up on last post, I supposed to write about usage of MSPDebug but instead we will discuss out capturing the output from the LaunchPad.

The default microcontroller, MSP430G2553 was pre-installed with a demo Temperature Measurement program. Once you've powered up the LaunchPad via USB port, the red and green LED will toggle alternatively. Pressing the P1.3 button (left to the blinking LEDs) will start the measurement. To reset back, press the reset button (right to the blinking LEDs).

Since the only visual indicator (did I mentioned I should have bought the other LaunchPad with embedded LCD?) of the program is through the LEDs, how to we obtain the measurement of the temperature? Basically using mspdebug, stty, and cat (similar post but with more descriptions)
$ mspdebug rf2500 exit
$ stty 2400 -F /dev/ttyACM0
$ cat /dev/ttyACM0

There are other ways to read or sniff raw data from serial ports but this is out of the scope of the discussion here.

Press the P1.3 button to start the measurement. You will obtain a series of characters as shown below. Each character is the numerical representation of the ASCII characters. P indicates 80 °F / 26.67 °C and Q indicates 80 °F / 27.22 °C.
QPQPQQQQQQQPQQQQQQQPQQQQQQPQQQPQQQQQPQQQQQQQQQ

From the output above and `dmesg` output when we plugged in the USB cable to power up the LaunchPad, the device will be assigned to device name of `ttyACM0` instead of `ttyUSB0`. TTY stands for TeleTYpewriter.
[21518.005311] cdc_acm 2-1.2:1.0: No union descriptor, testing for castrated device
[21518.005357] cdc_acm 2-1.2:1.0: ttyACM0: USB ACM device

Why so? Turn out for any USB communication devices like embedded microcontrollers or mobile phones, it's reusing an old control model called Abstract Control Model (ACM) for exchanging raw data. In other words, these devices were identified as modem and communication is done by reusing an old modem communication standard.

To reconfirm that, show all information on `/dev/ttyACM0' using `udevadm` command. For privacy reason, serial number have been replaced with `XXX`.
$ udevadm info /dev/ttyACM0
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/tty/ttyACM0
N: ttyACM0
S: serial/by-id/usb-Texas_Instruments_Texas_Instruments_MSP-FET430UIF_XXX-if00
S: serial/by-path/pci-0000:00:1d.0-usb-0:1.2:1.0
E: DEVLINKS=/dev/serial/by-path/pci-0000:00:1d.0-usb-0:1.2:1.0
/dev/serial/by-id/usb-Texas_Instruments_Texas_Instruments_MSP-FET430UIF_XXX-if00
E: DEVNAME=/dev/ttyACM0
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/tty/ttyACM0
E: ID_BUS=usb
E: ID_MM_CANDIDATE=1
E: ID_MODEL=Texas_Instruments_MSP-FET430UIF
E: ID_MODEL_ENC=Texas\x20Instruments\x20MSP-FET430UIF
E: ID_MODEL_FROM_DATABASE=eZ430 Development Tool
E: ID_MODEL_ID=f432
E: ID_PATH=pci-0000:00:1d.0-usb-0:1.2:1.0
E: ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_2_1_0
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_INTERFACE_FROM_DATABASE=EHCI
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_REVISION=0105
E: ID_SERIAL=Texas_Instruments_Texas_Instruments_MSP-FET430UIF_XXX
E: ID_SERIAL_SHORT=XXX
E: ID_TYPE=generic
E: ID_USB_DRIVER=cdc_acm
E: ID_USB_INTERFACES=:020201:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Texas_Instruments
E: ID_VENDOR_ENC=Texas\x20Instruments
E: ID_VENDOR_FROM_DATABASE=Texas Instruments, Inc.
E: ID_VENDOR_ID=0451
E: MAJOR=166
E: MINOR=0
E: SUBSYSTEM=tty
E: TAGS=:systemd:
E: USEC_INITIALIZED=21528600683

MSP430 - Setting Up LaunchPad Development Board with Ubuntu 16.10

Following up on previous post on MSP430 LaunchPad development kit. We'll proceed with setting the console-based development environment for MSP430 in Ubuntu 16.10. Once this is have been done, we will look into how to interact with MSP430 through MSPDebug via USB interface.

First, find all relevant packages for MSP430.
$ apt-cache search msp430
binutils-msp430 - Binary utilities supporting TI's MSP430 targets
gcc-msp430 - GNU C compiler (cross compiler for MSP430)
gdb-msp430 - The GNU debugger for MSP430
msp430-libc - Standard C library for TI MSP430 development
msp430mcu - Spec files, headers and linker scripts for TI's MSP430 targets
mspdebug - debugging tool for MSP430 microcontrollers

However, notice that the GNU toolchain for MSP430 in the repository is still using the old GCC version of 4.6.3. A newer version of the 5.x toolchain (maintained separately by different vendor) exists but you'll need to install it manually.
$ dpkg -L gcc-msp430 | grep bin | grep gcc-
/usr/bin/msp430-gcc-4.6.3

Install all these packages.
$ apt-cache search msp430 | awk '{print $1}' | xargs sudo apt-get install -y -

Open your console and run `dmesg` command in tail mode.
$ dmesg -w

Plug in and power up the LaunchPad to your USB port. By default, MSP430G2553 will have a demo temperature measurement app installed. Once you've connected through USB, there still be a sequence of LED blinking between red and green color. To stop that, please the P1.3 button to start the Temperature Measurement mode (I've no idea what this, just follow the Quick Guide).

Output of `dmesg` as follows. Note I've removed the serial number for privacy reason.
[ 2407.555756] usb 2-1.2: new full-speed USB device number 6 using ehci-pci
[ 2407.687908] usb 2-1.2: New USB device found, idVendor=0451, idProduct=f432
[ 2407.687913] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2407.687917] usb 2-1.2: Product: Texas Instruments MSP-FET430UIF
[ 2407.687920] usb 2-1.2: Manufacturer: Texas Instruments
[ 2407.687922] usb 2-1.2: SerialNumber: 
[ 2407.695830] cdc_acm 2-1.2:1.0: No union descriptor, testing for castrated device
[ 2407.695858] cdc_acm 2-1.2:1.0: ttyACM0: USB ACM device
[ 2417.806759] hid-generic 0003:0451:F432.0004: usb_submit_urb(ctrl) failed: -1
[ 2417.806843] hid-generic 0003:0451:F432.0004: timeout initializing reports
[ 2417.807991] hid-generic 0003:0451:F432.0004: hiddev0,hidraw0: USB HID v1.01
Device [Texas Instruments Texas Instruments MSP-FET430UIF] on
usb-0000:00:1d.0-1.2/input1

The device, MSP-FET430UIF, is an external USB hardware debugging device but I'm not sure why the embedded USB interface was using the same serial number. Maybe it's using the same chipset? Also, you can probably ignore the error message in the log as we can connect to the board without issue.

You can also check the device id using `lsusb` command.
$ lsusb | grep Tool
Bus 002 Device 009: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool

# More verbose details
$ lsusb -v -d 0451:f432

To connect to the board through the USB interface and MSPDebug program. Run this command and observe that the blinking LEDs have stop. Why we use `rf2500` driver? Turn out that the MSPDebug tool was originally written for EZ430-RF2500. The drive name was confirmed by showing the list of USB devices through MSPDebug. Again, serial number was removed for privacy concern. The bus:device number (002:011) may be different every time you plug in the USB cable.
$ mspdebug --usb-list | grep 2500
    002:011 0451:f432 eZ430-RF2500 [serial: ]

There are several ways to connect to MSP430. First way should be sufficient enough.
$ mspdebug rf2500

# Using bus:device id
$ mspdebug -U 002:011 rf2500

If there are no other errors, you should see below results.
MSPDebug version 0.22 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2013 Daniel Beer 
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Trying to open interface 1 on 007
rf2500: warning: can't detach kernel driver: No data available
Initializing FET...
FET protocol version is 30394216
Set Vcc: 3000 mV
Configured for Spy-Bi-Wire
fet: FET returned error code 4 (Could not find device or device not supported)
fet: command C_IDENT1 failed
Using Olimex identification procedure
Device ID: 0x2553
  Code start address: 0xc000
  Code size         : 16384 byte = 16 kb
  RAM  start address: 0x200
  RAM  end   address: 0x3ff
  RAM  size         : 512 byte = 0 kb
Device: MSP430G2xx3
Number of breakpoints: 2
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data: 25 53

Available commands:
    =           erase       isearch     power       save_raw    simio       
    alias       exit        load        prog        set         step        
    break       fill        load_raw    read        setbreak    sym         
    cgraph      gdb         md          regs        setwatch    verify      
    delbreak    help        mw          reset       setwatch_r  verify_raw  
    dis         hexout      opt         run         setwatch_w  

Available options:
    color                       gdb_loop                    
    enable_bsl_access           gdbc_xfer_size              
    enable_locked_flash_access  iradix                      
    fet_block_size              quiet                       
    gdb_default_port            

Type "help " for more information.
Use the "opt" command ("help opt") to set options.
Press Ctrl+D to quit.
(mspdebug)

When you first execute the MSPDebug program, the temperature measurement app in the MSP430 will halt and waiting for your next command. To resume its execution, just type `run` command and the LEDs will start blinking. (provided you don't activate Temperature Measurement mode).
(mspdebug) run
Running. Press Ctrl+C to interrupt...

More to come as we will explore more and different usage with MSPDebug.