Summer project – PowerShell IoT – pt 3. Needles and Pins.

Disclaimer: Pictures and GIFs are crap here. Deal with it.

So, I finaly got my PI working as expected, and was ready to start testing stuff.
Looking at the examples of the PowerShell IoT Github page , Lighting a single led would be a good first test.

In the box of goodies  I initialy had purchased I had five LEDs, 10 different resistors, a breadboard and the cables needed.

Before coding however, there is some knowledge needed:

  1. What is this GPIO thing?
  2. How do I know where to connect the cables on my PI?
  3. What are resistors, how do they work, and which one out of the millions available should I use?

So lets answer them in order.
GPIO is, to put it simple, the easiest way to interact with any kind of external device.
Connect your thing with one cable to any GPIO pin, and the other end to ground (‘GND’).
a GPIO pin has two modes you can set it to: High or Low (‘On/Off’ and ‘Up/Down’ are other terms i’ve stumbled accross here, but thats not what Wikipedia says..)
You can actually read and write data to GPIO, but for our test thats not necessary.
There is much more to GPIO, but for now that is nothing we need to know.

A great command I discovered pretty early on was ‘pinout’
As I understand it, this comes as a part of the package gpiozero, but it seems to be installed by default on Raspbian.
It prints out basic info of your Pi, and the layout of the pins. Please note that they are not in order!
If you connect something the wrong way, bad things might happen.
To make things even more interesting, the WiringPi numbers (that PowerShell IoT uses) is not the same as the numbers on the PI pinout command..
A complete map of numbers can be found here.

So step one would be two cables to the PI. One GPIO and one Gnd.

Next up we need to connect the cables to the breadboard, and a resistor on one side of it.
I googled it, looked at resistor calculator apps and so on, but I dont want google to simply solve my problem, I want to know how to solve it myself.
Nothing made it click until i stumbled on a sign in the store where i bought my things that had the following on it (roughly translated from swedish):

Resistance (kΩ) = ( Source voltage (V) -Voltage drop (V) ) / Power (mA)
If my Source voltage is 12V and i want to connect a LED of 3,6V 20mA I need a resistance of 0,42kΩ

PS:> (12-3.6)/20

Awesome! Learning instead of just repeating what others told me.

Last lesson to learn was that a LED can be connected backwards. It doesn’t work.
After realizing this everything was connected:
Raspberry Pi GPIO18 pin -> Resistance (330Ω) -> LED -> Raspberry PI GND
(This is exactly the same as the example on GitHub)


Fire up pwsh, Import the example LED module and voila!

Once one led is working, connecting more and writing small blink script was as simple as 1-2-3,
And so, my first adventure in to PowerShell IoT ended like this:
Its pronounced 'hyyif'

Thats it for my first venture. Next up will be an accelerometer.
I dont have no code from this available on GitHub, as it is already available in the PowerShell IoT repo.
Lessons learned:
Invest in a real breadboard and a breakout cable / cobbler. Its well worth the few $ it costs and makes it so much easier to connect stuff.

Summer project – PowerShell IoT – pt 2. Installation and prereqs.

Disclaimer: This is just what I did. some of this might actually be unneccesary, irrelevant or just plain weird. If so, let me know, and Ill try and update next time I install Raspbian.

So, to get everything we need up and running,
This is what i ended up with doing.

Download Raspbian and install in using etcher.
A simple guide for this can be found here.

Insert the sd card in the Pi, and boot it up.

After initial setup, start bash (console),  and do the following

  • Expand disk to use all free space on sd card using the following command
sudo raspi-config --expand-rootfs
  • Configure network to use WLAN. This is espacialy needed if you, like me, have a hidden SSID which is not supported in the gui configuration.
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 

I found a guide here of how to configure it, and my conf file ended up looking like this


And after doing this, I did a reboot to get connected to my network.

sudo reboot
  • Next step, Install prereqs for PowerShell and PowerShell IoT.
    According to the PowerShell install instructions, we need libunwind8.
    It seems to be some kind of prereq for CoreCLR 2.0 to work properly as it can generate really weird errors if it is missing.
sudo apt-get install libunwind8
  • Install Powershell. Download the latest build from here
    the file you get is a gziped file, that you can install using the following command.
mkdir ~/powershell
tar -xvf ./Downloads/powershell-6.0.2-linux-arm32.tar.gz -C ~/powershell/

This will install powershell in the ~/powershell folder. Feel free to use any folder you like.

  • Install Mono framework. PowerShell-IoT is based on the unosquare raspberryio framework, and that in turn requires a Mono version greater than 4.6 installed. The following commands will upgrade your installed packages, and install mono for you.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mono-complete
sudo apt-get install dirmngr
# Verify mono version -gt 4.6
mono --version
  • Finaly we install the unosquare raspberyio framework that PowerShell-IoT is based on using nuget. First off, make sure we have nuget installed.
sudo apt-get install nuget
  • Because the nuget version distributed is old, you will get a really weird error when trying to install stuff. Update Nuget exacutable by running the following command.
sudo nuget update -self
  • And finally, we can install raspberryio.
nuget install Unosquare.Raspberry.IO
  • It’s time to enter the world of powershell. Start Powershell using the following command.
sudo WIRINGPI_CODES=1 ~/powershell/pwsh

What is this WIRINGPI_CODES? you ask. a well structured and good explanation can be found on the PowerShell IoT Github page.

Photo from terminal on Raspbian. I have no idea how to do screenshots on Linux. And I know i didnt use the wiringpi variable. Bad Bjompen.

In the next chapter we will finally start to look in to some code and the first project: lighting a Led. ’til then, stay cool in the heatwave.

Summer project – PowerShell IoT – pt 1. The prequel.

Disclaimer, This is jut a prequel, no code is here. If you are just curious about how to get going, read chapter two directly.

Summertime is upon us, and I am in the middle of vacation.
Swedish weather right now is pure terror with forest fires, no rain and I am spending most of the days in the couch just trying to cool down.
What could be a better way than some code?

This spring Microsoft released Powershell IoT,
And there was some presentations of it at PSConfEU.
Since I have a Raspberry Pi, I thought this would be an interesting project to check out, And so, the summer project was decided.

At first I decided something I wanted to automate at home:
I have a crock pot. A cheap one without temp controll and automatic turn off, but it does its job.
If I could get my Pi connected to a temp sensor, using a needle in the food beeing prepared,
My plan was first to set a temerature alarm, but soon I realized I could connect it to a powerswitch,
and automatically turn the Crock Pot to off when meat reaches $temp.
Project one was designed.

Before I started messing with the project itself, I realized I would have to check out how PowerShell IoT works,
so i bought some cheap sensors (temp/humidity and acceleration), a bunch of leds, resistors, cables and a breakout board for design and connections.
All of this added up to a sum of about 20$. IoT stuff is cheap! =)

Good to go, I hit my first hurdle:
I haven’t installed or ran Linux in years.. how do this work?

I started by installing Raspbian, the default Raspbery Pi Operating system.
You can find raspbian here:
I opted for the desktop version. Why? Easier was my guess.

Secondly, We need to put it on a SD card.
I had a 16Gb card spare, so I used that one, connected to my laptop, and installed the image downloaded using Etcher, found here:
All of this is documented fairly well on the Raspbian page, and was very simple.

Throw the SD card in to the Pi, and off we go. I thought.
I started by installing PowerShell for Raspbian. I picked the correct version from,
Downloaded it, followed the instructions, and… nothing worked any more.
I ran out of diskspace.
Turns out the default raspbian image only has a 4 gb partition, the rest of the sd card is left unused.

Reinstall, and try again in chapter two.