Speed testing the MPU9150’s functions using a LinkIt ONE

Standard

Background

I am working on a project where I am gathering a lot of data. One of the sources of my data is my 9Dof sensor. Since I am logging at sub-second intervals, I wanted to know how long (the cost of time) each sensor takes to return data, so I make sure to get as many data points, from as many data sources as possible.

I set up this project with the sole intention of determining the cost in milliseconds of the standard example, then try to figure out how to make it faster.

Setup

I grabbed my trusty LinkIt ONE and my 9Dof sensor (MPU9150, connecting over I2C), and looked at the example library. I wanted to get data from each of the sensors as fast as possible, and I will do post-capture processing for heading and orientation. I set my sights on these three programs:

  • getAccel_Data
  • getGyro_Data
  • getCompass_Data

I then made blocks of C to run in a loop:

Serial.print(millis() % 1000);
Serial.print(",Acc1,");
getAccel_Data();
Serial.print(Axyz[0]);
Serial.print(",");
Serial.print(Axyz[1]);
Serial.print(",");
Serial.print(Axyz[2]);
Serial.print(",");
Serial.println(millis() % 1000);


This is my code for checking a single Accelerometer data gathering. I figured all I had to do is try running the same block, with additional runs of “getAccel_Data;” and notations of “”Acc_” so I can to comparisons afterwards. I then take the time difference between the start and end and map it to the sensor read type, and the sensor read count. After that, I subtract the time of the single run to the double and triple run to find how much longer it took for the one or two additional runs.

Accelerometer Tests

Let’s have a look at one set of my results (do note, time is in milliseconds, 1/1000th of a second):

Row Labels Average of Runtime StdDev of Runtime
Acc1 23.307 2.230
Acc2 45.701 3.985
Acc3 68.123 6.254

First thing I see here is that 23.3 + 45.7 does not equal 68.1. This is good, this is what I expect, and am glad to see. My formula for calculating the actual average runtime of getAccel_Data is as follows:

( (Acc2 – Acc1) + (Acc3 – Acc1) ) / 3

This is set up to give a double weight to the difference between Acc3 and Acc1, since there was an additional run compared to Acc2 to Acc1.

Testing All Sensors

I created a few sets of functions besides the stock ones to test out.

  • getAccelGyro_Data: Combined getAccel_Data and getGyro_data, eliminating duplicate runs of accelgyro.getMotion9
  • getDof_Data: Combines getAccelGyro_Data and getCompass_Data
  • getRawDof_Data: getDof_Data without the calculations, just raw values

Ultimately, I let my computer run, and I got 4600 records for each set of sensors. Here’s my results:

Runtime
Function Runs/cycle Average StdDev
getAccel 1 23.307 2.230
getAccel 2 45.701 3.985
getAccel 3 68.123 6.254
getAccelGyro 1 23.364 1.998
getAccelGyro 2 45.844 3.899
getAccelGyro 3 68.235 6.166
getGyro 1 23.303 2.005
getGyro 2 45.729 3.924
getGyro 3 68.192 6.200
getCompass 1 11.231 2.411
getCompass 2 21.774 4.139
getCompass 3 32.368 6.095
getDof 1 33.926 3.493
getDof 2 66.875 7.062
getDof 3 99.803 10.856
getRawDof 1 33.945 3.418
getRawDof 2 66.967 7.083
getRawDof 3 99.951 10.899

From this, I calculated the following:

Function Actual Cycle Cost Overhead Cost
getAccel 22.4038 0.8983
getGyro 22.4380 0.8591
getCompass 10.5597 0.6631
getAccelGyro 22.4504 0.9287
getDof 32.9420 0.9872
getRawDof 33.0094 0.9418

Conclusion

  1. The library should not have “getAccel_data” and “getGyro_data”, rather just combine the two together for optimal performance.
  2. Also, when we look at the ‘getDof” vs. “getRawDof”, by saving the larger values instead of reducing their size before saving, it actually costs time. About 0.0674 milliseconds per cycle.
  3. You save 22.4596 milliseconds per cycle by combining gathering the sensor data into one procedure.
  4. You save 0.0681 milliseconds by running “getDof_data” instead of “getAccelGyro_data” and then “getCompass”.

Unboxing the LinkIt ONE

Standard

So you got yourself a LinkIt ONE, and you’re trying to figure it out. Everything on paper looks pretty cool, but it’s a little intimidating. Don’t worry, I will help you through it.


First thing you notice is the small size of the box, and the distinct lack of weight. The blue on the edges stands out and looks crisp. Then you flip the box over and see all the small text on the back. The biggest things to take from the small text is that this is a very flexible, powerful board.

20150804_11551420150804_115441


You should cut the two tape circles that hold the top and bottom of the box together before trying to open it up. This is only a suggestion, as user experience varies with the method employed. Once you get it open, you realize they are serious about wanting you to use this for IoT, as on the inside of the glowing pink lid, it says “The Ultimate Developer Board for Wearables and Internet of Things”. This is the 5th time you see this.

20150804_115533


The board is now exposed. You take a moment to let this masterpiece sink in. It’s green and yellow. Why? I’m not sure, but it’s a coloring style they have carried over to their other LinkIt products, so I’m just going to go with it.

20150804_115607

When you look closer you’ll see every pin labeled, including the pins in the Grove connectors. I wish they would color code the board connectors based on the type (digital, analog, i2c, serial), but they have not, and I have yet to do that myself.

There’s a couple switches on the board that are key to your user experience:

  • SPI/SD: this determines if the board can send over serial, or write to the SD card (using the LSD library). I know, it sucks having to choose, but you’ll move on.
  • USB/BAT: this tells the board what power source to pull from. If the board is in BAT mode, it will charge and run off USB, but stay on when unplugged. Also important to note is that providing 5v to the 5v pins does not charge or power the board. It was recommended to me to sacrifice a micro USB cord and power it through the USB port.
  • MS/UART: when the computer is connected to the ONE, you have to choose how it shows up. MS is used for loading small files onto its 10mb storage or upgrading the firmware. UART is what we are used to from ‘duino programming.

Take the board out and look at the bottom. There’s a shield that takes up about 60% of its size with a sticker with your UUIDs. You’ll also see a SIM card holder on the top. The micro SD slot is between that and the motherboard, accessible from the end. The card clicks into place. The ONE can support up to 32GB. At the other end of the board are the three connectors for the antennas. Be diligent when connecting your antennas so that they go in the right place.

20150804_115555


Take out the black foam, and you’ll find the good stuff. There’s a battery in one bag, and the antennas in the other. Looking at the antennas, you realize they couldn’t have chosen a wider variety. The battery is awesome in that the connector is polarized so you won’t plug it in wrong, and the ONE has a built in system for charging and reporting on its’ state.


20150804_11561920150804_115629

20150804_115645At the bottom of the box there are an additional two sheets of paper that are almost impossible to get out. The smaller one is the Quick Start Guide, and the larger one is the wall pin-up that describes the connections. Careful where you post this, as it is certainly described as hardware porn.

20150804_122309 20150804_115720


It’s said a few times that the main processor is the MediaTek 2502A, and to give you an idea what it actually does, I’ll give it a shot. It’s a Socket on a Chip (all in one) that has Bluetooth and GSM/GPRS abilities. Bluetooth modes 2.0 and 4.0 are supported, and cell bands 850/900/1800/1900MHz are usable. This means that T-Mobile, AT&T, and Ting are all available to use in the USA. The Wifi is actually a separate chip (I think the one that drives the LinkIt Connect) but is integrated seamlessly. The libraries you’ll use are prefixed with an “L”: LGPS, LDateTime, LBT along with many others, and then my favorite, LSD the SD card library.

The one thing that is distinctly lacking is a USB cord. The ONE uses a standard mirco USB adapter, and has worked fine on a 2.0 port on my laptop. When plugged in, the battery will charge, regardless of the coding actions being performed on it. Remember the SD/SPI switch that I mentioned earlier? That’s one time that you’re going to have to fly blind since you can’t have serial output while the ONE is reading/writing to the SD. Also interesting to note is that the ONE shows up as two serial connections in the Arduino IDE.

Once you get all the items out of the bags, you’re going to wonder how to organize the unwieldy mess of wires and antennas. I too was wondering that, since I wanted to just put this beauty in a case, and forget about it. Alas, I have yet to find one, so I made one out of Legos. Then I rebuilt it, then rebuilt it again. This has proven to be quite a solid transportation and developmental base station.

Final version, or all versions

20150105_124124


I’d recommend you take a look at what you are actually going to use, then only have those antennas connected. I was looking towards my old stand-alone GPS with a frayed connection cord as justification for all my time spent figuring out a case for the ONE.

In my next post I’ll talk about getting up and going with programming the ONE with Windows 7. I will also discuss the different libraries and uses with them.

Why should I get a LinkIt ONE?

Standard

This is the first in a multi-part series on choosing and becoming familiar with the LinkIt ONE.

Why LinkIt ONE?

Maybe you’re on the fence about what platform to start off with. Maybe you have a project in mind that you need Wi-Fi connectivity. Maybe you want to just have all the hardware taken care of so you can move onto coding. Maybe you need a LinkIt ONE.

What is it?

It’s a very nice and complete Arduino clone, with the chips coming from MediaTek, and the board coming from Seeed Studio. It uses a micro USB for programming, and you need to use a special variant of the Arduino IDE that has packages and libraries in the right place. I’ve been able to add new libraries to this without any compatibility issues, so don’t worry about that.

Hardware for price is unparalleled. You get a device with GPS, Wi-Fi (2.4 GHz and client only), Cellular, BT, built in battery connecter/charger, microSD slot, 10 mb flash for code, and a 260 MHz processor to make it all work. There’s no cases available, so for now you’re going to have to make your own. There’s also two Grove adapters (I2C and UART) right on top.

What can it do?

With the amount of programming space you can use (about five times of a normal UNO), there’s not much you can’t fit into it. With the array of hardware available, there’s not much connectivity that is not available. I have used it for projects that leverage the extra storage space, along with the wireless connectivity abilities. Having everything on one board makes getting up and going with code really easy.

What can’t it do?

Since the pins are 3.3v, you need to make sure you connect things properly. You also have to choose (there’s a switch on the board) between accessing the SD card or the serial back to the computer by USB. I’ve also found there’s no native way to provide power back to the board, I have to connect by USB to recharge the battery and power the ONE.

Summary

The LinkIt ONE is very versatile, compact, cheap (now $60 USD) Arduino clone that can utilize existing sensors and libraries to truly be the IoT backbone for 99% of your connected devices.

Pringles Can antenna with a LinkIt ONE

Standard

With my never-waning obsession with wardriving, I wanted to make something that played off it that anyone could use. I’ve seen can antennas over the years, and wondered about making one.
So I did. And here it is:

Materials:

  • Zip ties
  • Pringles can
  • Linkit ONE
  • Grove RGB screen
  • Big paper clip

How I made it:

First I looked at how the cantennas were made online. They were not only putting the antennas in the can, but they were actually making a Yagi. This was something I decided I was not going to do. Too much effort, and not enough time. I put a zip tie through the can right below the nutritional information, as this is where I saw the true builds place their entry point. I connected the zip tie around the outside, and pulled it taught. This would be the base of our antenna’s location.


20150325_092302 20150325_092323

20150325_092310

I then attached the antenna towards one of the in-can portion of the zip tie, making sure I had enough of the tail to comfortably attach to the LinkIt without strain. Last thing I needed to do was to break my wifi card. With that in place, I connected the antenna to the LinkIt, and the placed the LinkIt against the can, and put one zip tie on snugly to keep it from going anywhere. I tucked the battery into the left side, allowing just enough wire length to connect it.
The last and final piece is the screen. Here I did a loop of a zip tie through the end of the can, then held it in place with a large paper clip. I felt that the way I did it encompassed the “hacker” mentality of doing what’s needed to get the job done.

The code:

The code I wrote is an adaptation of the wifi scan. There’s three different versions of the code. First is to roll through all the 2.4gHz networks on the screen. The second is to exclude some. Since I work where there are many APs, this was my main code. Then when I did my actual testing, I filtered my results to only display one AP’s signal.

On boot up, I also have the screen show the battery percentage, as I wanted to make sure I had enough juice. I’m still at 100% after almost an hour of testing. The LinkIt is a beast.

Code sauce: Wifi Witch Code

Testing Method:

I wanted to test the effectiveness of the antenna, so I grabbed my second LinkIt (Thank you Seeed!), put it in my coveted Lego v3 case, and had it report my location, along with its signal strength. No reflectors of any kind were used. I had it report to my computer, and I recorded the data into Excel. I set the router up next to the window to give be the best chance to see it with my equipment. No mods were done to my stock WRT54GS, and it was transmitting at its stock wattage (75mWs or so).

20150326_122426 20150326_122404

Testing out in the field:

I literally walked out into a field and parking lot to see how far it would work. The graph below shows my results by distance:

Signal Strength Comparisons

20150326_125332

Conclusion:

As we can see, there’s a noticeable difference in signal strength at the further distances, with the can providing a higher signal level at all distances (except the fluke at 206m, IDK, maybe becuase I was on a hill?). The main thing to note is that the antenna in the can provided a solid signal, while the unshielded antenna was spotty. Quality of the signal was noticeable. Overall, a Pringles can over your antenna will help you maintain contact from a long distance.

Future plans:

I plan on making a proper logger for the LinkIts so that it records their location along with the signal strength so I can do a scatter plot. This should show the quality of the data, not just the theoretical maximum.

Project Mashup – Converting an RC Enzo into an Arduino powerhouse

Standard

A few pieces fell in place over the last 24 hours that are calling me to make this project. I was gifted an awesome 1:16 scale Ferrari Enzo RC car, and in hacker form, I want to mash it together with a Seeed Studio Linkit ONE. I will be acquiring another one than the one I have in my Lego case v3, as I love that one so.

I took some pre-conversion pictures so that I can do a full build log.


Stock website:

http://silverlit.com/toy/power-in-speed-licensed-116-scale-racer-86027-ferrari-enzo

Product pictures:

86027_2[1]86027_1[1]


My pictures:

20150130_13292520150130_13294620150130_13300820150130_132356


Plans:

Since the LinkIt ONE has GPS, I plan on having a data recorder in it. I will also leverage wifi and bluetooth for connectivity. I also like the idea of using the audio out to drive a speaker to add realistic sounds. Vroom!!

I would love to design a distance sensing array to give this outright automation abilities. I will be trying very hard to keep the look and feel of the original shell, so that adds a lot of restrictions on placement and size. I have hope, and will post updates on my IR blaster arrays.

Thoughts?

LinkIt ONE Lego Case Versions

Standard

I found I had collections of pictures from each of my Lego case versions. Since the internet loves lessons and OC, here you go!


Version 1:

20141025_173414

Shortcomings:

  • Plugging in anything was super hard, and don’t even think about the micro SD card
  • Reset button was hidden

Version 2:

20141112_20331620141112_20340520141112_20354220141112_203710Shortcomings:

  • Fragile
  • Held the board in by pinching it. This is not the best way of doing things
  • There was still a little too much movement of parts

Version 3:

Full build log link:

https://deltainnovativelabs.wordpress.com/2015/01/15/linkit-one-lego-case-v3/

20141118_22385220141118_223904

20150105_12412420141118_223922

20150105_12414020150105_12432120150105_12434920150105_12444220150105_12451820150105_12454220150105_12470120150105_12474020150105_12482720150105_12483920150105_124922

Shortcomings:

  • Shield probably won’t fit
  • People constantly try to play with the rollers thinking it’ll do something

LinkIt ONE Lego Case v3

Standard

This build was something I did on my own to protect the LinkIt ONE that I carry with me so dearly. With all of its modules, it has become my main go-to unit, and for its price, it cannot be beaten for a while. Where it is lacking is in the durability department. Those cords are dangling all over the place, and just asking to be broken. About 4 hours of tinkering and using went into this design, and the only shortcoming that I am finding is that it probably does not accommodate shields. There are worse things, so we move on.

20150105_12412420150105_124140

This is compact and just big enough to hold all the antennas and battery in place. The pieces used were what I had available, and I’m sure that each person will have a slight variant. Have fun with it.

Step 1:

20150105_124922

Lay out the bottom pieces like the picture has. The large ones are two 4×12 flat bricks with a 1×8 in between. The 1×4 on top is smooth to wedge the battery in place to prevent movement.

Step 2:

20150105_124839

The frame and the build of the case is a little unique because the LinkIt is only 7 bricks wide. In this picture, you are building up the battery and cellular voids. All the gray angles are the same, and in the bottom right is a 1×4 and 1×3 to build up support for the wifi/bt antenna.

Step 3:

20150105_124827

Put your battery in place. It’s now or never.

Step 4:

20150105_124740

This is where the magic happens. There’s two 1×8 flats for the LinkIt to rest on, but the 1×4 on the left and the 1×2 on the bottom right keep it in place. Don’t’ forget to add the 1×4 you see in the bottom right.

Step 5:

20150105_124701

Here is where you get your LinkIt in place. Set it on top of the smooth bricks you put in during the 4th step. Build the wifi/bt antenna enclosure you see closest to you with the white bricks. The black bricks are full 16 length. Make sure the cell antenna is pushed completely in so the wifi/bt holder won’t damage it.

Step 6:

20150105_124542

Put them in place, making sure the cord for the wifi/bt antenna does a little loop that you see in the picture. That will contain the extra length and relieve stress from the contact points. Build the set of Legos you see closest to you. This will hold the GPS.

Step 7:

20150105_124518

Build the axle with the rims on it. These have just the right spacing to hold the board and GPS in place. The axel is 8 long with ½ brick length on each end.

Step 8:

20150105_124442

Going clockwise around the picture, the length of the large pieces are 12, 8, and 10. Make sure you have the black connector on the first one, and the 4 and 6 length flat Legos on for spacing in the next steps. The axel goes into the third from the right hole on the first length, and the fifth from the right hole on the third piece.

Step 9:

20150105_124349

Put the pieces in place from step 8, making sure the LinkIt and the GPS are sitting easily in place. At this point, the board should not move. Grab your two 2×6 flat pieces.

Step 10:

20150105_124321

Put those 2×6 pieces on either side of the top of the case. Next grab two 2×8, two 2×4, and one 1×4 flat pieces and assemble like you see in the picture. This is going to go on top.

Step 11:

20150105_124124

Put the Legos assembled in step ten on top, making sure the GPS antenna is seated inside without forcing anything. At this point, make sure everything is pushed together. Then shake around like there’s no tomorrow. The only noise you should hear is a slight movement of the battery.

Step 12:

Build awesome things.