C# is widely used to code devices from phones to computers. This lesson explains how TinyCLR OS is used to bring a similar experience to even smaller circuits, like on the BrainPad.
Prerequisite
This lesson assumes you already know the basics of C# coding and know how to start a C# project.
Under the Hood
C# is a full blown language that is used to code all kinds of devices, from tablets to computers. All devices share the same .NET framework (the libraries), making it possible for the same code to run on all devices. These devices usually run Linux or Windows operating systems.
GHI Electronics TinyCLR OS brings C# and a Micro Framework of .NET to smaller devices that do not run Linux nor Windows. There are multiple chips and modules offered that can be used to build all kinds of IoT devices and embedded systems. BrainPad Pulse, for example, is using the SITCore SC13 chipset.
BrainPad Libraries
We have always added the BrainPad NuGet library to our projects and then used them in our code by adding “using static BrainPad.Controller”. That NuGet automatically pulled in a lot of TinyCLR OS NuGets that handle many things, like pin control and drawing libraries. The source code for the library is found here, https://github.com/brainpad-board/api.
Using the BrainPad library allows for an easier use. In contrast, using TinyCLR OS libraries directly gives the user further control. The TinyCLR Tutorials cover all features and how they can be used.
LED Blinky
We will start with building a simple blink LED program, using TinyCLR OS directly. We first need to know what pin the LED is connected to. The BrainPad hardware repo has the schematic we need. Looking at the schematic, there is only one LED and it is connected to PA8.

Start a project like you did before, but this time do not add the BrainPad NuGet library to your project. Instead, we will search for TinyCLR libraries.
Go to “Manage NuGet packages…”. Do not forget to go to the browse tab and then enter tinyclr in the search bar. You will see a long list of available libraries.

We will select the GPIO library. The TinyCLR docs for GPIO are here if you want to dig further. This code will pull in the GPIO and Threading libraries. The threading libraries are what we need to “Sleep”, which is used instead of Wait() that we used before. Then the code makes an led variable. This variable is a GPIO object that we then set to output. From there we can use an infinite loop to set (write) the pin to high and to low.
There is one thing left, what pin? We know it is pin PA8 from earlier. To use Pins, we need to add the pins NuGet library just like we did with GPIO.

using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Pins;
var led = GpioController.GetDefault().OpenPin(SC13048.GpioPin.PA8);
led.SetDriveMode(GpioPinDriveMode.Output);
while (true) {
led.Write(GpioPinValue.High);
Thread.Sleep(100);
led.Write(GpioPinValue.Low);
Thread.Sleep(100);
}
Other Devices
Blinking an LED directly is more work than when using the BrainPad libraries. While this is true, this code will run on other devices, whereas the BrainPad code will only run on the BrainPad.
There are several devices in the SITCore family that run TinyCLR OS. The FEZ boards, which are Single Board Computers, are good options.

Say we want to use the FEZ Flea and blink its LED. The FEZ Flea has an LED that is connected to PA8, just like on the BrainPad. This means no code changes are necessary.

Same goes for others as well, like FEZ Bit. The difference is that FEZ Bit uses the SC20100 chip instead of the SC13048 chip, and the LED is connected to PE11, requiring a minor code change.
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Pins;
var led = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE11);
led.SetDriveMode(GpioPinDriveMode.Output);
while (true) {
led.Write(GpioPinValue.High);
Thread.Sleep(100);
led.Write(GpioPinValue.Low);
Thread.Sleep(100);
}

What’s Next?
You are now ready to start learning how to read the BrainPad schematic and then control the BrainPad directly using TinyCLR. This will provide you with enough knowledge to start coding other TinyCLR-capable devices in C#, like the SITCore FEZ Single Board Computers.
BrainStorm
What would it take to build a smart coffee maker? We can’t fit a laptop or a tablet inside of it! That is true for most smart devices, from appliances to security systems. Those need a smaller version, something similar to the BrainPad, or the FEZ boards. These IoT smart devices or embedded systems are everywhere and continuing in the future, and developers making them are well-compensated as they require a special kind of knowledge that is different from PC/web developers. A circuit and an “under the hood” understanding are necessary. You are taking your first steps towards developing smart devices.