Arduino Robot–Infrared Remote Control

I added an infrared receiver to my robot prototype.  Now I can (kind of) control the direction and speed using a remote control.

The code needs some work to smooth out the controls, but it is an exciting start!

I referenced this intractable – How to Use IR Remotes with Arduino (Current and Updated) to get started using the IR remote.

To start with I connected the IR receiver and just had it output the IR codes to the serial window.  I pressed each button and made a note of the corresponding code.  I then defined these as constants in the sketch to make them easier to reference.

I simply followed the advice on the IR receiver product page to connect up the 5v and ground and then connected the receiver to the Arduino pin 11 (via the connection on my stacked motor shield):

RobotIR

Continue reading

Arduino Robot – Initial Prototype

I have an overall goal to use the Arduino to build some kind of really simple robot.  Eventually I hope to do cool things like remote controlling it and maybe control it through a C# application (and eventually over the internet would be awesome!)

This weekend I put together my robot chassis.  I got the Emgreat Motor Robot Car Chassis Kit.  Here is how it looked after I assembled it:

assembled

assembled1

Continue reading

Arduino Ranging Distance Sensor with LCD and RGB LED

Last week two new components for my Arduino arrived in the mail:

  • 16×2 LCD (Liquid Crystal Display) Module
  • SainSmart HC-SR04 Ranging Detector Mod Distance Sensor

So of course I had to combine the two into a project!

I started off by using the ranging sensor to read the distance  of objects directly in front of it (based on this instructable).  I then used this data to change the color of a RGB LED.  So it lights up green if there is nothing within 30cm, then turns blue when something gets within 20cm and then red when closer than 10cm.

The idea behind this is I am hoping to integrate this into an upcoming robot/car project.  I’m hoping to have the robot stop itself before crashing into a wall (or my kid or a cat!)  One step at a time though!!

Once I had this working, I thought it would be cool to display the distance on the LCD.  The first thing I had to do was solder the header pins into the LCD board (this was a kind of huge step for me, as I’d never used a soldering iron before, so it was pretty exciting stuff!)

I used the awesome adafruit tutorial to wire up the LCD and updated the code to output the distance.

Here’s how it looked running:

DistanceSensor

Distance Sensor running

Continue reading

C# Serial Communication with Arduino


Introduction

A couple of weeks ago I got an Arduino Uno.  Suffice to say I’m now a little bit obsessed with it.

I know nothing about electronics, but found the idea that I could write code to control electronic components absolutely fascinating!

I bought the Vilros Arduino Ultimate Starter Kit, which is awesome and had everything I needed to get started right away.  It includes a great little guide book that steps you through some basic circuits (or sketches I guess they are called).

Of course, me being me, I couldn’t quite make it through the entire guide before I started going off on my own (note to self: go finish the last few samples!)

One of the tutorials uses a temperature sensor and some code that reads the temperature and outputs it to the serial communications port.  As soon as I saw that I could write to the COM port, I knew I had to create something that could receive commands and output results, which I could then integrate with a C#.NET application.  And hence this project began… Continue reading

Error enabling SQL Notifications Broker

I’m using a combination of SQL dependency and ASP.NET SignalR to provide real time updates to a web UI when certain data changes in within a SQL database.

I was having problems with this, as the SQL dependency was never firing.  This worked fine in development, but failed when I moved it into a Dev Integration environment (with a different SQL Server).

I ran the following SQL to enable the notifications:

ALTER DATABASE Cge SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE ;
GO

Continue reading

Blog Code Syntax Highlighting

I recently had a problem with my code samples syntax highlighting.

I use the SyntaxHighlighter Evolved WordPress plugin, but noticed that this started to just display a box around the code – without applying any of the special formatting.

I have been using PreCode to copy/paste my source code into a Pre tag.

Anyway, long story short, I found a setting for the plugin that, once enabled, fixed the problem.

In my WordPress admin page, under Settings > SyntaxHighlighter, I had to enable the “Load All Brushes”  option:

image

It even tells you right there in the description that you need this when using <pre> tags!

Real Time Map with D3.js and ASP.NET SignalR


Introduction

I’ve been using D3.JS a lot recently at work to create some economic data visualizations.

I also got the chance to play with ASP.NET SignalR to update a web page showing progress on long running workflow type process (using a SQL Dependency, which was cool!)

For the last few months I kept thinking to myself “wow wouldn’t it be cool to hook up D3.js and SignalR to have a real time updated data visualization?”  I mentioned this to a couple of developer friends (at a bar where all the best ideas originate!) and they said “hey what about one of those D3 maps you keep talking about?!”.  And thus this experiment was born.

It turned out to be really simple to get this working, although I’m sure it helped that I’ve recently been working with both of these technologies.  This post will intentionally gloss over some of the extra details – like how exactly the map gets drawn initially and how the SignalR hubs work – and concentrate on the real time update.  I’ll include a couple of links at the end of the post to give you a head start on both D3 mapping and SignalR.

Continue reading

MVC 5 Unobtrusive client side validation with jQuery 1.10.2

I’m working on a new ASP.NET MVC 5 (5.1.2) application within Visual Studio 2013 Update 2.

I tried to add client side validation using Model Data Annotations and the Html Helper:

[Required(ErrorMessage = "Please enter the required value")]
public int ARequiredValue { get; set; }

@Html.ValidationMessageFor(model => model.ARequiredValue, "", new { @class = "text-danger" })

This didn’t work.  Instead of the validation kicking in, the submit button just posted to the controller.

Initially I saw an error in my browser console, saying that jqueryval couldn’t be found (http 404).  This was coming from my attempt to output the jqueryval bundle.  Investigating this lead me to find that this bundle was not configured.  Worse, the JavaScript (jquery.validate and jquery.validate.unobtrusive) files that it needed were not even included in the project.  These used to (in my MVC4 projects) be included by default within a new MVC project.

So I tried to use Nuget to install the Microsoft jQuery Unobtrusive Validation package:

image

But got an error saying Operation Failed – Updating ‘jQuery 1.10.2′ to ‘jQuery 1.4.1′ failed. Unable to find a version of ‘Microsoft.jQuery.Unobtrusive.Validation’ that is compatible with ‘jQuery 1.4.1′:

image

I checked the version of jQuery included (by default) in my project was jquery-1.10.2.min.js.

I need to investigate into this some more to see if there is a better solution, but I really needed to get this working in a hurry, so here is my temporary workaround.

I copied the following unobtrusive validation JavaScript files from an existing working MVC solution into my Scripts folder

  • jquery.unobtrusive-ajax.min.js
  • jquery.validate.min.js
  • jquery.validate.unobtrusive.min.js

Then I added reference links to these files within my main _Layout.cshtml file:

  

  
  
  
  @Styles.Render("~/Content/css")
  @Scripts.Render("~/bundles/modernizr")
  @Scripts.Render("~/bundles/jquery")
  @Scripts.Render("~/bundles/bootstrap")
  

  
  
  

So far this seems to be working, but I’d be interested to hear if anyone has hit this problem and has any more information.

Update

A helpful reader (Eldi) commented with a simpler solution.  I just tried it in a newly created MVC project and it works.  Thanks Eldi!

Using NuGet, install the following packages in this order:

  • jQuery.Validation
  • Microsoft.jQuery.Unobtrusive.Validation

Installing jQuery.Validation first fixes the problem.

Creating a Simple Bar Chart with D3.js

This post will step through creating a bar chart with D3.js.

To keep things simple we will be using some hard coded data.  I grabbed the top five goal scorers for Manchester United last season (from ESPN FC) and put them into JSON format.  So we have an array of the player’s name and the number of goals they scored.  I’m populating this in the document ready event (using jQuery):

$(document).ready(function () {
    var jsonData = [
        { "PlayerName": "Robin Van Persie", "GoalsScored": 26 },
        { "PlayerName": "Wayne Rooney", "GoalsScored": 12 },
        { "PlayerName": "Javier Hernández", "GoalsScored": 10 },
        { "PlayerName": "Shinji Kagawa", "GoalsScored": 6 },
        { "PlayerName": "Patrice Evra", "GoalsScored": 4 }
    ];
});

We are going to be creating a SVG element containing the various rectangles, lines and text that we need to build up a chart.  The end result will look like this (which you can see running at http://darrenblogsamples.azurewebsites.net/D3/BarChart):

image

Continue reading

Software Developer