Friday, July 31, 2015

VLC Command Line Change Container MKV to MP4

I wanted to change a bunch of MKVs to MP4, while doing a direct stream copy. VLC can do this with the GUI, but there was a lot of stuff to remux, so I decided to do it with the VLC CLI instead. Here is the bash one-liner I used:

 for f in *.mkv; do vlc "$f" --sout="#std{access=file,mux=mp4,dst='${f/%mkv/mp4}'}" vlc://quit; done;

I used the following sites for reference:

Monday, March 9, 2015

Ubuntu Reinstall nVidia Drivers

This is here just to remind myself.

Every time there is a linux kernel update, it will clobber the nVidia drivers and they will need to be recompiled and reinstalled.

After kernel update do:
sudo apt-get install nvidia-331-updates --reinstall

This should blow away and reinstall everything, and redo the kernel mod for the nvidia drivers.

Tuesday, December 9, 2014

MPL3115A2 sensor with Raspberry Pi

Here is a short write up on using the MPL3115A2 with the Raspberry Pi.

The MPL3115A2 is a precision pressure and temperature sensor. I bought mine from SparkFun.

Installing I2C for Pi

Getting started you'll have to install the I2C packages for Raspberry Pi, and enable them.
From a Raspberry Pi terminal use the following commands:
sudo apt-get install python-smbus
sudo apt-get install i2c-tools

Enable the modules by adding them to /etc/modules
sudo nano /etc/modules
and add the following two lines:

Remove the modules from the blacklist by commenting them out "add # to the front"
sudo nano /etc/modprobe.d/raspi-blacklist.conf
Make sure the spi and i2c lines are commented out:
#blacklist spi-bcm2708
#blacklist i2c-bcm2708

Lastly, the MPL3115A2 requires a proper repeated start command in it's I2C communication. Raspberry Pi doesn't do this out of the box, but there is a kernel module that can be enabled to make it perform repeated start correctly. Run the following commands to enable repeated start on the Pi:
sudo su -
echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined
More details about the repeated start problem can be found here:

Connecting the Sensor

Next solder some headers to the breakout and connect it to the Raspberry Pi. You'll want to use the following Raspberry Pi GPIO pinout:

Python I2C Code

Finally, we need to write some code to read data from the sensor. The following is an example Python program to use smbus to read data from the sensor.
from smbus import SMBus
import time

# Special Chars
deg = u'\N{DEGREE SIGN}'

# I2C Constants
ADDR = 0x60
CTRL_REG1 = 0x26
PT_DATA_CFG = 0x13
bus = SMBus(1)

who_am_i = bus.read_byte_data(ADDR, 0x0C)
print hex(who_am_i)
if who_am_i != 0xc4:
    print "Device not active."

# Set oversample rate to 128
setting = bus.read_byte_data(ADDR, CTRL_REG1)
newSetting = setting | 0x38
bus.write_byte_data(ADDR, CTRL_REG1, newSetting)

# Enable event flags
bus.write_byte_data(ADDR, PT_DATA_CFG, 0x07)

# Toggel One Shot
setting = bus.read_byte_data(ADDR, CTRL_REG1)
if (setting & 0x02) == 0:
    bus.write_byte_data(ADDR, CTRL_REG1, (setting | 0x02))

# Read sensor data
print "Waiting for data..."
status = bus.read_byte_data(ADDR,0x00)
while (status & 0x08) == 0:
    #print bin(status)
    status = bus.read_byte_data(ADDR,0x00)

print "Reading sensor data..."
p_data = bus.read_i2c_block_data(ADDR,0x01,3)
t_data = bus.read_i2c_block_data(ADDR,0x04,2)
status = bus.read_byte_data(ADDR,0x00)
print "status: "+bin(status)

p_msb = p_data[0]
p_csb = p_data[1]
p_lsb = p_data[2]
t_msb = t_data[0]
t_lsb = t_data[1]

pressure = (p_msb << 10) | (p_csb << 2) | (p_lsb >> 6)
p_decimal = ((p_lsb & 0x30) >> 4)/4.0

celsius = t_msb + (t_lsb >> 4)/16.0
fahrenheit = (celsius * 9)/5 + 32

print "Pressure and Temperature at "+time.strftime('%m/%d/%Y %H:%M:%S%z')
print str(pressure+p_decimal)+" Pa"
print str(celsius)+deg+"C"
print str(fahrenheit)+deg+"F"

Sample Output:
pi@raspberrypi ~ $ sudo python
Waiting for data...
Reading sensor data...
status: 0b0
Pressure and Temperature at 12/10/2014 04:51:56+0000
99838.75 Pa

More Resources

MPL3115A2 Datasheet:

Arduino code for reference:

Thursday, June 27, 2013

Making room on your SSD

Here is a quick and dirty method for making more room on your Solid State Drive (SSD). Most people have a SSD for the OS and a Hard Disk Drive (HDD) for data. Since the "Program Files" folders in Windows have a big footprint, and not every program needs the extra speed of running on SSD, we can move the files to the HDD and link them from the SSD. This is transparent to the programs, but your SSD should see some space savings. Let's get started!

First we need to "backup" the data from our "Program Files" folders. We can use xcopy to do this:

xcopy /S /H "C:\Program Files" "E:\Program Files"
It will ask you if "Program Files" is a file or a directory. Press 'D' to select directory.
If you have a 64-bit system, then do the same thing for "Program Files (x86)".

Now all we need to do is set up hard links on the folders in "Program Files" to point to the folder on the HDD instead. You can pick what programs you want to do this to. I leave my games on the SSD (because I like the performance), and other programs like Skype get moved to the HDD.

To link a folder all you have to do is delete the current one (be certain you've backed it up properly!) and create a hard link with the same name:

rmdir /S /Q "C:\Program Files\Adobe"
mklink /J "C:\Program Files\Adobe" "E:\Program Files\Adobe"

Related reading: LifeHacker - Move the Users Dir in Win 7

Other copy options include windows robocopy:
robocopy /S /Z /R:0 /W:2 /V /MT:4 "D:\Program Files" "E:\Program Files"
or a Linux Live CD:
cp -ar <source> <dest>