Posts Tagged ‘c#’
Orange Pi Development Boards

Quokka IoT FPGA Board is Programmable with C# Language (Crowdfunding)

January 12th, 2018 1 comment

Quokka IoT (preliminary) hardware specifications:

  • FPGA – Intel Altera Cyclone IV, 6K logic elements, EP4CE6E22C8
  • Clock – 50MHz
  • Connectivity – WiFi via WiPy module
  • Expansion
    • 40x GPIO (3 banks by 8 pins, with direction and voltage (3.3V or 5V) configuration, 16 raw IO pins 3.3V)
    • 2x Dual Channel 10 bit ADC (3.3V)
    • 2x Dual Channel 10 bit DAC (3.3V)
    • H-Bridge for DC motors with support for external power
  • Power Supply – 5-24V DC input

The specifications are preliminary, because the FPGA may be replaced by one with more logic cells (e.g. 20K) depending on the popularity of the project. Drivers are available for each hardware component on the board including ADC and DAC drivers, UART, JSON serializer\deserializer and much more.

As mentioned in the introduction, C# programming is possible with QDT, and it’s not limited to Quokka IoT board, so you should be able to use it with other FPGA boards, although a license may be required as we’ll see below.

You can watch a short demo of the board in action while attached to a robotic chassis.

The project has launched on Kickstarter with a $30.000 AUD funding goal (~$23,600 US). Rewards start at 150 AUD ($118 US) for Quokka IoT board only, but if you want to use the board with QDT, you’d need to add 50 AUD extra for a total of 200 AUD (~$158 US). Shipping adds 25 AUD ($19.7 US), and delivery is scheduled for May 2018.

Thanks to TLS for the tip

Using GPIOs on NanoPi NEO 2 Board with BakeBit Starter Kit

May 21st, 2017 10 comments

NanoPi NEO 2 is a tiny 64-bit ARM development board powered by Allwinner H5 processor. FriendlyELEC sent me a couple of NEO 2 samples together with their BakeBit Start Kit with a NanoHat and various modules via GPIOs, analog input or I2C. I’ve already tested both Armbian with Linux 4.11 and Ubuntu Core Qt with Linux 3.10, and ran a few benchmarks on NanoPi NEO 2. You would normally prefer to use the Armbian image with Linux mainline since it provided better performance, but at the time I was told GPIO support was not there.

Configuring NanoPi NEO 2 board with BakeBit library

So this week-end, when I decided to test GPIO support and BakeBit Starter Kit, I decided to follow this advice, especially image is still the recommended one in the Wiki. So I went with that image.

I’ll use Python examples from Bakebit library, but if you prefer something similar to WiringPi, you may consider using WiringNP library directly instead of using Bakebit. Since NanoHat Hub comes with header with digital I/O (including 2 PWM), analog input, I2C and UART interfaces, I’ll make sure I try samples for all interfaces I have hardware for. FriendlyELEC did not include a module with a UART interface, so I’ll skip that one.

I followed instructions in BakeBit wiki from a terminal which you can access from the serial console or SSH. First, we need to retrieve the source code:

Then we can start the installation:

The last line will install the following dependencies:

  • python2.7           python2.7
  • python-pip         alternative Python package installer
  • git                        fast, scalable, distributed revision control system
  • libi2c-dev           userspace I2C programming library development files
  • python-serial     pyserial – module encapsulating access for the serial port
  • i2c-tools              This Python module allows SMBus access through the I2C /dv
  • python-smbus   Python bindings for Linux SMBus access through i2c-dev
  • minicom             friendly menu driven serial communication program
  • psutil                   a cross-platform process and system utilities module for n
  • WiringNP           a GPIO access library for NanoPi NEO

This will take a while, and after it’s done, the board will automatically reboot.

We can check if everything is properly running, but try out one of the Python scripts:

hmm, python-smbus was supposed to be installed via the installation script. Let’s try to install it manually:

Running the command again with verbose option shows the download URL is not valid:

So I went to looking for another python-smbus library in case the name has changed, and I finally installed the pysmbus:

I could go further, but the I2C bus was not detected:

So maybe the driver needs to be loaded. But running sudo modprobe i2c_sunxi it does nothing, and I could notice the .ko file is missing from the image…

So let’s try to build the source code for the board following the Wiki intructions:

We also need to install required build packages…

… download gcc-linaro-aarch64.tar.xz toolchain, and copy it to lichee/brandy/toolchain directory (do not extract it, it will be done by the build script).

Now we can try to build the kernel for NanoPi NEO 2 (and other Allwinner H5 boards).

and it failed with more errors possible related to CROSS_COMPILE flag. There must be a better solution… FriendlyELEC guys might not work on Saturday afternoon, and while I did contact them, I decided to try one of their more recent images with Linux 4.11 available here.

Let’s pick since it has a similar name, and is much newer (released 3 days ago). I repeated the installation procedure above, and …

Success! Albeit after 4 to 5 hours of work… Let’s connect hardware to ind out whether it actually works, and not just runs.

Analog Input and Digital Output – Sound Sensor Demo

The simplest demo would be to use the LED module, but let’s do something more fun with the Sound Sensor demo I found in BakerBit Starter Kit printed user’s manual, and which will allow us to use both digital output with the LED module connected to D5 header, and analog input with the Sound sensor module connected to A0 header. Just remember the long LED pin is the positive one.

You can run the code as follows:

I changed the source a bit including the detection threshold, and timing to make it more responsive:

The LED will turn on each time the the sound level (actually analog voltage) is above 1.46V.

PWM and Analog Input – Servo and Rotary Angle Sensor Demo

We can test PWM output using the Servo module connected to D5 header, and control it using the rotary angle sensor module connected the A0 analog input header .

Click to Enlarge

The sample for the demo runs fine, and use the potentiometer is detected:

However, the servo is not moving at all. Raspberry Pi relies on rpi-config to enable things like I2C and other I/Os, and I noticed npi-config in the Wiki for NEO 2. So I ran it, and sure enough PWM was disabled.

So I enabled it, and answered Yes when I was asked to reboot. The only problem is that it would not boot anymore, with the system blocked at:

So maybe something went wrong during the process, so I re-flashed the Ubuntu image, reinstalled BakeBit, and re-enabled PWM0. But before rebooting, I checked the boot directory, and noticed boot.cmd, boot.scr, and the device tree file (sun50i-h5-nanopi-neo2.dtb) had been modified. The DTB looks fine, as I could decode it, and find the pwm section:

Let’s reboot the board. Exact same problem with the boot stuck at “Starting kernel…”. So there’s something wrong with the way npi-config modifies one or more of the files. With hindsight, I should have made a backup of those three files before enabling PWM the second time… I’ll give up on PWM for now, and ask FriendlyELEC to look into it.

I2C and Analog Input – OLED UI controlled with Joystick

The final test I’ll use the I2C OLED display module connected to one of the I2C headers, together with the analog joystick module connected to A0 header.

Click to Enlarge

Let’s run the sample for the demo:

It works, but there’s a bit of a lag, and the sample may have to be improved to better detect various states. I’ll show what I mean in the video below.

The bad parts are that documentation is not up-to-date, enabling PWM will crash the image, and while the Python sample do demonstrate IO capabilities, they should probably be improved to be more responsive. The good part is that we’re getting there, the hardware kit is a really nice, and I think the documentation and software should become much better in June, as FriendlyELEC has shown to be responsive to the community issues.

What? Python sucks? You can use C language with GPIOs too

If Python is not your favorite language, FriendlyELEC also provided some C languages samples in the C directory:

As we’ve seen above, Bakebit library appears to rely on WiringNP, and you’d normally be able to list the GPIOs as follows:

The utility is not too happy about seeing an Allwinner H5 board. But maybe the library in the board is not up-to-date, so I have built it from source:

and run the gpio sample again:

Excellent! It’s not quite a work-out-of-box experience, but NanoPi NEO 2 can be used with (most) GPIOs.

My adventures with NanoPi NEO 2 board are not quite done, as I still have to play with NanoHat PCM5102A audio add-on board, which I may end up combining with a USB microphone to play with Google Assistant SDK, and I’m expecting NanoPi NAS Kit v1.2 shortly. I’ll also update this post once PWM is working.

Xamarin Ported Android to C#. Results: Massive Performance Improvements over Dalvik

May 2nd, 2012 No comments

Xamarin has been providing Mono, a C# framework that can work on Linux for some years, and more recently they have also launched Mono for Android and iOS so that you can write or re-use existing C# application on the most common samrtphone platforms.

But their latest project “XobotOS Research Project” goes much further, as they have entirely re-written Android Dalvik engine based on Java with C#. Considering the million of lines of code in Android, they have found a tool to automatize the Java to C# conversion. This tool is an Eclipse plugin called is Sharpen, and Xamarin has made further improvements to Sharpen which are available on Github.

They already have ported Android 2.x and Android 4.0 to C#. If you wonder why they would do that, look at the “benchmarks” below showing Mono vs. Dalvik implementation of Android for binary tree, jovian and hashtags.

Massive difference in the performance of structs and generics in binary tree implementation in Java and C#

Mono vs Dalvik Android Benchmarks

Since the company focuses on mobile apps, Xamarin amazingly explains that this implementation has just been done for “fun” and they have released XobotOS source code. However, this was not done in vain and some of the work will be implemented in their future products namely:

  • Direct Graphics Access to Skia: Mono for Android currently accesses the graphics libraries through Java, but thanks to the code written for XobotOS, Mono will be able to access the native rendering code in Skia.
  • Java to C# tooling:  As mentioned above, a new  improved version of Sharpen is available as part of XobotOS release.
  • Replacing Java code with C# code: They will be able to replace some chunks of Java code with C# code to improve performance.

You can read Xamarin’s Android Ported to C# blog post for further details.

200 C# Programming Video Tutorials

September 5th, 2011 No comments

Last month, 200 Android Development Video Tutorials by TheNewBoston had been uploaded to ChangingTheUnknown Youtube channel. They have now prepared another playlist with 200 C# programming video tutorials for beginners in C#.

To give you an idea of what you would learn, here are the titles of the first 10 tutorials:

  1. Introduction and Installing C# 2010
  2. Changing Forms Properties
  3. Showing MessageBoxes
  4. Variables
  5. Changing Properties With Code
  6. If Statements
  7. More on If Statements
  8. If Statements pt 3
  9. Switch Statements
  10. Mathematical Operators

You can watch the first tutorial: “C# Beginners Tutorial – 1 – Introduction and Installing C# 2010” below.


Categories: Programming, Video Tags: c#, programming, tutorial, video

New Revision of C++ Programming Language: C++11

August 16th, 2011 No comments

The Final International Draft standard (FCD) was unanimously approved on August 12th, 2011. The standard should be published this year. The draft name of the standard is C++0x, but since it will be published this year, it should probably renamed C++11, and if there are delays in its publication it could well be renamed to C++12.

You can download the 1334 pages “Working Draft, Standard for Programming Language C++” to get the full details.

If you don’t feel like going thru that massive document, but still want to learn about C++0x, I recommend you check the C++0x FAQ on Bjarne Stroustrup (The creator of C++) homepage.

Here are some the new features and improvements:

  • initializer-lists – Initializer lists are not just for arrays any more
  • uniform initialization syntax and semantics
  • template aliases (previously know as template typedef)
  • rvalue references
  • defaulted and deleted functions
  • variadic templates
  • auto – deduction of a type from an initializer
  • inherited constructors –
  • decltype – the type of an expression (replacement for typeof)

According to Stroustrup, these enhancements are sufficient to make C++0x feel like a new language.


Categories: Programming Tags: c#, c++0x, c++11, programming, standard

C Code to get MAC Address and IP Address

April 5th, 2011 No comments

Function in C to return the MAC Address:

Function in C to return the IP Address:

Running .NET applications on Linux Embedded Systems

February 7th, 2011 1 comment

You may have some applications developed using Microsoft .NET application framework that are running on Windows XP, Windows Vista and Windows 7.

.NET for Linux

dotnet Framework in Linux

Run Microsoft .NET Framework Apps in Linux

If after spending much effort and time, you have a request to port your application to Linux, you don’t need to rewrite everything thanks to Mono, an open source implementation of .NET framework that can be run in Windows, Linux and MacOS.

The development framework is composed of three parts:

  • Mono – An open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET
  • MonoDevelop – An open Source C# and .NET development environment for Linux, Windows, and Mac OS X
  • Mono Tools for Visual Studio – Development Tools to develop and migrate .NET applications to Mono on Linux without leaving Visual Studio. This application can be tried for 30 days and / or purchased. This tools is compatible with Visual Studio 2008 and Visual Studio 2010.

A large number of applications already use mono including:

  • Unity3D – Unity is is a 3D game editor with powerful cross-platform capabilities (also used together with Qualcomm Augmented Reality development kit)
  • gTwitter – A standalone GTK# twitter application
  • Paint.NET – A port of Paint.NET 3.0 to run on Linux
  • Nant – A free .NET build tool.
  • Ayuda OpenSplash – A (soon to be) open source digital signage player

Some limitations

Mono 2.8 is compatible with all versions of .NET  (up to .NET 4.0). However mono is not 100% compatible with all features of the .NET framework, here are the limitations:

  • .NET 4.0 Limitations:
    • CodeContracts – API complete, partial tooling
    • EntityFrameworks – Not available.
    • Server-side OData – Depends on Entity Framework.
  • .NET 3.5 Limitations: N/A
  • .NET 3.0 Limitations:
    • WCF – silverlight 2.0 subset completed
    • WPF – no plans to implement
    • WF – Will implement WF 4 instead on future versions of Mono.
  • .NET 2.0 Limitations: N/A
  • .NET 1.1 Limitations:
    • System.Management – does not map to Linux
    • System.EnterpriseServices – deprecated

Mono .NET Application Framework for Embedded Systems

mono can also be used for ARM and MIPS platforms running Linux and other OS.

It is currently running on iPhone, Linux (Maemo) and Android devices  such as Nokia 770

The best way to cross-compile .NET framework for ARM is to use ScratchBox, a cross-compilation toolkit for Linux.

The instructions to cross-compile Mono native code (Virtual Machine to run on ARM) and managed code (C# toolchain) are available at

Since Mono 1.2.1, mips targets are also supported.

If your systems is low on flash, follow the instructions to reduce mono footprint.