Connecting a Pimoroni Environmental Monitor to IoT Central

The Pimoroni Environmental monitor is an amazing piece of hardware. I recently purchased a few to monitor air quality around the house. https://shop.pimoroni.com/products/enviro?variant=31155658457171

Packed into the HAT for a Raspberry Pi Zero you will find:

  • BME280 temperature, pressure, humidity sensor
  • LTR-559 light and proximity sensor
  • MICS6814 analog gas sensor 
  • ADS1015 analog to digital converter (ADC)
  • MEMS microphone
  • 0.96″ colour LCD (160×80)
  • Connector for particulate matter (PM) sensor (available separately)
  • Pimoroni breakout-compatible pin header
Device Template

Device Definition json file is in the github repository along with the source code. This can be imported into Azure IoT Central and the views generated.

environ.py
IoT Central Dashboard

Source code: https://github.com/apead/Pimoroni-Env-Monitor-IoT-Central

Product Information: https://shop.pimoroni.com/products/enviro?variant=31155658457171

Where to buy?

https://www.pishop.co.za/store/enviro–for-raspberry-pi

Cross Platform Iot at CTXUG

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

Azure Iot Hubs

 

Devices wise 

 

Raspberry Pi 3

Intel Edison

Raspberry Pi Zero W

Latte Panda and Arduino Leonardo

MXChip Azure Kit

Devices everywhere! Latte Panda, Pi With Android Things. NexDock

 

The awesome new MXCHIP Azure Iot kit (Arduino)

 

The presentation can be found here:  https://github.com/apead/XUGSA/tree/master/19072017

Android Things Weather Station Sample with Azure Iot Hubs:    https://github.com/apead/Xamarin-AndroidThings-Contrib

Cross Platform Generic Xamarin Forms sample that ran on Phone, Android Things and Windows 10 Iot (I didn’t demo this, but it works too):   https://github.com/apead/XUGSABuildAutomation

 

Xamarin Android Things Nuget:  https://www.nuget.org/packages/Xamarin.Android.Things/0.4.0-devpreview

 

Xamarin Android Things Contrib Drivers:  https://www.nuget.org/packages/Xamarin.AndroidThings.Contrib.RainbowHat/0.40.0-beta

 

Getting Started with Xamarin Iot:   http://explorationspace.co.za/2017/06/21/xamarin-iot-comes-to-visual-studio-2017-on-windows/

 

MXChip Azure Kit:   https://microsoft.github.io/azure-iot-developer-kit/

 

Android Things Starter Kit with Rainbow Hat:   https://shop.pimoroni.com/products/rainbow-hat-for-android-things

 

Rainbow HAT

 

There’s a Xamagon!

 

Interesting VR Stuff happening in Aliens office

Android Things GPIO Callbacks

Following the blog post to get you up and running with Android Things, Visual Studio and Xamarin.  http://explorationspace.co.za/2017/02/26/using-xamarin-and-visual-studio-with-android-things/

 

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.

 

The source can be found here:   https://github.com/apead/Xamarin-Android-Things

 

Intel Edison with PIR and Buzzer

 

 

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);

 

Happy Android Things development with Xamarin!

 

Using Xamarin and Visual Studio with Android Things

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

 

Samples:   https://github.com/apead/Xamarin-Android-Things

Blink Led

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.

 

Simple UI Android Things Sample

 

 

 

Learning Resources:

 

SDK Samples:  https://developer.android.com/things/sdk/samples.html

How to install Android Things on your Device:   https://developer.android.com/things/preview/index.html

A great article on the basics of electronics and hardware:  https://riggaroo.co.za/android-things-hardware-basics/

 

Happy Android Things Development with Xamarin!

Windows 10 IOT Remote Display Experience

With Microsoft Build 2016 complete, there are so many things to be looking at and trying out.   One of the more useful features for me right now is the new remoting functionality in Windows 10 IoT Insider Preview 10.0.14295.   I have this running on a Raspberry Pi 3 and I am busy with some work using an array of sensor telemetry.  Being able to see what is happening remotely make life far easier when building Universal Apps.

To configure this is very simple.    There is a new menu option added to the administration console called “Remote”.  This is accessible via the URL:  http://[ipaddress of pi]:8080.   If you haven’t changed the password the login should be:  “Administrator” and “p@ssw0rd”

IoT Remoting

Enable the Windows IoT Remote Server by ticking the box presented.

 

To access the Raspberry Pi remotely you need a client.   This is available in the Windows Store either by following the provided link, or just by searching for “Windows IoT” in the store.  https://www.microsoft.com/store/apps/9nblggh5mnxz

 

remote client

 

This will run on any Windows 10 device.   Just something to note: on a Windows 10 Mobile device (Lumia 950 XL in my case) you may have to set the device color scheme to light for the application text to be legible.  I’m sure this will be corrected in later builds.

iot client

Fill in the IP address of the Raspberry PI in the “Enter an IP address” text box and click / tap “Connect”.  You should now be seeing what the Raspberry Pi is displaying.

WP_20160403_16_42_25_Pro_LI
Remoting to a Windows 10 PC / Tablet

WIN_20160403_17_10_17_Pro
Remoting to a Lumia 950 XL