Cheap Arduino mesh using RF24 radio modules

Communication between devices is key when you want to combine one or more devices. In my previous blog, I used I2C, Bluetooth and RF24 modules. The latter ones, the RF24 have a few advantages: they are cheap and do not need pairing. In my previous blog, I used them for a peer-to-peer (or better: Master-Slave) communication. This time, we will look at a mesh network using these devices.

Continue reading “Cheap Arduino mesh using RF24 radio modules”

Advertenties

Control your Arduino Rover using Firmata and Xbox One Controller

A few month ago I bought a little rover (controlled by an Arduino Uno) for a very good price. The kit was very complete: Car chassis, 2 Car Wheels, 2 DC Gear Motors, a UNO R3, an L298N Dual H-Bridge Motor Controller and several other components.

This rover is meant to be programmed for autonomous operation. Hence an ultrasonic sensor and a servo is also added in the kit. Also a nice Arduino sensor shield 5 is in the kit. Yes, it was a real bargain 😉

But my idea was to use both an Xbox One Controller and the Firmata protocol to drive this one by myself or one of my sons. And it works very well!

Here is a video of the final solution:

In this blog, I will show you how it’s done.

Continue reading “Control your Arduino Rover using Firmata and Xbox One Controller”

Using your Xbox One controller in a UWP app

One of my original Xbox One controllers became useless a few weeks ago. It started to ‘walk away’ with my left stick. Whenever I released my thumb, it still generated a forward motion, not very handy if you are in the middle of a battlefield…

So I ordered a new one from the Microsoft Store but being a geek, I bought one with the Wireless Adapter for Windows.

02 adapter

This adapter makes it possible to use it on a Windows 10 device, like my laptop.

Continue reading “Using your Xbox One controller in a UWP app”

Better long running custom Firmata functions

If you managed to get to this part, you have seen how simple wired communication protocol between two Arduino’s is transformed into communication over Bluetooth using the Firmata protocol. Great!

Now we take a look, again, at a demo given at the Ignite 2015 in Australia. In this demo, an ultrasonic distance reader is used to generate a custom stream of measurement.

Although it’s a demo and it serves a purpose, the solution shown has an architectural flaw. If we look deeper into the Arduino code, we will find a ‘while (true) {}’. It is put inside a switch inside the ‘custom function handler’ sysexCallback().

Yes, this generates a constant stream of measurement but it also locks up the Firmata on the Arduino. No other call will de handle anymore because the endless loop is just blocking further communication.

Continue reading “Better long running custom Firmata functions”

Using a GPS receiver for Arduino

A few days ago I bought this GPS receiver component from the internet It only costs less than 10 dollars, a fair price. There are also components of 5 dollars but I have not checked them out yet, but they seem to do the same.

gps01

The number on the module was xm37-1612 and it is a rather common GPS module, even used in drones.

This module needs 4 pins: ground, power (3.3V or 5V), TX and RX. So it communicates using a serial port.

So just solder the pins on the module. Keep the big ceramic antenna on top, and pins downs. I soldered the pins up too so it’s not possible to put in on a breadboard 😦

Then connect the module to the Arduino using power and ground and the RX-TX. For now use port 0 and 1 (on an Arduino Nano), RX on RX, TX on TX (which is strange, normally they have to be crossed… Maybe it’s just this type which is behaving strangely).

Now connect the Arduino to a laptop using the USB cable. It is really easy to test the module!

This is how… Just open up the Arduino Sketch IDE and select the right board (I use a Nano) and select the right Com-port for the USB (I use port 3). And the open up the serial (port) monitor. Select a communication speed of 9600 baud, the speed the module uses. If just needed to upload an empty project.

And there you have it, raw GPS information coming from your GPS module.

gps02

Note: this trick works for my Nano. My Leonardo is not showing anything… (Update: this is due to the differences in the design of the board. Pro tip: if you want to use other pins, check out Software serial. But also check out the board limitations, such as the Arduino design. I use port 8 and 9 for RX/TX on the Arduino)

As you can see, the messages are shown in plain text. And for the trained eye, it even makes sense 🙂 (Just like a scene from The Matrix).

The GPS gives a lot of information: your position, the position of the satellites in sight, your speed, your heading, your elevation (but pretty poor), UTC time and the quality of the measurement.

The quality is called DOP, dilution of precision and it is an indication of the accuracy of the fix. It ranged from 1 to 50 but a DOP less the 10 is considered poor.

Btw. A GPS also receives information from the satellites which is not passed to the user. I am talking about trajectory and frequency information. Most GPS satellites are not geostationary and once in a while their trajectory is changed to avoid collisions with other space debris (or the IIS or Martians). And every satellite communicates in a different way/frequency. This information is put into a table and has to be updated frequently so the GPS ‘knows when to listen and where’. Otherwise, it loses the ability to receive the right information. High-level GPS devices (like a TomTom or Garmin) have the ability to upload the table from the internet (using some software tool provided by the company). But low-level modules have to receive it from the satellites. This can take up to a couple of hours. So collect all your GPS devices you keep at home or in your car and let them run for a couple of hours.

So what do these lines mean?

Each line is a certain sentence with specific information. Some sentences give the same information but overall they have their own usage.

For example, let’s look at:

$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47

The $GPGGA means that this sentence contains the essential GPS information. The *47 is just a checksum of this line. If the checksum of the line does not match *47, just ignore this sentence. Serial communication is easily corrupted but you will get a new sentence in just a fraction of a second.

The information in the sentence is separated by commas and each value represents some vital information. Eg. 123519 is a Fix taken at 12:35:19 UTC (It is always today). 4807.038,N  means Latitude 48 deg 07.038 seconds North and 01131.000,E  means Longitude 11 deg 31.000 seconds East.

More detailed information is available at http://www.gpsinformation.org/dale/nmea.htm

Looking at this complex data, do you still want to know your position? 🙂 In 2005 I already parsed these sentences and it is very intensive. And that was written in C#, we are using an Arduino with another language now…

Do not worry, we do not have to parse the data on our own. Now TinyGps comes to the rescue. There are two version a default one and a newer TinyGPS++. Both are working for our module.

So download the software library and import it into the Arduino Sketch IDE. And let’s start using the test_with_gps_device example (or ‘fullexample’ if you use TinyGps++).

As you can see in the code of the example, you are able to adjust the baud rate in the code, the RX Port and the TX Port.

But because you are working using an actual device, please now attach RX to TX and visa-versa.

Now there is a catch! In my innocence, I adjusted the code so I used port 1 and port 0 (although the code was referring to port D4 and port D3). So it was not working… See how the checksum is failing…

gps04

In other examples, I made the same mistake. It just gave a lot of corrupted characters. What was I doing wrong besides being stubborn?

Well as we have seen in the previous communication, the RX-TX line is used by the USB to fill the serial monitor. So the RX-TX is already in use! But officially this is the only possibility for serial communication.

Therefore, the example uses SoftwareSerial. This library simulates serial communication on other ports. So do not ignore port 4 and 3 🙂

gps03

If you experience lines full of stars but the checksum is zero, the communication could be ok… Please check RX is connected to TX etc.

So now you have some basic knowledge about both the working of GPS in general and specific knowledge about accessing your GPS module using TinyGps.

Update for Neo-6m-GPS module

Today I tested another GPS module, a Neo 6M module (https://www.aliexpress.com/item/GY-NEO6MV2-NEO-6M-GPS-Module-NEO6MV2-with-Flight-Control-EEPROM-MWC-APM2-5-large-antenna/32648952399.html). It only costs $3.75, including shipping, so it was worth a trial.

gps

The module at the top of this web page, pushes it’s NMEA messages over the RX/TX lines. So I just attach an Arduino Nano with an empty sketch and the raw GPS info appears in the debug window.

This Neo 6M module gave nothing…

but I got the right information using the TinyGPS-13 library. Look in the Arduino IDE at the “simple GPS sketch”. Just connect 5V to VCC and ground to GND. Then connect TX with port 4 and RX with port 3.

Port PPS can be ignored (this is used for time/clock functionality).

And with that sketch, GPS info will arrive (in-house I connected to 7 satellites now). A led on the GPS module shows when data arrives at the module.

On the web page of the seller, a warning is given that the chip is old. But my GPS module gave good reception and accurate location. So, for less the four dollars I can recommend this GPS module. The module has a separate ceramic antenna (attached by a wire which contains some sticker (better leave it on, could be some interference filter)). This makes the module a bit fragile but also mode flexible to place in a casing.

 

 

Getting IP-Address in Win 10 IoT Core

I was working on a new pet project for Windows 10 IoT Core.

At this moment Win10 IoT Core is not supporting the Wi-pi Wi-Fi dongle. So I am using a Dlink 505 mobile companion to attach my Raspberry Pi b2 to my local network. This works great although Visual Studio has some trouble detecting the device.

But because the default app (yes, this is just an app) on the Pi shows the current IP-address, I can simply submit that address when deploying (in the project settings).

pack1

So far so good.

But when I deployed my own app I ran into a little problem. My Pi gets the current IP-address dynamically so at one point my deployment was not working anymore. The device had a new IP-address….

And this address is also needed for RDP so it is rather important.

I wanted to read the current IP address in C# code so I could show it in my own app. This seems a bit trivial, but Google was not helping me this time. All examples were based on System.Net so that was not working.

Then I was thinking, could it be that the default app is just open sourced? That way I could look in the code MSFT provided.

And yes it is! Just go to the github location.

And there I found the code to read the IP4 address (now a bit modified):

public static string GetCurrentIpv4Address()
{
  var icp = NetworkInformation.GetInternetConnectionProfile();
  if (icp != null
        && icp.NetworkAdapter != null
        && icp.NetworkAdapter.NetworkAdapterId != null)
  {
    var name = icp.ProfileName;

    var hostnames = NetworkInformation.GetHostNames();

    foreach (var hn in hostnames)
    {
      if (hn.IPInformation != null
          && hn.IPInformation.NetworkAdapter != null
          && hn.IPInformation.NetworkAdapter.NetworkAdapterId
                                                     != null
          && hn.IPInformation.NetworkAdapter.NetworkAdapterId
                      == icp.NetworkAdapter.NetworkAdapterId
          && hn.Type == HostNameType.Ipv4)
      {
        return hn.CanonicalName;
      }
    }
  }

  return "---";
}

Resolve the namespaces if needed…

So thank you MSFT for making the code available.

Dvlup.com is now part of MSDN network

Almost two years ago, I joined http://www.dvlup.com. I was exploring and building Windows Phone apps and Nokia had this really exciting program. What’s better then building apps? Building apps and getting free stuff for them!

A few months ago, Microsoft has rebranded dvlup.com to MSDN Rewards. So join it for free.

The program is very easy: just finish some challenges and earn points. And with these point, go shopping in the rewards shop.

The challenges are very streight-forward; Earn XP and/or point by building apps with special features, do a quiz for a special subject, attend a (online) event or update a app.

Last month DVLUP introduced me into machine learning using Azure, programming the Microsoft Band and the Edge browser. And I have my app tested by others using http://www.wpbeta.me.

I really like dvlup.com as a gamification concept. As the slogan says: “Have fun. Earn rewards. Build new ideas” it connects you to new technology, new tooling and other part of MSDN you normally do not encounter.

The only drawback for me is that it is not possible anymore to earn hardware in The Netherlands. Pitty because with Windows 10 just around the corner and having earned enough points for a simple device, it would be nice to buy a nice tablet or phone in the Microsoft Store. But maybe this will change in the near future.

So if you are interested in Microsoft technology and earn some software tooling, hardware (in some area’s) or gift cards, just join dvlup.com.

See how I am doing at https://rewards.msdn.microsoft.com/svelde