Return of Netduino, .NET on small hardware

A little piece of magic wandered into my Twitter feed recently. Between the Windows IoT stuff I messed with this summer, controlling LEDs via Xamarin.Forms, and this awesome news, I’m bound to be learning the hardware side of things a little better. Netduino is back!— Netduino (@netduino) July 20, 2017 That’s right, Netduino has returned; this time Wilderness Labs has taken the reins (with Bryan Costanich heading things up). Netduino is a hardware platform, similar to Arduino with lots of input and output options through a bunch of pins on the board, that allows interacting with it using .NET. Not only has Wilderness Labs resurrected Netduino, they have released three new boards: Netduino 3, Netduino 3 Ethernet, and Netduino 3 WiFi. According to the Wilderness Labs Netduino docs, these new boards are as fast as ever, all running Cortex-M4 processors at 168MHz, and with more flash storage and a bump in RAM: the base Netduino 3 has 384KB of flash (matching the old Netduino 2 Plus), and the Netduino 3 Ethernet and Netduino 3 WiFi both have a bump to 1,408KB. If it wasn’t obvious, the Netduino 3 Ethernet board also offers a 10/100 Ethernet port, and the Netduino… Continue reading

Xamarin.iOS C# Recipe: Animating Views with iOS 7 UIGravityBehavior (UIKit Dynamics)

Now that iOS 7 has landed, and Xamarin gave us same-day C# support, it’s time to start poking at the new bits. One such piece is UIKit Dynamics. With UIKit Dynamics, you can greatly simplify all sorts of view animations. While this simple recipe will only address UIGravityBehavior, iOS 7 adds a bunch of other predefined behaviors and allows the creation of custom ones as well. Source code is available on GitHub. Basic Gravity Animation To have a view simply start falling off the screen, you just toss the desired view at a new UIGravityBehavior and add that behavior to a UIDynamicAnimator. UIDynamicAnimator animator; public override void ViewDidLoad() { base.ViewDidLoad(); View.BackgroundColor = UIColor.White; animator = new UIDynamicAnimator(View); var item = new UIView(new RectangleF(new PointF(50f, 0f), new SizeF(50f, 50f))) { BackgroundColor = UIColor.Blue, }; View.Add(item); UIGravityBehavior gravity = new UIGravityBehavior(item); animator.AddBehavior(gravity); } You can continue to put items under the effect of gravity by adding them to the behavior. gravity.AddItem(someOtherView); That’s really it for basic gravity, but craziness is only a step beyond that. You can modify the Angle, GravityDirection, and Magnitude of your gravity as well. Potential Memory/Performance Trap It’s worth noting that those items that go flying off the… Continue reading

MonoTouch Programming in Visual Studio

TL;DR Never underestimate the little time sinks of switching between IDEs regularly. To write MonoTouch code in Visual Studio 2010 (debug/deploy still requires MonoDevelop on a Mac), go get VSMonoTouch. If you have any issues getting it going, you may need to toss in some project file tweaks. Set it to not reference mscorlib.dll Set the System.Web.Services reference to version (and likely any others that may conflict with the latest .NET runtime assemblies). Background I’ve been programming with MonoTouch for a few months now using MonoDevelop. I really enjoy learning new things (even if MonoTouch saved me from learning Objective-C), but switching IDEs always tosses a few kinks in my productivity. I have tweaked a number of key bindings in MonoDevelop to match Visual Studio, some at the cost of my ability to adapt to the Mac’s defaults that are normally used everywhere. At one point I switched copy and paste to use Ctrl in MonoDevelop, but then I kept screwing up outside of the IDE. Regardless, I have become fairly productive in MonoDevelop from simply adapting to the new system through repetition (often screwing up when I switch back to Windows now). I don’t really have a problem… Continue reading

Creating an animated spinner in a Xamarin.iOS (MonoTouch) UIImageView

Background I’m well into my first week of building the Sierra Trading Post first iOS app using Xamarin.iOS and it has been a fun ride so far. One of the first things needed was a system for showing a loading image while asynchronously retrieving the final image with a web request. Attempt 1 Xamarin has a recipe for using a UIImageView‘s AnimationImages to make a spinner. UIImageView someImageView = new UIImageView(); someImageView.AnimationImages = new UIImage[] { UIImage.FromBundle(“Spinning Circle_1.png”), UIImage.FromBundle(“Spinning Circle_2.png”), UIImage.FromBundle(“Spinning Circle_3.png”), UIImage.FromBundle(“Spinning Circle_4.png”), }; someImageView.AnimationRepeatCount = 0; // Repeat forever. someImageView.AnimationDuration = 1.0; // Every 1s. someImageView.StartAnimating(); It may be possible to make this work, but it wasn’t quite what I needed. This seems to be more of an image rotation than an animation. As a result, it creates a jerky animation between the various images equally distributed over the AnimationDuration you set. After this, attempts to find some ideas for a better solution lead me to about a hundred lines of code that proved a difficult to consume, involving a CGBitmapContext and CGAffineTransform.MakRotation. (To be fair, this code isn’t doing something as simple as what I want to do.) Hoping to avoid that, I simply added four more… Continue reading

Mono for Android: “aapt.exe” exited with code 1

TL;DR Also available in TL;SO (too long; Stack Overflow) flavor. Getting this error: “aapt.exe” exited with code 1? Do you have any files in your Mono for Android solution that are being packaged together with the app (e.g., “AndroidResource” build action)? If so, make sure they don’t have anything but letters, numbers, periods, and underscores ([a-z0-9_.]) in their names. Details I am still getting my feet wet with Mono for Android (MfA) development. One of my first projects was a flashlight app for my Galaxy Nexus that introduced me to a couple Android/MfA development quirks. One concept in app development that I would like to explore is long-running tasks. How do I keep something going after the user has switched off to something else? Greg Shackles has a new Visual Studio Magazine article on Background Services in MfA on just that topic. He creates a background service for playing an MP3 file using a standard Android service. In his sample project, he sets up the service to play some Creative Commons Nine Inch Nails music. I’m betting that I’m the first person to use (and include in the sample) a Nine Inch Nails song for Visual Studio Magazine. #winning— Greg… Continue reading