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!

 

FacebookTwitterGoogle+LinkedIn

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!

FacebookTwitterGoogle+LinkedIn

Getting Started with a pcDuino

This is a brief introduction to the pcDuino.    I personally love it.  It’s a very compact, high performance device but with compatibility with arduino shields.   This is great for IOT use cases where more performance (or you could say intelligence) is needed.   The applications for this is endless and I hope to be exploring many of those in blogs to come.

Today I will just start with getting to know the pcDuino, and will take baby steps and we will begin with installing Ubuntu on it.  Out of interest, the pcDuino can also run Android 4.2.

 

PcDuino

 

As the picture shows, the pcDuino is nice and compact, but has all the features you could want on a device.  Having said that, there is only 1 Type A USB port.   I suggest as per my photo, to use a USB hub at-least to get everything up and running.  Many thanks to ‘O’Reilley’ for mine! 🙂   I am using a USB thumb drive, but to save a port a micro SD card could also be used.   There is a SD card slot under the board next to the audio connector.

 

Overview (as per www.pcduino.com)

pcDuino3 is a high performance, cost effective single board computer. It runs operation systems such as Ubuntu Linux and Android. pcDuino3 has HDMI interface to output its graphic desktop screen. It could support multi-format 1080p 60fps video decoder and 1080p 30fps H.264 and MPEG4 video encoder with its built-in hardware video processing engine. It targets specially the fast growing demands from the open source community. pcDuino3 provides easy-to-use tool chains and is compatible with the popular Arduino ecosystem such as Arduino Shields.

Features & Highlights:

  • 100% compatible with original Arduino Shields
  • 100% compatible with Linux and Android
  • Further support for:
  • C, C ++ with GNU tool
  • Java with standard Android SDK Python
  • Arduino pin header, Aduino UNO Slots: 14x GPIO, 2x PW M, 6x ADC, 1x UART, 1xSPI, 1x I2C
  • Ethernet 10M/100Mbps, WiFi, SATA

 

Below is the specs for the pcDuino 3 and 3B.   I will be using a 3B in this post.

 

CPU AllWinner A20 SoC, 1GHz ARM Cortex A7 Dual Core AllWinner A20 SoC, 1GHz ARM Cortex A7 Dual Core
GPU OpenGL ES2.0, OpenVG 1.1, Mali 400 Dual Core OpenGL ES2.0, OpenVG 1.1, Mali 400 Dual Core
DRAM 1GB 1GB
Onboard Storage 4GB Flash, microSD card (TF) slot for up to 32GB 4GB Flash, microSD card (TF) slot for up to 32GB
Video Output HDMI 1.4 with HDCP support HDMI 1.4 with HDCP support
OS
  • Ubuntu 12.04
  • Android 4.2
  • Ubuntu 12.04
  • Android 4.2
Arduino extension interface Arduino sockets, same as Arduino UNO
14xGPIO, 2xPWM, 6xADC, 1xUART, 1xSPI, 1xI2C
Arduino sockets, same as Arduino UNO
14xGPIO, 2xPWM, 6xADC, 1xUART, 1xSPI, 1xI2C
Network interface
  • Built-in WiFi
  • Ethernet 10M/100Mbps
  • Built-in WiFi
  • Ethernet 10M/100Mbps/1Gbps
Audio out
  • 3.5mm analog audio interface
  • I2S stereo digital audio interface
  • 3.5mm analog audio interface
  • I2S stereo digital audio interface
LCD LVDS LVDS
IR IR receiver IR receiver
SATA SATA Host socket SATA Host socket
Camera CSI CSI
Battery Li-Poly Battery Interface Li-Poly Battery Interface
USB 1 x USB host, 1xUSB OTG 1 x USB host, 1xUSB OTG
Power 5V, 2000mA 5V, 2000mA
Overall Size 121mm x 65mm 121mm x 65mm
Image download Image for pcDuino3  Image for pcDuino3B

 

Installing Ubuntu 14

Downloand the Ubuntu 14 Nand image here:   https://s3.amazonaws.com/pcduino/Images/v3/ubuntu14/pcduino3_livesuit_ubuntu14_GbpsMAC_20141231.tar.gz

 

Download Phoenix Suite for writing the Nand Image to the pcDuino from here:  https://s3.amazonaws.com/pcduino/Tools/PhoenixSuit1.0.6.zip

I didn’t have much luck getting Phoenix Suite to work in Windows 8.1 64 bit.  The USB driver does not install.  I however had success on Windows XP and Windows 7.

 

You will need two micro USB cables for writing the nand image.   You will also need a 5V 2A USB power supply.   I am using an iPad charger which is working just fine.

 

Plug in the USB power supply into the power USB port.  This is situated between the Ethernet port and the HDMI port.     Then plug in the second USB cable into the micro USB OTG port, which is situated next to the USB type A port on the opposite side of the board.   The other end of this cable will be plugged into the PC.

 

Run the Phoenix Suite software.     It will oddly say, “No Device Attached”, but ignore that.      Select “Firmware” which is top center of the dialog.   And browse to the image.   Note that this uses the “img” file, so be sure to extract the “gz” file that was downloaded.   I used 7zip to do this.   Click on the “Upgrade” button.  Again ignore any messages that pop up.

phoenix

On the pcDuino board press the “Upgrade” button.   While holding the button, press the “Reset” button.    These are both clearly marked on the board.

 

A popup will appear in Phoenix Suite: “Does mandatory format?”   Click “Yes”.

 

A few minutes later you should be greeted with a message:  “Upgrade Firmware Succeeded!”   Plug in a HDMI cable, mouse, keyboard and reset the pcDuino.   A moment later Ubuntu should boot and the GUI will appear on the HDMI monitor.  Also note the Tx and Rx leds on the board will both be lit up indicating success.

 

This is just the first step to exploring the pcDuino. I hope it was helpful.

FacebookTwitterGoogle+LinkedIn

Rolling your own Android Emulator

In certain situations the emulators provided just don’t cut it.      It is actually relatively simply to create your own by just using an x86 image of Android.   It is also possible to add additional features to the emulator for testing by virtue of daemons installed.

 

Download Android X86 iso image of choice from http://www.androidx86.org/download

 

Boot ISO in Hyper Visor of choice. (Android will work in VMWare, VirtualBox and Hyper-V) 

 

Install any GPS, Accelerometer, orientation etc spoof daemons of choice

 

Android Debugger Bridge  (ADB)

 

Once Android is booted (first time), run terminal (on Android) and issue commands below

o setprop service.adb.tcp.port 5555

o stop adbd

o start adbd

o or adb tcpip 5555 

 

From the development PC (issue commands via CMD – adb can be found in platform-tools folder in you Android SDK folder):

o adb connect [Android emulator ip address]

 

If the ip not known from Android terminal command: (busybox ifconfig)  Connect as normal from Visual Studio.   Should appear as Hyper Visor name, ie VMWare etc

 

 

FacebookTwitterGoogle+LinkedIn