Set up a Raspberry Pi 2
Set up a Raspberry Pi 2
Get your computer ready for the Windows Developer Program for IoT, set up your Raspberry Pi 2 and build your first Windows IoT Core app.
1. Set up your Raspberry Pi 2
2. Write your first app: Hello, Blinky!
In this tutorial, we'll create a simple LED blinking app and connect a LED to your Windows 10 IoT Core device.
This is a headed sample. To better understand what headed mode is and how to configure your device to be headed, follow the instructions here.
Also, be aware that the GPIO APIs are only available on Windows 10 IoT Core, so this sample cannot run on your desktop.
Load the project in Visual Studio
You can find the source code for this sample by downloading a zip of all of our samples here and navigating to the samples-develop\Blinky
. The sample code is available in either C++ or C#, however the documentation here only details the C# variant. Make a copy of the folder on your disk and open the project from Visual Studio.
Connect the LED to your Windows IoT device
You'll need a few components:
A 220 Ω resistor
A breadboard and a couple of connector wires
An LED (any color you like)
Wiring your Raspberry Pi 2
- Connect the shorter leg of the LED to GPIO 5 (pin 29 on the expansion header) on the RPi2.
- Connect the longer leg of the LED to the resistor.
- Connect the other end of the resistor to one of the 3.3V pins on the RPi2.
- Note that the polarity of the LED is important. (This configuration is commonly known as Active Low)
Here is the pinout of the RPi2:
Here is an example of what your breadboard might look like with the circuit assembled:
Deploy Your App
- With the application open in Visual Studio, set the architecture in the toolbar dropdown. If you're building for MinnowBoard Max, select
x86
. If you're building for Raspberry Pi 2 or the DragonBoard, selectARM
.
- Next, in the Visual Studio toolbar, click on the
Local Machine
dropdown and selectRemote Machine
- At this point, Visual Studio will present the Remote Connections dialog. If you previously used Powershell to set a unique name for your device, you can enter it here (in this example, we're using my-device). Otherwise, use the IP address of your Windows IoT Core device. After entering the device name/IP select
Universal (Unencrypted Protocol)
Authentication Mode, then click Select.
- You can verify or modify these values by navigating to the project properties (selectProperties in the Solution Explorer) and choosing the
Debug
tab on the left:
When everything is set up, you should be able to press F5 from Visual Studio. If there are any missing packages that you did not install during setup, Visual Studio may prompt you to acquire those now. The Blinky app will deploy and start on the Windows IoT device, and you should see the LED blink in sync with the simulation on the screen.
Congratulations! You controlled one of the GPIO pins on your Windows IoT device.
Let's look at the code
The code for this sample is pretty simple. We use a timer, and each time the 'Tick' event is called, we flip the state of the LED.
Timer Code
Here is how you set up the timer in C#:
public MainPage()
{
// ...
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += Timer_Tick;
InitGPIO();
if (pin != null)
{
timer.Start();
}
// ...
}
private void Timer_Tick(object sender, object e)
{
if (pinValue == GpioPinValue.High)
{
pinValue = GpioPinValue.Low;
pin.Write(pinValue);
LED.Fill = redBrush;
}
else
{
pinValue = GpioPinValue.High;
pin.Write(pinValue);
LED.Fill = grayBrush;
}
}
Initialize the GPIO Pin
To drive the GPIO pin, first we need to initialize it. Here is the C# code (notice how we leverage the new WinRT classes in the Windows.Devices.Gpio namespace):
Let's break this down a little
- First, we use
GpioController.GetDefault()
to get the GPIO controller. - If the device does not have a GPIO controller, this function will return
null
. - Then we attempt to open the pin by calling
GpioController.OpenPin()
with theLED_PIN
value. - Once we have the
pin
, we set it to be off (High) by default using theGpioPin.Write()
function. - We also set the
pin
to run in output mode using theGpioPin.SetDriveMode()
function.
using Windows.Devices.Gpio;
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
pin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
pin = gpio.OpenPin(LED_PIN);
pinValue = GpioPinValue.High;
pin.Write(pinValue);
pin.SetDriveMode(GpioPinDriveMode.Output);
GpioStatus.Text = "GPIO pin initialized correctly.";
}
Modify the state of the GPIO pin
Once we have access to the GpioOutputPin
instance, it's trivial to change the state of the pin to turn the LED on or off.
To turn the LED on, simply write the value GpioPinValue.Low
to the pin:
pin.Write(GpioPinValue.Low);
and of course, write GpioPinValue.High
to turn the LED off:
pin.Write(GpioPinValue.High);
My RaspberryPI 2b
Start here: https://www.raspberrypi.org/
LogOn:
Linux | Win10 | |
username | pi | Administrator |
password | raspberry |
p@ssw0rd / frtfrt |
link |
startx
sudo apt-get install ...
SW Images:
http://downloads.raspberrypi.org/NOOBS/images/
Remote control: vnc, Bitvise, ...
http://www.realvnc.com/download/viewer/
Projects:
Basic Temperature Logging To The Internet With Raspberry Pi
http://www.raspberrypi-spy.co.uk/2015/06/basic-temperature-logging-to-the-internet-with-raspberry-pi/
Raspberry Pi 1- Wire Digital Thermometer Sensor (DS18B20)
http://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor/
Touchscreen:
http://diyhacking.com/raspberry-pi-touchscreen-lcd-tutorial/
https://www.raspberrypi.org/forums/viewtopic.php?f=45&t=119088
ThingBox
http://thethingbox.io/docs/Flash_Pi_image.html
Blynk
https://play.google.com/store/apps/details?id=cc.blynk
Domoticz
https://www.domoticz.com/wiki/Domoticz_Wiki_Manual