How to connect to Raspberry Pi 2 with Windows 10 IoT

To connect from your local PC to your Raspberry Pi 2 follow the next steps:

  • Check your Pi IP and/or computer name. (Default computer name is MINWINPC.)
  • Search for PowerShell in Windows and run it with administrative privileges.
  • Type: net start WinRM
  • Type: Set-Item WSMan:\localhost\Client\TrustedHosts -Value MINWINPC
    • You may need to click “Y” to allow this change.
  • Type: Enter-PsSession -ComputerName MINWINPC -Credential MINWINPC\Administrator
  • Enter the password which is: p@ssw0rd

You’re now connected.

For more complete and detailed instructions follow: http://ms-iot.github.io/content/en-US/win10/samples/PowerShell.htm

How to install Windows 10 IoT on Raspberry Pi 2 without Windows 10

For those who want to install Windows 10 IoT but don’t want to install Windows 10 follow the steps below:

  • Insert the SD card where you want to install Windows 10 IoT
  • Format it to FAT32 if needed.
  • Download Windows 10 IoT https://ms-iot.github.io/content/en-US/Downloads.htm
  • Unzip the downloaded ISO and you should see a file called Flash.ffu
  • Download the Windows 10 ADK at the end of this page: https://msdn.microsoft.com/en-us/windows/hardware/dn913721.aspx
  • Search for Windows Imaging and Configuration Designer in your installed programs and run it.
  • Where it says deploy (top left corner right under the title bar) click on the down arrow and select the device where you want to install Windows 10 IoT (either a USB drive where your SD card is or a removable drive if you have one in your computer.)
  • Click on deploy.
  • Select the Flash.ffu file you downloaded before and click open.
  • Click next.
  • Make sure the target disk is correct and click next.
  • Click Flash.

After a few minutes you should have Windows 10 IoT installed in your SD card and you can now try it on your Raspberry Pi 2.

Generating TypeScript documentation generation

There’s a great little tool called TypeDoc that allows us to generate html documentation based in our comments inside our TypeScript files similar to what JavaDoc does. To use this tool follow these steps:

  1. Install nodejs: http://nodejs.org/dist/v0.10.35/node-v0.10.35-x86.msi
  2. Open command line and run nodejs by typing: node
  3. In the nodejs prompt install typedoc by typing: npm install –global typedoc
  4. Type: typedoc -t ES5 –out doc/ references.ts

This will compile all the documentation (classes, namespaces, functions, etc.) that can be referenced by the file references.ts and it will be put under the doc folder in the current directory where that command is ran.

It’s preferred to update your project’s documentation from time to time and TypeDoc has integration with tools like Grunt but if you want this to run after you create a build you can add this command to the post build events list of commands the way I’ve shown in the previous post. For example:

<Exec Command="typedoc -t ES5 --out &quot;$(ProjectDir)/doc/&quot; &quot;$(ProjectDir)/tsDec/references.ts&quot;" />

TypeDoc follows JavaDoc comment tags:

@param <param name> <description>
@returns <description>

Examples:

/**
* This is a function.
* @param arg This is the argument.
* @returns Returns a value.
**/
function func(arg: text): string;

/**
* This is a name.
**/
var name:string = "a name";

You can also use the @preferred tag if you have different comments for the same thing (e.g. a module that is declared in different files and has different comments in both files or an interface and its class implementation) and you want to use a specific comment over the other as TypeDoc will use the first comment that it finds.

Adding pre and post build events in Visual Studio (Windows Store / JavaScript projects)

In Visual Studio you can add pre and post build events, basically these are commands that you can program to run before the build command executes and after it finishes building the solution configuration. To configure these you can easily go to Project -> Properties -> Build Events and write whatever commands you want to run in the Pre and post build events boxes. Of course that this is only true for C# or C++ projects. If you tried to do this in a Windows Store JavaScript application project you most likely noticed that these pre/post build events were missing. Not sure what was the reasoning behind it but I guess the folks at the VS team thought it would be a good idea. Anyway, you can still get access to these by editing you jsproj file and looking for:

<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>

You’ll notice that there’s a whole section that is commented out with this comment:

To modify your build process, add your task inside one of the targets below then uncomment that target and the DisableFastUpToDateCheck PropertyGroup.
Other similar extension points exist, see Microsoft.Common.targets.

So you just need to follow the instructions and add a command inside one or both of the pre/post build event xml nodes. To add a simple copy a file named lib.dll from the output directory to your project directory after building you’d do something like:

<Target Name="AfterBuild">
  <Exec Command="copy &quot;$(OutDir)/lib.dll&quot; &quot;$(ProjectDir)/&quot;" />
</Target>

Note: the &quot; is intentional so that the string gets quoted when it’s used by the copy command.

TypeScript declarations for Player Framework

– Are you programming in JavaScript?
– Yes.
– Are you using TypeScript?
– No.
– Please stop! Do yourself a favour and go learn TypeScript to use it in your project.

I’ve been programming JavaScript for Xbox One projects and since I saw a TypeScript session at Build 2014 that I was completely sold to it.

TypeScript is a language that is a superset of JavaScript compiling the result to plain JavaScript. It makes JavaScript development easier to manage by adding types, classes, modules and interfaces. And because it compiles to JavaScript, you don’t really need to have any TypeScript compiler to run a project.

What if you already have a big JavaScript project?
No problem, you just start slowly converting the code to TypeScript or you can create declarations (similar to a .h file for C/C++ projects) for your utility libraries that work just as well.

My TypeScript contribution to the world is a Player Framework (MMPPF) declaration file available at the DefinitelyTyped GitHub repository.

Enjoy and start using TypeScript!

Raspberry Pi Wifi dropping connection

Started playing with my Raspberry Pi this weekend and noticed that the wifi connection would not stay up for long when connected through SSH. After some digging online I found that the wifi was getting put in sleep mode. Here’s how to fix it:

  • Create a new file named 8192cu.conf at the following location /etc/modprobe.d/8192cu.conf
    sudo nano /etc/modprobe.d/8192cu.conf
  • Write the following command
    options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

    (This makes sure that the power management is turned off thus preventing the dongle from going to sleep mode.)

  • You can go further and ensure that the connection remains up and stable by sending a ping request from your Pi to the router using crontab:
    crontab -e

    (Adds a new entry to crontab.)

  • Enter the following at the end of the file:
    */1 * * * * ping -c 1 192.168.1.2

    (Change the 192.168.1.2 to the IP of your router. The IP of the router can be found by opening a command prompt in Windows and running the ipconfig command and checking the number besides “default gateway“.)

If you don’t have a Edimax wifi dongle you may have to find how to disable the power management for your device.

Source: http://www.xbmchub.com/forums/raspberry-pi-discussion/8037-your-wifi-dongle-dropping-connection-mainly-edimax-ew-7811un.html

How to debug a Windows 8 app upgrade in Visual Studio

Some times it’s useful to debug if your new update breaks anything to users who have the previous version of your app. The process to debug this is not very straightforward but here it is:

– Create a package with first version (right click on the project -> store -> create package)
– Install the package.
– Run app and make sure it saves some user data.
– Make a new package with second version.
– Install package.
– On the Start menu, search for Debuggable Package Manager and then start it.
– A PowerShell window properly configured for the AppxDebug cmdlet appears.
– To enable debugging of an app, you must specify the PackageFullName identifier of the app.
– Type Get-AppxPackage at the PowerShell prompt (to view a list all apps that includes the PackageFullName.)
– At the PowerShell prompt, enter Enable-AppxDebug PackageFullName where PackageFullName is the PackageFullName identifier of the app.
– Run app
– Launch Visual Studio
– Go to Debug -> Attach to process…
– In the list of available processes select the one called WWAHost.exe and with the name of your app in the Title column.

“New” technologies (Discovering the TI world)

Today’s post describes my adventure into the world of TI (Texas Instruments) programming. A little bit out of its time but nevertheless interesting to anyone who likes to learn new things and open their horizons.

My cousin is a few months away of completing his Civil engineering degree and is really interested in TI programming, doing scripts that help him solve problems really fast instead of having to do them manually (most useful in exams). He does all the programming in TI-Basic, a language similar to Basic but specific to TI calculators and like most (if not all) of these interpreted languages, they don’t provide any security if you want to sell your programs. Thus he turned to C programming. Now, C is a whole new beast when compared with this TI-Basic language and it’s much harder to start doing some interesting things without your programs crashing all over the place.

He asked me for help but having no knowledge of this TI-Basic or C tools/libraries/APIs available for these calculators and without access to internet and limited documentation and samples I wasn’t able to get complete the program although I did manage to make half of it. This was a 4 hour marathon that started around 22h30 till 2h30 and I had to admit defeat at the time since I was very tired but I promised to help him to finish the program. I don’t have a TI calculator so I needed to find a way to test it in my PC and fortunately there is an IDE along with an emulator and ROM image available for free on the internet. I’ll list what’s needed to be able to run and the debug C programs for TI calculators because it took me a while to get everything up and running due to incompatible versions of software.

  1. Download and install TIGCC 0.96 beta 8 (Unofficial version)
  2. Download and install TiEmu 3.02a
  3. Download TI Voyage 200 ROM image (my cousin’s model)
  4. Create a project in TIGCC
  5. Run the project (Debug –> Run)
  6. When the TiEmu wizard appears select “You have downloaded a FLASH upgrade on the TI website”
  7. Then select the TI Voyage 200 ROM image you’ve downloaded before.

Voilà! If everything went well you should see the program running on the emulator.

If you want to debug your project, follow these steps:

  1. Project –> Options
  2. Select the “Compilation” tab and then the option “Generate debug information”
  3. Run the project (Debug –> Run)

You should see new windows open if you followed these steps. These are the debug windows that will help you find your bugs.

Here are a few snippets I had to discover here and there through samples / documentation:

/* Retrieves strings passed into the program */
ESI argptr;
int argtype;
char *str;
InitArgPtr (argptr);
while ((argtype = GetArgType (argptr)) != END_TAG)
{
  if (argtype == STR_TAG)
  {
    str = GetStrnArg(argptr);
    printf("%s", str);
  }
  else
    break;
}
/* Get a variable from TI-Basic into C */
SYM_ENTRY *sym_entry = SymFindPtr (SYMSTR ("variableName"), 0);
if (!sym_entry)
  return FALSE;
ESI expr = HToESI(sym_entry->handle);
int argType = GetArgType(expr); /* Retrieves the type of the expression */
long num = GetIntArg(expr); /* Retrieves an integer if the expression holds an integer (positive or negative) */
/* Directly from TIGCC documentation: Run a TI-Basic program or statement from C */
char fname[25];
HANDLE h;
strcpy (fname, name);
strcat (fname, "()");
push_parse_text (fname);
h = HS_popEStack ();
TRY
  NG_execute (h, FALSE);
FINALLY
  HeapFree (h);
ENDFINAL

Including tigcclib.h will make sure that you have all the TI library functions available in C. For the last snippet you need to follow these steps if you have an error regarding push_parse_text function:

  1. go to Project->Options
  2. select the “Compilation” tab
  3. click on “Program Options…”
  4. select the “Operating System” tab
  5. and set the “Minimum AMS Version” as 1.01

Kinect Calibration

This program adjusts Kinect to better see the user, this way the user doesn’t have to move back or forward (unless Kinect’s angles aren’t enough to see the user). I think this is a useful thing to have when you start your Kinect application.

The code is very simple to follow. Use Kinect’s elevation angle to change the Kinect’s “view” and track the user in sight. For each angle count how many joints Kinect is tracking and save that angle as the best if we reach a new maximum number of tracked joints.

void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
	// Get skeleton information
	using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
	{
		if (skeletonFrame != null && m_skeletonData != null)
		{
			skeletonFrame.CopySkeletonDataTo(m_skeletonData);
		}
	}

	m_curTime = m_watch.ElapsedMilliseconds;

	if (m_calibrationState == CalibrateState.GoingDown)
	{
		// If the sensor reach its lowest angle, let's do a full scan from min angle to max angle.
		if (m_curTime >= WaitTime)
		{
			m_watch.Reset();
			m_watch.Start();

			m_bestAngle = m_kinect.MinElevationAngle;
			m_maxNumTracked = 0;

			m_calibrationState = CalibrateState.GoingUp;
			m_kinect.ElevationAngle = m_angles[m_curAngleIndex++];
		}
	}
	else if (m_calibrationState == CalibrateState.GoingUp)
	{
		if (m_curTime >= WaitTimeGoingUp)
		{
			m_watch.Reset();
			m_watch.Start();

			// If we scanned all the angles, lets adjust kinect to the best angle.
			if (m_curAngleIndex > m_angles.Length - 1)
			{
				m_calibrationState = CalibrateState.GoingBest;
				m_kinect.ElevationAngle = m_bestAngle;
				return;
			}

			m_kinect.ElevationAngle = m_angles[m_curAngleIndex++];
		}

		// For each skeleton, count the number of tracked joints and save the best
		// angle when the number of tracked joints is greater than previous values.
		foreach (Skeleton skeleton in m_skeletonData)
		{
			if (skeleton == null)
				continue;

			if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
			{
				//TODO: Improve algorithm by using the number of inferred joints.
				int numTracked = 0;
				int numInferred = 0;
				foreach (Joint joint in skeleton.Joints)
				{
					if (joint.TrackingState == JointTrackingState.Tracked)
						numTracked++;
					else if (joint.TrackingState == JointTrackingState.Inferred)
						numInferred++;
				}

				if (numTracked >= m_maxNumTracked)
				{
					m_maxNumTracked = numTracked;
					m_bestAngle = m_kinect.ElevationAngle;
				}
			}
		}
	}
	else if (m_calibrationState == CalibrateState.GoingBest)
	{
		// Just wait until kinect adjusts itself to match the best angle.
		if (m_curTime >= WaitTime)
		{
			m_watch.Reset();

			m_calibrationState = CalibrateState.Idle;
			m_kinect.SkeletonFrameReady -= KinectSkeletonFrameReady;

			// Reset Kinect state.
			DisableStreams();
			EnableStreams();

			// Signal that we finished the calibration.
			if (OnCalibrationComplete != null)
				OnCalibrationComplete();
		}
	}
}

You may notice two things about the code:

  • First is that I’m using time to control between Kinect movements. The reason for this is that if we try to compare Kinect with the angle we set, we might not get the same value for different reasons (Kinect sensor is not 100% accurate or it couldn’t physically rotate the sensor to that exact angle).
  • And second is the fact that I’m only scanning the skeleton for some angles. I don’t know if this is a Kinect’s limitation or if I did something wrong in the code but I couldn’t track any joints while Kinect was moving. So what I did was move the sensor between some angles and wait there a bit to count the bones for each one of those angles.

Known limitations:

  • it only supports 1 user at this moment;
  • the scanning process is not ideal.

Download:

Kinect Calibration (13Kb)

Visual Studio 2010/11 Utilities

Here is a compilation of very useful utilities for VS 2010 and VS 11.
Note: Utilities with an asterisk (*) beside the name are not available to VS 11 yet.

CLIArgs Made Easy

http://www.ricardosabino.com/?p=214
CLI Args Made Easy (Command Line Arguments Made Easy) is an add-in that allow you to change the command line arguments of the startup project very easily by adding a combobox in the toolbar. It also saves all the arguments you insert for future use.

Debugger Canvas (*)

http://msdn.microsoft.com/en-us/devlabs/debuggercanvas.aspx
Debugger Canvas is a new user experience for the debugger in Visual Studio Ultimate. It pulls together the code you’re exploring onto a single pan-and-zoom display. Visual debugger and multithreading debugging goodies.

Productivity Power Tools (*)

http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
A set of extensions to Visual Studio Professional (and above) which improves developer productivity. Very useful enhanced scrollbar, vertical tabs, quick find files, searchable references and editing tools.

ReSharper

http://www.jetbrains.com/resharper/
With unparalleled support for C#, VB.NET, XAML, JavaScript, XML, HTML, CSS, ASP.NET and ASP.NET MVC, including comprehensive cross-language functionality, ReSharper will help Visual Studio users write better code, easily examine and refactor existing code bases. A must have for anyone who’s doing C# code.

Visual Assist X

http://www.wholetomato.com/
Read, write, navigate, and refactor code FAST with more than 50 productivity-boosting features for C++/C, C#, VB, ASP, JavaScript. A must have for anyone who’s doing C++ code.

VisualHG (*)

http://visualhg.codeplex.com/
Mercurial Source Control Plugin for MS Visual Studio.