Keyes 18B20 Temperature Sensor and Raspberry Pi 2

I recently got my hands on a Keyes 18b20 temperature sensor.

These are great little modules but it took awhile to figure out how to get it connected to the raspberry pi and the necessary Raspberry pi config.txt changes.

 

Keyes 18B20 Pinout

Here are the Pinouts for the Module.

Keyes

The Module already has the 4.8 K pull-up resistor you’d typically have to wire  up along with the DS18b20 so the only components you need are the Keyes module and a Raspberry pi.

The Module also has an LED that will flash when the temperature is read.

Raspberry Pi2 GPIO Header

The 18B20 is a 1 wire device so the Signal pin needs to be connected to Pin #7 GPIO04 (GPIO_GCLK).

For the GND we’ll use Pin# 06.

For the 5v we’ll pick Pin #02

gpio header

 

Wiring it up

To wire it all up.

Keyes GND -> Pin# 06.
Keyes 5V -> Pin #02
Keyes Signal -> Pin #07

wired up

 

Config the Pi w1-gpio

By default the w1-gpio is not enabled. You need to enable w1-gpio in the config.txt or the Pi will not recognize any 1 wire devices.

To enable w1-gpio open the config.txt file in nano with the command:

sudo nano /boot/config.txt

Add the following line to the config.txt file.

dtoverlay=w1-gpio

save and exit nano.

Reboot your Pi.

 

Reading the Temperature Sensor

To read from the temperature sensor you need to find the device Id.  Each 1-Wire device is identified by with a unique id consisting of a family code and identifier. The Temperature sensors will have a family code of 0x28.

Go to the directory that contains the 1 wire devices and list the contents.

cd /sys/bus/w1/devices
ls

There will be a list of the devices on the 1 wire bus.. You will see something like 28-031465885cff.

To read the data you’ll read the contents of the w1_slave file substituting the ID of your device for 28-031465885cff.

cat “/sys/bus/w1/devices/28-031465885cff/w1_slave

The temperature will be at the second line of the file in the form
t=22300

Value is in Celcius*1000 so in the above example it would be 22.3 degrees celcius.

 

Sharepoint App Parts Disappearing

Symptom:

You install a Sharepoint Application and add an App Part. Everything is working great but a few weeks later your App Parts have disappeared. The Sharepoint Application is still installed and shows no errors.

Cause:

This can happen if a previous install on a Sharepoint Application was uninstalled. Uninstalling the Sharepoint Application will put it in the Recycle bin where 30 days (or somewhere in that range) later the recycle will kick in and do final cleanup.

So if you’ve installed the same Sharepoint Application and Added an App Part between those 30 days when the recycle bin does its final cleanup the App Part will disappear.

Repro:

Microsoft Sharepoint Application X installed.
Uninstall Application X (this will put it in the recycle bin).
Install Application X
Add an App Part to the Page
Wait for 30 days or go to the Recycle bin and remove the previously uninstalled Application X instance (Also make sure to check the Secondary recycle bin and clear that out)

Workaround:

To workaround this issue if you Uninstall a Sharepoint Application you think you may install again within 30 days go to the Recycle bin and remove all instances of the application.

 

 

 

Convert TroopMaster Data to SqlLite

Troopmaster is used by Scout Troops for keeping track of Scouts advancement, outings, personal information, etc.

Troopmaster provides a way for exporting some of the data but doesn’t provide a way to export Outing information. Outing information is also lost when a Scout is archived.

tm2sqllite is a utility that converts Troopmaster data to a sqllite database.

Once the data is converted to sqllite then data can be queried with sql statements and sqlLite utilities.

Click tm2sqllite to go to the download page.

 

 

Run Windows 10 from a USB Thumb Drive

By setting up Windows on a bootable external USB flash Thumb drive you have a way to boot into a computer that made need maintenance,  if you want to easily switch between different Operating system copies, try out an OS or application without needing to install on your computer hard drive, or just for fun.

There are directions on the web including in this post Run Windows from an external USB drive that work for setting up a USB external hard drive or if you can get the removable bit set on a flash drive. However these don’t work for a USB Flash such as a Thumb drive.

I’ve done some experimentation with the Windows 10 technical preview and have success getting a USB Flash drive to work which I will walk you through. The instructions below are close to how you would setup an external USB hard drive but there are some tweaks and some remaining issues hopefully Microsoft will have a better story when Windows 10 ships.

The underlying issues with USB Thumb drives are that Microsoft doesn’t support partitions for removable media. Until Microsoft supports partitions or provides better ways to setup the boot information I’d recommend continue to use a USB Hard Drive instead of a Thumb drive.

 PreReqs

Windows 10 Technical preview .ISO or DVD.
USB 2.0 or higher Flash drive with at least 15 Gb or storage capacity

Formatting the Flash Drive

We need to setup the Flash Drive as NTFS. Windows 10 doesn’t work going to a Fat32 drive due to file lengths and ExFat isn’t bootable.  To complicate things even more since the Bootable isn’t set Windows won’t recognize multiple partitions.

We’ll use DiskPart to format the disk and set an active partition.

Run DiskPart as administrator. Its important on to make sure you run as administrator or you’ll get all sorts of errors when running commands.

My typical method of running DiskPart is to first launch a cmd prompt as admin and then type DiskPart.

In Disk Part type

DISKPART> list disk

The disks along with your USB drive should be displayed. Be careful pick the right disk and remember the disk number.

Select the Disk with the select disk # command substituting your disk number for the #

DISKPART> Select Disk #

Run the following commands to erase the disk, create a primary partition, mark the primary partition as active, format it and then assign it a letter.

DISKPART> Clean
DISKPART> Create Partition Primary
DISKPART> Select Partition 1
DISKPART> Active
DISKPART> Format FS=ntfs  quick
DISKPART> Assign

Make note of the assigned drive letter. The examples in the next steps will use e: but you will need to substitute in the letter assigned to your drive.

Find the install.wim file

On the Windows DVD the install.wim is at sources\install.wim. If you have the .iso and windows 8 you can mount the .iso as a disk and use that. I found its faster if I mount the .iso and then copy the install.wim file to my local disk.

For our purposes lets say we have the install.wim at location f:\sources\install.wim

Pick the image index to install

The install.wim can come with multiple images but for Window 10 Technical we pick index 1.  For Windows Server there are multiple choices. To see the list of available image you can run the following command from and administrator cmd prompt (Always use administrator on Windows 8).

dism /get-wiminfo /wimfile:f:\sources\install.wim

Install the image

You now have all the information you need. Just Dism the image you want to the disk.

The following command will  apply the image index 1 on disk f: to the disk on E:

dism /apply-image /imagefile:f:\sources\install.wim /index:1 /applydir:e:\

This can take awhile so be patient.

Mark the drive as bootable

Next you  need to set the disk to be bootable. This is where I haven’t figured out a nice way to get this to work just doing a single bcdboot command.

What does work is to bcdboot both the %windir% boot information as well as the boot information just copied to the USB Flash Drive. More information on bcdboot can be found at https://technet.microsoft.com/en-us/library/dd744347(v=ws.10).aspx

For the boot files we need to specify BIOS since we are going to an NTFS partition.

Back at your administrator cmd prompt run both of these commands substituting the drive letter of your flash drive for e:

%windir%\system32\bcdboot  e:\windows /s e: /f BIOS

 Boot from your USB

Restart your computer to boot from the USB.

Computers have different ways to select to boot off USB, Bios, F9, Esc, F12 that goes beyond the scope of this post. You’ll need to figure out the steps for your specific computer. You may also have to turn off Secure Boot in the BIOS for it to recognize the USB Thumb drive. I also found it worked better if I made the USB drive first in the boot order.

What can go wrong at this point?

Sometimes things go fine from here but other times the Drive isn’t being recognized or you get a message the boot file is missing.

If the USB Flash doesn’t boot properly or gives an error:

  • Shut down
  • Remove the USB Flash Drive
  • Start the computer off of the hard drive.
  • Once booted put in the flash Drive and make note of the drive letter it mounted on.
  • Run the bcdboot command for the drive letter. If e: again then run

%windir%\system32\bcdboot  e:\windows /s e: /f BIOS

  • Restart from the USB

If you run bcdboot multiple times the boot menu will come up. Pick the top one since that is the most recent.

Run through the Windows Setup

Let Windows go through its setup process. If a reboot is necessary make sure on reboot you select the option to boot off the USB Flash Drive.

I hit some issue with what appeared to be time outs when using a slower USB Thumb Drive that it would reboot and restart setup. If this happens you can keep trying but you probably need a faster USB Thumb drive.

Clean up the extra boot image ( Optional)

Congratulations. You have now booted and ran Windows off of a USB Flash drive.

If you had to do bcdboot multiple times when you reboot you can just continue to makethe selection of which Windows to load in when launching the Flash drive or clean up the extra boot entries. I’m not sure why you don’t need them anymore other than there must be some extra Windows goo that marks it to boot off the same partition as selected to Boot From (which would be the ideal way to mark it in the first place).

You can remove the extra boot choices with BCDEdit.

Other Issues

I’ve been running off of a USB Flash to try out Windows 10 since I want to wait to upgrade my main hard drive until Windows 10 is released. While doing this I have found the following issues

Fragile – I found that the USB Flash drive seems to be easily corruptible if you don’t let the computer shut down COMPLETELY before pulling the flash drive or if Windows Hangs and leaves you with the only choice to power down.

Complains about Page Swapfile. Ignoring the error seems to be okay. I’ll update the reported issues when Windows 10 is released.

Run Windows from an external USB drive

By setting up Windows on a bootable external USB drive you have a way to boot into a computer that made need maintenance or if you want to easily switch between different Operating system copies.

USB Drive vs. Flash

The directions below will work with a USB Drive but will only work with a USB Flash Drive if you can get the Removable bit turned off.

Windows doesn’t like USB Flash Thumb Drives to boot off of if the Removeable bit is set. The Removable bit on the USB causes windows to not allow partitions and hangs Windows on boot from the USB.

Supposedly bootit will flip a Lexar to remove the removable bit but I never got a USB Flash Thumb Drive to work.

Note: I’ve tried USB Flash on Windows 10 preview with some limited success.

Windows Versions

Not all versions of Windows can be used. I’ve gotten the Following to work.

Windows 8
Windows Server 2012
Windows 10
Windows Server 2016 Technical Preview 4

Formatting the Disk

We’ll use DiskPart to format the disk and set an active partition.

Run DiskPart as administrator. Its important on Windows 8 to make sure you run as administrator.

In Disk type

DISKPART> list disk

The disks along with your USB drive should be displayed. Be careful pick the right disk and remember the disk number.

Select the Disk with the select disk # command substituting your disk number for the #

DISKPART> Select Disk #

Run the following commands to erase the disk, create a primary partition, mark the primary partition as active, format it and then assign it a letter.

DISKPART> Clean
DISKPART> Create Partition Primary
DISKPART> Select Partition 1
DISKPART> Active
DISKPART> Format FS=ntfs  quick
DISKPART> Assign

Make note of the assigned drive letter. The examples in the next steps will use e: but you will need to substitute in the letter assigned to your drive.

Find the install.wim file

On the Windows DVD the install.wim is at sources\install.wim. If you have the .iso and windows 8 you can mount the .iso as a disk and use that. I found its faster if I mount the .iso and then copy the install.wim file to my local disk.

For our purposes lets say we have the install.wim at location f:\sources\install.wim

Pick the image index to install

The install.wim can contain multiple images. For Windows 8 there is only one but for Windows Server there are multiple choices. To see the list of available image you can run the following command from and administrator cmd prompt (Always use administrator on Windows 8).

dism /get-wiminfo /wimfile:f:\sources\install.wim

Install the image

You now have all the information you need. Just Dism the image you want to the disk.

The following command will  apply the image index 1 on disk f: to the disk on E:

dism /apply-image /imagefile:f:\sources\install.wim /index:1 /applydir:e:\

This can take awhile so be patient.

Mark the drive as bootable

Next you  need to set the boot on the new e:. In your administrator command prompt run bcdboot.

bcdboot e:\Windows /s e: /f ALL

 Boot from your USB

Computers have different ways to select to boot off USB, Bios, Esc, F12 that goes beyond the scope of this post. You’ll need to figure out the steps for your specific computer.

Couple of hot tips:

Sometimes my USB drives don’t start fast enough to show in the boot menu. If this happens press ctl-alt-delete to restart the machine for it to show up.

Depending on your BIOS when using Windows 8 and higher you may have to specify from Windows Advanced Settings to reboot and give you a chance to choose what disk to boot off of.

 

Remote desktop to Azure Virtual Machine running Ubuntu

A Linux server on Azure is a great combination but there are some extra steps to be able to remote desktop into a Linux box. This article will walk through how to get remote desktop setup on an Ubuntu Linux server.

The following prerequisites are assumed.

PreReq:
Azure account
PuTTY for SSH connection
Create an Azure Virtual machine
Set up endpoints on an Azure virtual machine

Step 1: Create an Ubuntu Server Virtual Machine

Click in the portal to create a new Virtual Machine from Gallery.

In the “Choose an Image” select an Ubuntu Server. If you choose 12.0 you can use the desktop that comes with Ubuntu. If you choose a higher version you will need to do Step 5 to install a desktop.

Fill in the Virtual machine information making sure to enable SSH either through certificate or password. I’d recommend using a password if you are still getting familiar with SSH

Walk through the rest of the Virtual Machine wizard and create the Virtual machine.

Step 2: SSH Connect to machine using Putty

To configure the Azure machine SSH connect to it with Putty using the DNS name of your Virtual Machine and SSH password that you set during Virtual machine creation.

Step 3: Setup the Root password

This step is not strictly required for Remote desktop setup but you should always setup a root password on a new Linux box.

In your Putty window run the following command and set a password for root.

sudo passwd root

Step 4: Configure Remote desktop with SSH

To configure the Azure machine SSH connect to it with Putty using the DNS name of your Virtual Machine and SSH password that you set during Virtual machine creation.

xrdp requires tightvncserver so tightvncserver should be installed first.

In your Putty window run the following commands:
sudo apt-get install tightvncserver
sudo apt-get install xrdp

Step 5: Install a Desktop

To use a Remote Desktop, we actually need to have a Desktop. If you’ve installed Ubuntu 12.0 you can skip this step. For Ubuntu 14 Gnome 3 will crash when connecting with remote services.

The desktops I’ve found to work well are MATE and Xfce4. My personal preference is MATE but I’d recommend you try out both and see which one you like.

There is also an extra step that we need to set which desktop to use when the xrdp service connection is made.

For MATE run the following commands in PUTTY:

sudo apt-get install mate
echo “mate-session” > ~/.xsession
chmod +x ~/.xsession
sudo systemctl restart xrdp.service

To try out Xfce4 run these commands in PUTTY:

sudo apt-get install xfce4-session
echo “startxfce4” > ~/.xsession
chmod +x ~/.xsession
sudo systemctl restart xrdp.service

Step 6: Add the RPD endpoint

In the Azure Portal add an RPD endpoint for your Virtual machine.

Step 7: Make the Connection

All that’s left is to Remote Desktop to the machine.

If you are on a Windows machine start the Remote Desktop Connection Exe.

WindowsKey – r to bring run the “Run As Dialog”
Type in “mstc” and then click the OK button.
The Remote Desktop window will open. Type in the DNS name of the virtual machine and connect using the same username and password used for the SSH (Putty) connection in step2.

Enjoy.