Arduino

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

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#

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#

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#

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…

C#

TCD.Mathematics

UPDATE: Source and samples for WinRT and WPF are now on GitHub: https://github.com/michaelosthege/TCD.Mathematics This is just a quick post to introduce you to TCD.Mathematics, which is a NuGet package that adds several extension methods to the System.Windows.Media.Media3D namespace. If you’re unfamiliar with this namespace, it contains Point3D, Vector3D, Line3D and Plane3D classes which can be used for three-dimensional calculations. EDIT: I just submitted an update to the NuGet package, wich adds support for WinRT. Please not that WinRT does not have neither Point3D, Vector3D, nor the System.Windows.Media.Media3D namespace. So in WinRT all classes, including substitutes for Point3D/Vector3D are located under TCD.Mathematics. EDIT: Since version 1.2.0 TCD.Mathematics is a Portable Class Library that targets everything: Silverlight 4+, .NET4+, .NET for Windows Store, Windows Phone 7+, Xbox360 – make sure you’re running version 2.1+ of NuGet Package Manager! The extension methods, which are added to the mentioned Point3D/Vector3D classes are: Vector3D.AsPoint3D() Point3D.AsVector3D() Vector3D.Normalized() Point3D.CenterOfClusterWithOtherPoint3Ds () Point3D.ProjectOnLine3D() Point3D…

C#

TCD.Controls

This is a summary and manual for all controls inside the TCD.Controls package. I’ll try to keep it updated. Windows 8 SilentTextBox – If AcceptsReturn=False and the user hits Enter normal TextBoxes make a ‘bling’ sound. SilentTextBox does not. HeaderedTextBox – A TextBox with a grey header above HeaderedTextBlock – A TextBlock with a grey header above; Automatically hides itself if the Text property is empty (unless AutoHide is set to False). LabeledProgressBar – a ProgressBar coupled with a TextBlock/Label; use it at the top of your page to indicate background progress (like the SystemTray.ProgressBar on Windows Phone) LayoutAwarePage – same as in all the samples Flyout – most recent post and how to use on Flyout SettingsContractWrapper – the easy way to integrate with the settings contract   Windows Phone CustomMessageBox – Async CustomMessageBox on Windows Phone ReverseAutocompletePopup – Making a reverse Autocomplete-TextBox on Windows Phone

C#

TCD.Device

Just another TCD namespace: TCD.Device. Its purpose is to contain additional namespaces that use features like Camera, GPS, Accelerometer, Compass.. Everything that has an effect on the App permissions the user sees on the Windows Phone or Windows 8 application. (Like ‘This app has access to your location, compass..’) TCD.Device.Camera CodeScannerPopup is another async control, specific to the Windows Phone platform, that can be used to scan for QR codes. (In theory other 2D-codes as well.) Usage: add the TCD.Device.Camera NuGet package add using directives for TCD.Device.Camera and TCD.Device.Camera.Barcodes in the calling method (eg. a Button.Click event) hide/show ApplicationBar, attach/remove BackKeyPress event Code sample: private async void Button_Click(object sender, RoutedEventArgs e) { CodeScannerPopup scp = new CodeScannerPopup(Microsoft.Phone.Shell.SystemTray.IsVisible, Format.ALL_1D); //important: hide ApplicationBar and handle BackKeyPress ApplicationBar.IsVisible = false; this.BackKeyPress += scp.HandleBackKeyPress; //now let’s go ScanResult r = await scp.ShowAsync(“BARCODE SCANNER”, “scan”); if (r != null) output.Text = string.Format(“{0}n{1}”, r.Text, r.Format.ToString()); //clean…

C#

TCD.Controls – Flyouts for XAML/C#

Hey there, Let’s start with the most important news: TCD.Controls is now available on NuGet (click here if you don’t know how this works, or why you want to use it) From now on, I won’t link *.zip packages with the sources anymore, because NuGet really make life easier. If you want access to the source files, just drop me an email There’s been one more or less important change to the Flyout control you should know about: It now has a property called “IsIgnoreLightDismissal”. To understand its purpose, imagine the following scenario (video below) You have a Button control that opens a FilePicker/FolderPicker, asking the user to select a File/Folder. This Button is hosted inside a Flyout control. Now when the user taps the Button, the Picker will popup, stealing the focus from your applications Window. Flyouts are required to hide on App-switch by the design guidelines, which is…

C#

Exploring NuGet

Since 5 hours now, I ‘m on NuGet and I’d like to share my first experiences. Why did I join NuGet? I joined NuGet, because it seems to be the most comfortable way to share libraries, containing XAML controls. Share them between my own projects, as well as with you. Previously I always had to include the project containing the controls in the solution I was working on, which was really annoying.. How can you use it? Let’s assume that you want to use a package in your project. All you need is the NuGet Package Manager Visual Studio extension. You can install it via Tools/Extensions and Updates. To use/reference a package from NuGet right-click on the references in the solution explorer and select ‘Manage NuGet Packages’. Then you can search for the package you desire (for example ‘TCD.Serialization’) and add it to your project. How do I use it?…