C#, Hardware, IoT

RCSwitch for Windows 10 IoT

RCSwitch is a library for controlling remote power sockets from Arduino. The original source code by Suat Özgür can be found on GitHub. In combination with the MX-FS-03V sender MX-05V receiver, I wanted to do the same thing on Windows 10 IoT on my Raspberry Pi. To use RCSwitch in a Windows Universal app, I ported the library into a C++ Windows Runtime Component. The RCSwitch port to the Windows Universal Platform is now available on NuGet. To use it in your IoT project, just install the NuGet package and then copy these code samples: Create an instance of the RCSwitchIO class: Turning remote power sockets on/off: In good .NET fashion, you can also subscribe to an event to listen for incoming signals: However I found that receiving does not work very reliably. Initially I was able to sometimes receive signals, but a few weeks later (with a different remote)…

C#, Machine Learning, Uncategorized

Learn and Predict the Gender of German Nouns

The German language is know to be relatively complicated and especially the gender causes lots of confusion. While English has only one article (the), three different articles are used in German: der (male) die (female) das (neuter) While rules to determine the gender of a noun exist, almost no German native speaker can name them. We can now solve this problem (determine the gender without memorizing the rules) using some simple machine learning with the Accord framework. Let’s quickly name the steps that will follow: find and extract a dataset of noun-gender associations split into training, test and validation dataset extract features into something the algorithm can use train a Naive Bayes test the model with the test dataset After quite a while of searching, I found this machine readable and CC-BY-SA 4.0 licensed XML file from Daniel Naber. In our Universal Windows App we can then load all nouns into…

C#, Software, Windows 8, Windows Phone, WinRT

Replay Practice

Are you playing an instrument? Yes? Then you probably know what it is like when you’re practicing the same few notes all over again! Sometimes playing it slower can help too. With Replay Practice you can do exactly that. Choose a song, move the markers and loop a part of the song at a speed of your choice. Replay Practice is available for Windows Phone 8.1 and Windows 8 !  

Arduino, C#, Hardware, Root, Windows 8, WinRT

Arduino as a MIDI/Bluetooth Relay for Windows 8.1 Apps

In my last post I described how a Bluetooth connection between Arduino and a Windows 8.1 device can be established. The next step for me was to connect the Arduino to my electronic drum kit which has both, a MIDI-IN and a MIDI-OUT jack, but any other electronical instrument will do as well. The wiring diagram for an Arduino Uno R3 with MIDI-IN/OUT and the JY-MCU Bluetooth module is shown in Fig.1. NOTE: Occasionally there are MIDI shields available for Arduino, so you might not have to build it on your own. The Arduino code to relay MIDI>Bluetooth and Bluetooth>MIDI is actually quite simple. //======================================================authorship //by Michael Osthege (2013) //======================================================includes #include “SoftwareSerial.h” //======================================================constants const int TX_BT = 10; const int RX_BT = 11; const int MIDI_TX = 1; const int MIDI_RX = 0; //======================================================bluetooth setup SoftwareSerial btSerial(TX_BT, RX_BT); //======================================================initialization void setup() {     Serial.begin(31250);     btSerial.begin(9600);     Serial.println(“Bluetooth initialized”); }…

Arduino, C#, Hardware, Windows 8, WinRT

Bluetooth communication between Arduino and Windows 8.1

Introduction Recently, after being inspired by this video of Arduino Bluetooth communication with Windows Phone 8 by Marcos Pereira, I got myself some new devices to play with: Arduino Uno R3 in a starter kit (link) JY-MCU Bluetooth module (link) and a few extra cables The thing is: I don’t have a Windows Phone 8 yet and the Windows Phone 7.8 APIs do not support this kind of Bluetooth communication. But: I have a Surface RT and with Windows 8.1 the RFCOMM API can be used to establish a serial link to the Arduino. Arduino and Visual Studio It happens that my developing skills are quite limited to C# and when I had to develop some Kinect software with Processing in early 2012, I almost freaked out. Arduino code is written in C++  and the standard Arduino IDE is derived from the Processing IDE. Fortunately there’s the Visual Studio extension…

C#, Root, UI, Windows Phone

A Custom (Async) MessageBox for WPF and Windows Phone

The System.Windows.MessageBox provided by .NET is limited to a very small set of MessageBoxButtons (Yes/No/OK/Cancel) which do not allow for custom Button texts. The System.Windows.Forms.MessageBox also blocks the UI thread, which can be an annoying disadvantage as well. The MessageBox on Windows Phone has the same disadvantages. Custom buttons in a MessageBoxe simplify the decision for the user, because they can describe the results of the action: However you need to do this with a custom control, so for WPF as well as Windows Phone I designed a simple method for asynchronously showing a MessageBox with custom buttons. (The WPF implementation based on this control by Evan Wondrasek) So let’s bring some sample code.In WPF you can use multiple custom buttons: And on Windows Phone you’re limited to 2 buttons: To use CustomMessageBox, you need to get TCD.Controls from NuGet: And on Windows Phone 7.x you also need async support,…

C#, Metro, Windows 8, WinRT

In-App Donations for Windows 8 Apps

Recently I wanted to offer my customers the opportunity to donate some money. No extra features, just a clean donation option. In-app purchases seemed to be the best option. The idea is to have a list of products which have a price and contain “donate” in their product ID (Fig. 1). In the app the list of products can be retrieved and shown when a donate button is tapped. If donations have been given can be checked by enumerating the existing licenses and looking for the “donate” term (Fig. 2). Reasonably simple right? Well the principle is simple, but in-app purchases are a bit tricky to develop, debug and get through certification. (It took me 7 submissions to get it right..) Those are the things that can result in certification failure: no internet connection -> exception store does not respond properly -> exception error message looks to much like a…

C#, Root, UI, Windows 8, WinRT

Localizing Enums (in a ComboBox)

Enums have many useful applications and are often used in CoboBoxes to let the user select things. In the code behind the enum values are often defined using more or less cryptic text, because neither spaces, special characters, or leading numbers can be used in enum values (for good reasons!). Therefor it is necessary to change the text to something more understandable (language-localized in some cases). One way to achieve this is to create the ComboBox items manually, but it’s much more comfortable to fill the ComboBox items directly with the enum values, because you can get/set the SelectedItem without converting it back and forth from/to the enum value. You can’t override the .ToString() method of the Enum type, so we have to come up with another solution. Just like any other control, the ComboBox uses a Template to create its items. We will replace the default template with one…

C#, UI, Windows 8, WinRT

Keyboard Dismissing ComboBox

In the last few days I came across a design issue with the touch keyboard on Windows 8. The keyboard dismissal logic (documented here) defines a list of controls which do not cause the keyboard to dismiss when they get focused. The purpose is to prevent the keyboard from opening and closing all the time when the user fills out a form and is likely to switch between keyboard-editable controls such as TextBox and other controls like AppBar, Checkbox, RadioButtons the ComboBox and some more. While that works fine with the other controls, ComboBox expands when interacted with and might get covered by the touch keyboard. And unfortunately you can’t change that behavior, or manually dismiss a deployed touch keyboard. (The user is in complete control over the keyboard.) While on the MSDN forums it was suggested to alter the layout such that the ComboBox is less likely to collide with the…

Bio, C#, Root

03 Der Needleman-Wunsch-Algorithmus

Einführung in die Bioinformatik Vorbereiten der Software Grundlagen der objektorientierten Programmierung Einfaches Codebeispiel – manipulieren eines strings Referenzieren einzelner Zeichen in einem string Generieren einer zufälligen Aminosäure-Sequenz Scoring von Alignments Prüfen auf Identität Bewerten von Mutationen – Substitution Matrix Bewerten eines Alignments Der Needleman-Wunsch-Algorithmus Die F-Matrix (abstrakt) Auswählen des Alignments (abstrakt) F-Matrix (Code) Auswählen des Alignments (Code) Die F-Matrix (abstrakt) Der Needleman-Wunsch-Algorithmus geht bei der Berechnung des idealen Alignements in zwei Schritten vor, um exponentiell skalierende Rechenzeit zu vermeiden. Zunächst wird die sogenannte F-Matrix berechnet, aus welcher anschließend das ideale Alignment zusammengesetzt wird. Zur Veranschaulichung alignen wir die Sequenzen GACFC und GCFHC. Jedes Feld in der Matrix (jede Zelle der Tabelle) beinhaltet einen Score. Diese Punktzahl ist jene, die auf dem Weg zur Berechnung des Feldes gesammelt wurde. Zur Berechnung einer Zelle sind immer die Felder links oben, oben und links notwendig: Unter den drei Feldern wird jenes gewählt, durch…