Monday, November 30, 2015

GPIO pins allocation under windows 10 IOT build on Raspberry PI

The Windows 10 IOT documentation https://ms-iot.github.io/
indicates that only the following pins are available 4,5,6,12,13,16,17,18,19,20,21,22,23,24,25,26,27 for GPIO.

If you wonder why so many pins are not usable as GPIO. This is because
  • GPIO 2, and 3 are reserved for I2C interface
  • GPIO 7,8,9,10,11 are reserved for SPIO interface
  • GPIO 14,15 are reserved for UART interface.


Note that 35 and 47 are also available but they drive LEDs soldered on the board and not pins on the GPIO connector.

If you are still using Windows10 IOT build 10.0.10240 you must know that for some unknown reasons the Raspberry PI GPIO pins 17, 19, 20, 21 are not usable. I think this is a very good reason to update to build 10.0.10556.

 

Program To list all the available GPIOs

 
I have developed a small program that list all the available GPIOs.
 
The XAML is the following
 

<Page
x:Class="CountGPIO.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CountGPIO"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="TextblockOutput" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Page>

 
 
And the C# code associated
 

using System;
using Windows.Devices.Gpio;
using Windows.UI.Xaml.Controls;
namespace CountGPIO
{
  public sealed partial class MainPage : Page

  {
    private GpioController gpio;

    public MainPage()
    {
    this.InitializeComponent();

    gpio = GpioController.GetDefault();
    this.TextblockOutput.Text = "List of Supported GPIO pins:" +  Environment.NewLine;
    for (int port = 0; port < 64; port++)
     {
     try

      {
      gpio.OpenPin(port);
      this.TextblockOutput.Text += "GPIO Pin: " + port.ToString() + " is OK" + Environment.NewLine;

      }
     catch (Exception)

      { }
     }
    }
  }
}
 


Sunday, November 15, 2015

How to use a PC To Connect a Raspberry PI to a WIFI network


Introduction

 
The problem is the following : I am using have a standard Raspberry PI (i.e. without any WIFI interface) at a location where the only way to access the Internet is the WIFI. Is it possible to use my portable PC running Windows as a router to connect the Raspberry PI to the Internet ?
 
 
 
The answer is YES and it is very easy
 
 

Step1: Activate ICS

Activate the ICS on the WIFI connection of the Windows computer. The ICS (Internet Connection Sharing) allows other computers to use the WIFI connection of the Windows computer.
This is done in the network control panel (you may reach it by using the command)
control ncpa.cpl
Then select properties on the WIFI network
 
 



And then activate the sharing of the the WIFI connection

Once this is done any computer connected to the PC ethernet port shall receive via DHCP an IP address in the 192.168.137.X network (note the PC is located at 192.168.137.1)
 
 
 
 

Step2 Connect the Raspberry PI to the PC


Connect the Raspberry PI with a standard Ethernet cable equipped with standard RJ45 connectors). You don't even need a crossed cable because the Raspberry PI support auto MDI-X (which means that the Raspberry PI will detect that a crossed cable is needed and automatically preform the « cross » internally) .
 
Now everything is done and your raspberry PI can access the Internet. But If You don't have keyboard and display connected to it you need to know which IP address the Windows PC DHCP has given to it.
 

Step 3 retrieve the Raspberry PI IP address

The simplest way to obtain this address is to query the ARP table. Start a Windows command prompt (if you don't know how to do it just press WINDOWS+R and type cmp ENTER)
and type the following command
arp -a -N 192.168.137.1
This will give you a reply that looks like that
 
In this list you see that the Rasberry PI has been granted the addres 192.168.137.55
 
Note : the 192,168,137,255, all the 224.x.x.x and the 239.255.255.250 addresses are all multicast addresses (we don't care about them)
You can now connect to you Rasberry PI via SSH and from the Raspberry PI communicate with the Internet.