Getting started with PowerShell (Core) on Raspbian (Raspberry Pi) – Light up a Led

Around a year ago, I started to investigate about new usages for my Raspberry Pi 3b . I love the Raspberry, a tiny, credit-card-sized SBC capable of running different operating systems, but most of the projects I found that seemed interesting were highly complex (or at least seemed) and used python, a language that I’m not familiar with. Around the same time, I also started to hear a lot about PowerShell (or maybe it caught my attention because I’ve started to use it at my work for simple stuff), as a scripting language mainly used (as far as I knew) to automate tasks.

PowerShell Core – A shell for every ecosystem.

That’s right, PowerShell Core (PowerShell from now on) is cross-platform and works on Windows, Linux and MacOS). This is a HUGE step for people that are used to PowerShell but weren’t able to do so outside of Windows. Sure, there are still limitations, but the progress has been huge.

PowerShell.IoT – The module

This module is the main reason why I decided to try PowerShell on Raspberry. A couple of weeks before the release of this module, I had bought a Scroll pHAT (that seems to be no longer for sale) as an incentive to learn python. But after seeing a tweet about the release of this module everything changed! I got hooked with the possibility of controlling LEDs, sensors and much more with only PowerShell!

One of the first things that I’ve done was to create a module to control the scroll pHAT that I’ve bought (guess what – I ended up not learning python), which got featured on Pimoroni’s GitHub repo!

Enough story, show me what I’ve came to see!

Alright, if that’s what you want, that’s what you will get. Let’s start by getting PowerShell. Microsoft’s documentation here is really good. I will leave the link here if you prefer to check their instructions, but I will help you and show the instructions, so that you don’t need to jump back and forth:

  1. Start by downloading the version that you want to your Raspberry. Remember that you can copy the link and use wget to download the file. (I always download the latest previews, this way I can test and report if I spot something) – Here’s the link. You want to look for something like powershell-x.x.x-linux-arm32.tar.gz (by the time of this writing, latest version was powershell-6.2.0-rc.1-linux-arm32.tar.gz)
  2. Install the pre-requisites sudo apt-get install libunwind8
  3. Create a folder where you want to store the powershell required files. For example  mkdir ~/powershell
  4. Unpack the tar file and copy the content to the folder you previously created. tar -xvf ./powershell-YOUR_VERSION-linux-arm32.tar.gz -C ~/powershell
  5. Congratulations, you can now launch PowerShell by going to the folder where the content is and type pwsh (according to this example, that is ​~/powershell/pwsh).
  6. Optionally, you can create a symlink so that you don’t have to specify the full path: sudo ln -s ~/powershell/pwsh /usr/bin/pwsh

Alright, so with this you have PowerShell ready to do whatever magic you want!

PowerShell.IoT module – Installation and usage

If you are already familiar with modules on PowerShell, this one is not different. The only “exception” here is that we will launch and use PowerShell with higher privileges (sudo). Why is that, you might be asking? Well, because this module interacts with GPIO, I2C, SPI, which require higher privileges.

So, start by launching PowerShell with higher privileges – sudo pwsh. After that, all we need to do is Install-Module Microsoft.PowerShell.IoT. This will ask if you trust the source, you can say you do. In case you have any doubts, the project is hosted on GitHub and it’s open source.

After it installs, you can import it with Import-Module Microsoft.PowerShell.IoT. Remember that you can always get help with Get-Command -Module Microsoft.PowerShell.IoT and Get-Help <Cmdlet name>.

Get-GpioPin Set-GpioPin command

The IoT module uses the WiringPi GPIO pinout. For further reference, you can use this website in order to easily know the pin numbers.

The gpio is fairly simple to understand: each pin has a number and a value (it also has PullUp/PullDown but we will not talk about that part). The pin number varies according to different implementations (remember that in this case, the one that’s used is the WiringPi one), and the value can either be high or lowHigh corresponds to 3.3V and Low to 0V. That said, the cmdlets related to gpio are really simple to understand and use:

  • Get-GpioPin – you pass an Id or an array of Ids, and it returns the pin’s value;
  • Set-GpioPin – you pass an Id or an array of Ids and that’s the value that you want to set.

Putting this into practice

To apply what we’ve just learned, let’s do the “hello world” of the hardware: lighting up a LED. There are several types of LEDs, but they usually have one “leg” shorter than the other. The shorter leg is the one that’s connected to GROUND (cathode), the other is the one that receives the voltage (anode). If your LED is like mine, they have the same size. Other way to know which is the anode and the cathode is by looking to what’s inside the LED. As the following image will show you, you have 2 parts, one bigger than the other.


The smaller part is the anode (on the right), and the other is the cathode. With this in mind, we can now try it. To see if your led is working, you can connect it directly to the 5V pin, if it lights up, everything is good, otherwise, make sure you didn’t swap the wires.


(My setup, green  connected to cathode (GROUND), grey is connected to anode (3.3V)

Let’s go ahead and plug it to the pin 8 (remember that’s for WiringPi, which means it’s the second pin on the second row). The LED automatically lighted up, didn’t it?! That’s because that pin is set to the High value by default. Let’s confirm this by doing Get-GpioPin -Id 8. Now it’s time to turn it off, by simply doing Set-GpioPin -Id 8 -Value Low. Let’s setup a loop that will turn it on and of each second.

Here’s the result:

This pretty much it. Pretty simple right? Now that you can control the gpio, spread wings to your imagination and go do awesome stuff! Want a suggestion? What about : “If the LED is on, send a notification to my machine

What’s the output? Something like this:

Want to know how that can be achieved? I’ll leave that to another blog post.

Screenshot from 2019-03-18 00-45-15.png

Other projects

If you want to check up on what I’m up to, feel free to visit my GitHub page. Everything that I do is open source.

Also, if you need any help or simply want to discuss/show me something, hit me up on twitter!

Thank you for reading!


I’ll be speaking at … PowerShell VG!

This year has been a blast so far. Ever since I’ve started to attend to local user groups, I’ve always been interested on what speakers bring and the way they show their content. Because I was only getting started on this [programming] world, I’ve always felt that there was nothing that I could bring to the community that would be useful/new. As the time passed, I’ve began to feel more comfortable and I’ve noticed that sometimes you don’t even need to bring something new, it can be as simple as a different approach to a problem.

PowerShell Core was release for the RaspberryPi. That was the BOOM for me. I saw not only something new and challenging, but also a possibility to bring some input to the community. So I’ve decided to explore its possibilities and see where it would take me. I’ve learned a lot about PowerShell and the Linux ecoSystem in that process (and still learning 🙂 ). During that time, I’ve also challenged myself (and was challenged) to start doing presentations, so I did! I’ve always been greeted with a warm welcome and never felt pressured about presenting (let’s not talk about those 5 minutes before the presentation where it seems that everything can go wrong 🙂 ).

All of this to say…

… that as the title states, I’ll be presenting on the PowerShell Virtual Group! This is a great achievement for me, since this is a well-known place where you can share and learn. I’ll be presenting about PowerShell Core and RaspberryPi! This session will be full of examples, walkthroughs, shiny LEDs, sensors and so on!

LEDs…sensors… PowerShell… what?!

I know right?! That does seem a little bit off…

If that’s something that you have interest, or even if you are just curious about it, tune in next Wednesday, September 26th! Register here!

A special thanks

To Aaron Nelson (b|t) for his availability and patience to organize this (and always fix the damn time zone errors :D)!

This is … PsPowerHour!

In case you are not aware of the awesome community news, let me tell you one: as you might know, in some conferences there’s something called “Lightning talks”, which consist in talks around 10 minutes (hence lightning), where the presenter presents you ANYTHING related to a subject. It can be slides, code, demo or even just talk about something. With this idea in mind, Warren F. (b|t) and Michael T Lombardi (t) decided to take the same approach… but virtually. Which means that ANYONE can assist and talk!

They have been doing an awesome job organizing it and the first session kicks tomorrow, Aug 21st @ 6pm EST.

Where can you see it?

It will be streamed on Youtube. But be sure to check out the PsPowerHour repository for more information.

With that said…

I’m really happy to say that I’ll be talking on the day this whole thing starts 😀 and I bet that you already know about what…

yep that’s right. I’ll have less than 10 minutes to give an idea to the community about what can you do with the PowerShell and a RaspberryPi (and other hardware).


See you there!


TUGA IT conference – First as Staff, now as Speaker!

I’m very proud to announce that I’ll be speaking on one of the biggest Portuguese technological conference, the TUGA IT . This conference gathers speakers from all around the world, who are passionate about what they do and want to share their experiences/knowledge.

This has an ever bigger meaning for me, since it was the first conference organization that I’ve attended other than the local User Groups. Highly motivated by Cláudio (b|t), last year I’ve helped the organization, and this year I’m a speaker. It was also where I was able to meet awesome folks such as Jaap (b|t) and Rob (b|t).

For me this is a HUGE achievement, both personally and professionally.

“But what will you be talking about?”

I will talk about using PowerShell on a RaspberryPi. I’ll share my experience with, what have I done with it, how, and what I expect to do. If you like PowerShell but don’t know RaspberryPi or the other way around, this might be a good session to attend to.

“Oh, that sound awesome but I can’t attend to it.”

If you just thought something like this don’t worry. You can always check out a previous presentation here, although I will probably have something new (but the core is still the same) 🙂 .

And as if speaking sessions weren’t enough, they also have WORKSHOPS

Registrations are open!

If you are not still convinced, check out the speakers list, and the schedule!

If you have interest (and you should!) I have good news for you: you can grab your seat today !

Final words…

I’m really excited about this event and I really hope that if you attend to the event, you sure to say hello!



I’ve shared Internet connection between Linux and headless RaspberryPi but can’t SSH


1 – Follow the first 4 steps described here;

1.1 – Additionally, just to be sure, ignore IPV6 on IPV6 tab;

2 – Instead of trying to ssh into the given network ( in my case), run

cat /var/lib/misc/dnsmasq.leases

connect to the given IP address.


I’ll be presenting using my raspberry and my laptop, so I have the need to be able to connect to it (raspberry) via SSH. In order to be able to do that, I need to have both devices on the same network. Connecting the laptop to the network is usually easy, since you are given an username and password and in the worst case you need to open the browser and login into some page.

As for the raspberry, that’s another story. I could carry around a keyboard, mouse and monitor just to establish the connection, but even that could not be enough… what if I have the lite version (just the console)? If the network provider want me to login into a webpage, that will be an headache.

After a quick word with André Melancia (t) he mentioned that Internet Connection Sharing (ICS) was easy since Windows XP. But… I’m using Linux 😀

A quick search on Google yielded this thread . Although many people there said that the first 4 steps were enough, for me they weren’t, because even so I wasn’t able to connect (you will understand why later).

Let’s see what we got

After following those steps, I’ve ended with the same output as the person who posted it


Ok, cool! Let’s test it.


We got it! Now I can SSH into my Pi…


Hum… I’m sure that I’ve entered the correct credentials (it is a fresh install, so in raspbian the user will always be pi and the password raspberry). What’s wrong?


Nmap (used for network descovery) even says that it allows SSH and it’s open…

Re-reading that thread, someone posts something that he states as relevant which is basically to ignore ipv6. Still no luck.

So what’s wrong?

Well, turns out I was targeting the wrong address. At first, everything was matching:

  • I was able to ping;
  • I was able to SSH into it, but I was getting permission denied;


How did you know that you were targeting the wrong address?

Digging a little bit more, I found this post , which suggests a command to run that will give us the correct address:

cat /var/lib/misc/dnsmasq.leases


which yielded something like:

1526507253 xx:xx:xx:xx:xx:xx raspberrypi xx:xx:xx:xx:xx:xx


It worked!


So what’s dnsmasq and how did it help finding/solving the problem?

According to  the official website and I quote:

Dnsmasq provides network infrastructure for small networks: DNS, DHCP, router advertisement and network boot

In resume, this tool scans the smaller network (in this case the ethernet one that only have one device) and gives us the ip address.

Do you have another methods? Please share!

Thanks for reading!

Simple Tip: How do I open explorer on current path in Powershell? Explore different ways

See what I did there? “Explore different ways”… “explorer”… no? ok…

The post today is really simple. I fell like I’m failing by not writing content more often, but there’s not always time and/or subject.

The things that might look pretty simple and obvious for some, is not for the others, and that’s what happened to me today.

On my working environment, I’ve set my Powershell window to always start on a specific folder (which is my Workspace folder). That is cool because I’ve a script that I usually need to make some modifications and run, so setting the path to point there was a good start. Even after that, I’ve always ended up opening explorer and navigating to the desired folder (mainly because I need to use other files from there). So today I asked myself “Why don’t I simply open Powershell and open the explorer from there?”

Failed attempts

  • explorer – First attempt, simply type explorer. That launched explorer (as expected, but not on the current directory);
  • Get-Location | explorer – Also launched explorer, but not on the desired directory;
  • explorer Get-Location – This one made plenty of sense to me, although it opened the “My documents” folder instead of the current directory. Funny enough, I was only missing the brackets between the CmdLet – we will see it ahead
  • . – Because I know that the dot “represents” the current directory, I thought that simply typing that would launch the explorer (but why would it ?)

(Funny, because I’ve tried with  explorer  and  but never occurred me to try explorer .)

So, what does work?

Like almost everything in this area, there are many ways to achieve this. After getting help from people @ SQL Server Community Slack (t), here are some options:

  • start .
  • start -filepath “C:\some\path” (start is an alias for start-process)
  • explorer $path (Thank you Gareth (t|b) for all the above)
  • explorer .
  • explorer (Get-Location) (the one that I almost got right).
  • invoke-item . (or even simpler ii .) (Thank you Andy (t|b) )

Fred (t|b) also mentioned a module called PSUtil  that has some functions for explorer (besides many others). I also recommend you to read his post about some things that this module contains.


The purpose of this post was not only (or mainly) to show how to open the current directory on the explorer, but to show that there are many commands and combinations that can be performed to achieve the same purpose. This can also be applied for other cases

Getting started with SignalR Alpha for ASP.NET Core 2.0! – My experience

This looks like a long post but it has lots of code and little explanations since SignalR is on an early stage. Stick until the end 🙂

Previously I’ve overheard about SignalR, which I’ve been told that it’s a library to allow “real time” communication with multiple web clients. My first thought was that it was some kind of message broker (like I’ve used before the RabbitMQ and MQTT protocol), but after a little reading and talking, I found out it’s much easier than that.

A couple of weeks ago, Microsoft announced SignalR (Alpha) for ASP.NET Core 2.0. This blog post is a really good entry point, and if you read it, you get a pretty straightforward idea of what’s new/different, like:

  • JavaScript/TypeScript Client
  • Support for Binary Protocols and Custom Protocols
  • Streaming
  • Scale-out

And many more things like “What’s Changed” (which I won’t cover because like I said, I’ve had zero experience with SignalR before this Alpha) and even the other topics won’t be covered here.

So what will you be talking about?

I will give you my approach/idea about how to work with SignalR in a scenario which is similar to my job’s needs.

My test case scenario and examples

First of all, keep in mind that I will not cover the javascript client, only the C# one. I’ll probably have the necessity to create an implementation on javascript, when I need to I’ll blog about it :).

In order to show a similar “real world” scenario, I’ll build a simple application simulating the following :

There are different type of workers on their workspace and they want to communicate between them. There are 3 groups:

  • Cool employees
  • Way Cooler Employees
  • Bosses

For obvious reasons, they only want to talk to the others on the same group (Cool employees with cool employees, etc etc).

To simulate this interaction we will have another application that simply perform 3 actions, according to correspondent button pressed:

  • C  key pressed – send message only to Cool employees
  • W key pressed – send message only to Way cooler employees
  • B  key pressed – send message only to Bosses

OK… so how does all of this work? Let’s try to visualize it:

Resuming: we want to have employees that belong to the “Cool Employees” group, others to the “Way Cooler Employees” group and the bosses that belong to the “Bosses”group. Have you noticed that I’ve been repeating the word “Groups”? It was with a purpose. With this post, I will show you how can you send messages to specific groups. But before jumping into it, let’s start from the beginning.


On the previous image, everything points to a hub, but what’s a hub? A hub is a “kind of” point-of-access (or bridge if you prefer) between the caller and the receiver(s). Having a quick look at this class:

It gives us access to properties like the Context, Clients and Groups, which we will explore next.

Starting with clients

The default Clients property is of the type IHubClients

This one, also implements an IHubClients interface, which has the following methods:

Since in this case T is of the type IClientProxy, we will have the following available:

We are getting somewhere! With this we already know that when sending a message, we will send it to a group and our code will be something like:

But how do we register a client on a group? We’ve seen that the hub has a Groups property.


Consists on a property of the type IGroupManager, which has two methods:

This is it! We already have the knowledge on how to register a client on a group and how to send a message to a specific group. Let’s implement our Hub. We need to allow each connecting client to register himself on a group, in order to receive only the messages that he wants to, and we need to create the method that will say “ok, I will send this information to this group”.

The Hub implementation

Please note that the Groups.AddAsync() method requires a connectionId, which in this case is the connectionId of the client that is registering himself on a group. To get the connectionId for the current client, we can use the Context.ConnectionId property.

A little parenthesis:

I had a doubt on how the groups were created: did I need to create if before trying to add a connection to it, or would it try to add and if the group did not exist it would be created? Due to the amazing community, it was easy to get some of my questions answered pretty quickly, and it even generated a little and quick discussion. Share your questions/ideas with the community, join ASP.NET slack. Here’s an example of what I’m talking about:

slack.pngAnother awesome “feature” of the open source, is that we can have things like this. Gurgen developed an android client library for SignalR that according to him:

“At the moment, it works only by websockets transport, but later I will add all other transports
The plus is that, this is only implementation of .net core signal r for android”


Ok, so before we can run our code and see things happening, there are two things that we need to add to the Startup.cs

With the routes.MapHub(“entryPoint”) we are specifying that in order to connect to the hub, the route must be ourAddress/entryPoint (in my case it was http://localhost:52846/entryPoint)

Testing what we’ve just created

In order to test this, we need to have a total of three projects: the project with the hub, one to simulate our clients (employees and bosses), and other to send the messages. We already know that our clients must register themselves on a group so that they can receive the desired messages.

In order to simulate the referred scenarios, on the project that simulates the employees and bosses, I decided to create Tasks, in which each simulate a client application, by connecting to the Hub, register itself on a group and setting the callback. Afterwards it just stays on a forever loop. With this in mind, some of the code that I will show isn’t obviously the best approach, but it’s just to make the simulation easier/doable.

Connect to the hub and prepare to receive the messages (employees and bosses project)

The connection itself is pretty straightforward, all we need to do is create a HubConnection object and call the StartAsync method. When the connection is established, we register ourselves on a group, by calling the RegisterConnectionOnGroup method that we created on the hub. For last, we set the callback, defining what should be done when we receive a message. Let’s have a look on the code that simulates a “Cool Employee” client:

NOTE: As I just mentioned above, the connection.StartAsync().GetAwaiter().GetResult() should not be done like that for obvious reasons (it will not be async at all), but honestly I couldn’t figure out how could I await that call inside a Task, because since I’m using Task.Factory.StartNew(new Action(…)) I can’t set the await on the method, because it would change the signature, hence it wouldn’t be an Action. In this case it is just to ensure that we invoke the RegisterConnectionOnGroup only after the connection is established. Do you know how to solve this? Please PM me or even better, comment down below!

The MessageSender project

This application just sits on a forever loop after establishing connection to the hub (via the same HubConnection logic) and “implements” the logic that I previously referred:

  • Send a message only to the bosses? Press B
  • Send a message only to the Cool Employees? Press C
  • Send a message only to the Way Cooler Employees? Press W

With this, we can finally test what was developed. First launch the project that has the Hub (SignalR project, in this case the EmployeeSignalR), then the SignalRClient1 which will create the various clients referred, and finally the MessageSender. Place the SignalRClient1 and MessageSenderconsoles side by side, and press the desired key on the MessageSender‘s console. See the magic happening!

Here’s an example:


For me, this was a whole new world since I’ve never really had contact with SignalR until I had created this project. Obviously, there might be some things that I said that are not exactly like i said, but as I stated at the beginning I tried to “give you my approach/idea about how to work with SignalR in a scenario which is similar to my job’s need”. Since none of us know everything, if you spot a mistake or you have another approach, please let me know!

A special thanks to David Fowler (b | t) for his help and quick replies to my questions! And also, thanks to Gurgen for his intervention on the explanation and his availability to talk to me about signalR.

You can download the full example from my github repo

Thank you very much for reading