There has been some nice progress on the pure c# library for the EV3 Lego Mindstorm Brick from Lego and the BrickPi3 from Dexter Industries. The BrickPi is great as it adds loads of extra processing power and more importantly memory for the EV3 kit using a Raspberry Pi.
The library is for both Xamarin.IoT and Android Things. As soon as it’s ready I’ll post the source to GitHub. If there is interest, I can also spend some time and port the Android Things implementation to Java or Kotlin for Android Studio.
The ultimate plan is to use this in a Lego based robot as a play project, but the experimentation will form basis of an actual larger artificial intelligence project. It will also be hooked up to Azure IoT for the telemetry.
I was inspired enough to dust off one of my older projects which included .NET MF and the Xamarin Monkey Robotics project. I then decided to consolidate and rearrange it with some of the newer stuff I’m playing with in the “Iot” space. It’s also an example of how Visual Studio can handle projects of all types, held together and fully “debuggable” within one solution. This seems like a good time to do this especially with the recent talks at the Xamarin User Groups in Cape Town (http://explorationspace.co.za/2017/07/20/cross-platform-iot-at-ctxug/) and Johannesburg (http://explorationspace.co.za/2017/07/12/cross-platform-iot-at-gxugsa/) on the topic.
I do still have to port all this to Visual Studio 15.3 preview 3 so I can have Xamarin Iot working in the solution as well.
Still a lot of on the list to do today, so I’ll end off here.
Last night was the Cross Platform Iot Session at CTXUG in Cape Town. The turnout was absolutely amazing! Thank you to all for coming it was a really fun evening!
Roger Weiss from Aliens kicked off with an overview of Windows 10 Iot Core and a few demos. These demos featured some awesome use of Microsoft Cognitive services and also some nifty voice controlled home automation.
It was then my turn. Unfortunately Chris van Wyk couldn’t make it this evening. 🙁
The session featured
Visual Micro for Visual Studio
Visual Studio Code with Arduino Extension which is now Open Source.
Xamarin Forms and Xamarin.Android with Android Things 0.41 Preview
The new Xamarin Iot preview for Linux based devices
Last night was the Cross Iot Session at GXUGSA in Johannesburg. It’s always fun presenting all the Iot toys, but also what can actually be done with Xamarin and the rest of the Microsoft tooling.
It’s also not always clear that you can basically do anything you want with Xamarin, so always nice and exciting to showcase it outside the usual phone type scenarios.
The session featured
Visual Micro for Visual Studio
Visual Studio Code with Arduino Extension which is now Open Source.
Xamarin Forms and Xamarin.Android with Android Things 0.4 Preview
The new Xamarin Iot preview for Linux based devices
Last week I pushed the Xamarin version of the Google Contrib drivers to Nuget. I’ve now added a sample project, to illustrate how it all works. The sample also includes the use of Azure Iot Hubs.
A great test of the contrib drivers is Pimoroni’s Rainbow Hat. https://shop.pimoroni.com/products/rainbow-hat-for-android-things The Rainbow HAT brings together a lot of the components mentioned above on one board. It’s provided with the Android Things Starter Kit so it’s a very good place to start. The first sample I’ve added here focus’s on this specific HAT.
The sample added is based on the google Weather Station sample. It has one difference, it uses Azure Iot Hubs for cloud messaging.
Sample Functionality
Temperature Monitoring
Pressure Monitoring
Push Button (A) to swap display from Temperature and Pressure on the board display
Native UI for RaspberryPi to display weather based on air pressure
Telemetry sent from Android Things Device to Azure via Azure Iot Hubs
Message support from Azure to Android Things Device.
To uses the Iot hub in the sample, the DeviceId, DeviceKey and HostName of an Azure Iot hub will need to be provided. I will do a post specific on Iot Hubs to provide more detail on this in subsequent blog posts. These variables are set in the MainActivity.
private bool _useHubs = true; // Set this to true to use Azure Iot Hubs
_weatherDevice.DeviceId = "<Add Azure Iot Hub Device Id Here>";
_weatherDevice.DeviceKey = "<Add Azure Iot Hub Device Key Here>";
_weatherDevice.HostName = "<Add Azure Iot Hub Hostname Here>";
I’m in the process of creating more samples of the rest of the contrib library. I’m also packaging more third-party drivers from around the community into reusable Nuget packages for Android Things with Xamarin.
I’m also having a lot of fun at the moment with a version of these drivers, built from scratch to work with Xamarin Iot. We can then have these components (and Rainbow HAT) working on Linux devices which will of course be awesome!
Android Things has GPIO callbacks which are triggered on certain trigger events. This is great for event handling. I’ve added a sample to Xamarin bindings which illustrates this by means of a Grove PIR (Passive InfraRed) sensor much like what’s in your home alarm system. If we use that in conjunction with a buzzer, you have a primitive alarm system.
Gpio callbacks are classes implemented inheriting from the abstract class Gpio Callback. This call back is triggered on certain trigger types. This are set on the gpio pin with the settriggertype method.
EDGE_NONE: No interrupt events. This is the default value.
EDGE_RISING: Interrupt on a transition from low to high
EDGE_FALLING: Interrupt on a transition from high to low
EDGE_BOTH: Interrupt on all state transitions
public class AlarmCallback : Com.Google.Android.Things.Pio.GpioCallback
{
public Gpio BuzzerPin { get; set; }
public override bool OnGpioEdge(Gpio p0)
{
if (p0.Value)
{
if (!BuzzerPin.Value)
{
BuzzerPin.Value = true;
Thread.Sleep(1000);
BuzzerPin.Value = false;
}
}
return true;
}
public override void OnGpioError(Gpio p0, int p1)
{
Log.Info("Alarmcallback", "Error");
}
}
The class has two methods to override. OnGpioEdge and OnGpioError. The OnGpioEdge method is called on a trigger event. The OnGpioError is called on an error.
This class is registered on the actual input gpio pin.
_callback = new AlarmCallback {BuzzerPin = _buzzerGpio};
_alarm1Gpio.RegisterGpioCallback(_callback);
Android Things is Google’s new IOT Android based platform. In essence it’s a slightly altered version of Android which can run on Iot type devices such as the Intel Edison and the Raspberry Pi3.
“Android Things lets you build professional, mass-market products on a trusted platform, without previous knowledge of embedded system design.”
Personally I’m not yet too impressed with Android Things. It is still very new and very raw and is lacking a lot of what you’d expect from an Iot platform. However, having finally a standard Android implementation officially from Google running on these devices has to be a good thing. The platform should just get better from here.
Running in Visual Studio using Xamarin
Of course being Android, Android Things works with Xamarin too. Using Xamarin will also be a benefit for all those awesome cross platform benefits it offers, like sharing your Iot code with your backend services, Android, Ios, Windows Phone, Windows 10, OSX, XBox and whatever other devices you’d like to be supporting in your solution.
Getting the devices to appear in Visual Studio is exactly as you’d expect. The devices will use the standard Android Debugging Bridge (ADB). Plugging in an Intel Edison via USB will be reflected as “Unknown Iot_Edison”. You can obviously also use the network debugging features of ADB. eg. adb connect <ip address> The device will then also be detected in Visual Studio. A Raspberry Pi will appear as “Unknown iot_rpi3”.
Using Xamarin is very simple. All we need to do is bind to the Android Things API Jar to be able to make use of all the features provided by the Android Things SDK. At this moment in time there isn’t an official release Nuget package from Xamarin to do this. It is however very simple to do this yourself. In this sample (and I’ve shared the code on GitHub) I’m binding to the new Dev Preview 2 API for Android Things (androidthings-0.2-devpreview.jar). Once the binding project is referenced from your Android Things project, everything will work as expected. Just of course with the benefit of using C# and not Java!
I’ve created some samples based on the Standard Android Things Samples
No Iot sample and demo is complete without a blinking LED. This sample is a conversion of the Android Things sample.
Simple UI
This sample is a simple illustration of using a UI on an Android Things device. It also illustrates GPIO pins and how to set the high/low values of the pins.