Follow me on Twitter @dglover
This is part of the #JulyOT IoT Tech Community series, a collection of blog posts, hands-on-labs, and videos designed to demonstrate and teach developers how to build projects with Azure Internet of Things (IoT) services. Please also follow #JulyOT on Twitter.
This tutorial has been tested with .NET Core applications running on Raspberry Pi OS and Ubuntu 20.04 (including Ubuntu Mate 20.04) for both 32bit (ARM32) and 64bit (ARM64). The projects also include build tasks for Debug and Release configurations.
The source and the samples for this tutorial can be found here.
The examples are found in the samples director of this repo and cover the following .NET Core scenarios.
- Simple hello world: dotnet.core.iot.csharp
- Azure IoT Hub: dotnet.core.iot.csharp.iothub
- .NET Core Web API: dotnet.core.iot.csharp.webapi
- .NET Core Web App: dotnet.core.iot.csharp.webapp
- Azure IoT Hub or IoT Central with DPS (Device Provisioning Service): dotnet.core.iot.csharp.dps.iot
- Azure IoT device twins: dotnet.core.iot.csharp.dps.iot.device-twins
- Azure IoT Hub device twins, and Pi Sense HAT: dotnet.core.iot.csharp.dps.iot.device-twins.sense.hat
- Simple Pi Sense HAT Sample: dotnet.core.iot.csharp.sense.hat 9: F# and .NET Core: dotnet.core.iot.fsharp
Check out the following Raspberry Pi Tips and Tricks to boot Ubuntu from USB3 SSD, how to overclock, enable WiFi, and support for the Raspberry Pi Sense HAT.
The .NET Core IoT Library connects your applications to hardware. In this tutorial you will learn how to:
- Develop a C# .NET Core IoT application from your Linux, macOS or Windows 10 computer,
- Streamline the develop, deploy, and debug process using Visual Studio Code,
- Use the .NET Core IoT library to read the CPU temperature. The CPU temperature will be used to represent the room temperature in this lab scenario,
- Stream temperature telemetry to Azure IoT Hub,
- Control a remote HVAC system.
.Net Core requires an AMR32v7 processor and above, so anything Raspberry Pi 2 or better and you are good to go. Note, Raspberry Pi Zero is an ARM32v6 processor, and is not supported.
The Raspberry Pi 3a Plus is a great device for .NET Core.
I'm super happy with my Raspberry Pi 4B 4GB and 8GB devices seen here dress with a heatsink case.
I like to use Raspberry Pi OS Lite as it takes less resources than the full Raspberry Pi Desktop version and I do all my Raspberry Pi development from my computer.
If you've not set up a Raspberry Pi before then this is a great guide. "Setting up a Headless Pi". Be sure to use the WiFi network as your development computer.
If you are not comfortable setting up Raspberry Pi OS Lite (Headless), then follow the Setting up your Raspberry Pi guide to set up the full Raspberry Pi OS Desktop version.
The Raspberry Pi Sense HAT has builtin sensors and a LED panel. If you have one then great, one of the labs uses this HAT.
It used by millions of developers, it is mature, fast, supports multiple programming languages (C#, F#, and VB.NET), runs on multiple platforms (Linux, macOS, and Windows), and is supported across multiple processor architectures. It is used to build device, cloud, and IoT applications.
There are lots of great resources for learning C#. Check out the following:
- C# official documentation
- C# 101 Series with Scott Hanselman and Kendra Havens
- Full C# Tutorial Path for Beginners and Everyone Else
The Microsoft .NET Core team along with the developer community are building support for IoT scenarios. The .NET Core IoT Library is supported on Linux, and Windows IoT Core, across ARM and Intel processor architectures. See the .NET Core IoT Library Roadmap for more information.
The System.Device.Gpio package supports general-purpose I/O (GPIO) pins, PWM, I2C, SPI and related interfaces for interacting with low-level hardware pins to control hardware sensors, displays and input devices on single-board-computers; Raspberry Pi, BeagleBoard, HummingBoard, ODROID, and other single-board-computers that are supported by Linux and Windows 10 IoT Core.
The .NET Core IoT Repository contains IoT.Device.Bindings, a growing set of community-maintained device bindings for IoT components that you can use with your .NET Core applications. If you can't find what you need then porting your own C/C++ driver libraries to .NET Core and C# is pretty straight forward too.
The drivers in the repository include sample code along with wiring diagrams. For example the BMx280 - Digital Pressure Sensors BMP280/BME280.
- Lab 1: Create your first Raspberry Pi .NET Core C# IoT Application
- Lab 2: Connect a HVAC room environment monitor to Azure IoT Central
- Lab 3: Remote control the room temperature
Have fun and stay safe and be sure to follow us on #JulyOT.