Monday, July 11, 2016

Arduino-like millisecond (ms) and microsecond (us)-resolution timestamps in Python: millis(), micros(), delay(), & delayMicroseconds()


Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Written: 11 July 2016
Last Updated: 19 Oct 2016
-updated code with Linux functions too (not just Windows); posted new code as a GitHub Gist

Other Articles:
Below, I show some code for basic Python millisecond (ms) and microsecond (us)-resolution timing functions. I made these to resemble Arduino functions I am already familiar with. Since these functions use the Windows API's QueryPerformanceCounter and QueryPerformanceFrequency functions, as-written, they work for Python in Windows only. If you decide to adapt them to Linux, please share how you did it in the comments section. Update (19 Oct 2016): I have updated these functions to work with Python in Linux now too! See here.

Functions and code samples. Functions include:

View on GitHub. #-create some low-level Arduino-like millis() (milliseconds) and micros() # (microseconds) timing functions for Python #By Gabriel Staples # #-click "Contact me" at the top of my website to find my email address #Started: 11 July 2016 #Updated: 11 July 2016 """ References: -personal (C++ code): GS_PCArduino.h 1) Acquiring high-resolution time stamps (Windows) - 2) QueryPerformanceCounter function (Windows) - 3) QueryPerformanceFrequency function (Windows) - 4) LARGE_INTEGER union (Windows) - -***** absolute-timing-cpu-cycle-count """ from ctypes import * #FUNCTIONS: def micros(): "return a timestamp in microseconds (us)" tics = c_int64() freq = c_int64() #get ticks on the internal ~2MHz QPC clock windll.Kernel32.QueryPerformanceCounter(byref(tics)) #get the actual freq. of the internal ~2MHz QPC clock windll.Kernel32.QueryPerformanceFrequency(byref(freq)) t_us = tics.value*1e6/freq.value return t_us def millis(): "return a timestamp in milliseconds (ms)" tics = c_int64() freq = c_int64() #get ticks on the internal ~2MHz QPC clock windll.Kernel32.QueryPerformanceCounter(byref(tics)) #get the actual freq. of the internal ~2MHz QPC clock windll.Kernel32.QueryPerformanceFrequency(byref(freq)) t_ms = tics.value*1e3/freq.value return t_ms def delay(delay_ms): "delay for delay_ms milliseconds (ms)" tStart = millis() while (millis() - tStart < delay_ms): pass #do nothing return def delayMicroseconds(delay_us): "delay for delay_us microseconds (us)" tStart = micros() while (micros() - tStart < delay_us): pass #do nothing return #EXAMPLES: #print loop execution time 100 times, using micros() tStart = micros() #us for x in range(0, 100): tNow = micros() #us dt = tNow - tStart #us; delta time tStart = tNow #us; update print("dt(us) = " + str(dt)) #print loop execution time 100 times, using millis() print("\n") tStart = millis() #ms for x in range(0, 100): tNow = millis() #ms dt = tNow - tStart #ms; delta time tStart = tNow #ms; update print("dt(ms) = " + str(dt)) #print a counter once per second, for 5 seconds, using delay print("\nstart") for i in range(1,6): delay(1000) print(i) #print a counter once per second, for 5 seconds, using delayMicroseconds print("\nstart") for i in range(1,6): delayMicroseconds(1000000) print(i)


***Subscribe by Email! (via FeedBurner)***

Saturday, July 2, 2016

About Me


Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Added to website: 2 July 2016
Last Updated: 6 Aug 2016
-More comments and notes added about my thesis Version 1; updated resume uploaded.

A Few Other Articles:
Table of Contents:
-Early Days
--Master's thesis downloads


2 July 2016:
Some may wonder about who I am, my background and experience, etc, so here it is. If you'd like me to come work for you as an engineer, contact me, as I'm hoping to be in the job-hunting market soon, so I can once again get on track pursuing my dreams. My resume is below. You can find my email by clicking the "Contact Me" tab at the top of this website.

Early Days:

I first decided I wanted a Radio Controlled (RC) airplane when I was about 5 years old. Since my dad taught me about money from a young age, via weekly chores and an allowance, I had a reasonable idea just what $300 or more meant. I knew that was a lot of dumping the trash and picking up dog poop, and I knew it would take me years to save up, so that's exactly what I did...I began saving for an RC airplane at age 5.

Fig. 1: My 1st RC airplane & I, age 11
Fast forward to when I was 8, and my dad told us kids that if we each spent $100 of our own money on a baby calf, he would teach us how to raise it, and he would provide it food and shelter and shots at no cost to us if we just did the work to raise our calf and pitched in to do the work to raise several for him too. After three years of hard work and waking up at 5:30am every day to feed them, we each sold our 3-yr old "springers" (pregnant females) at an auction, for something like $1100~1300 each. By now I was 11 years old. Just like I wanted to do when I was 5 years old, I followed through with my goal by spending $550 of my total money on my first Radio Control airplane, a glow-fueled Tower Trainer 40 (see Figure 1). With inflation, that is the equivalent of nearly $850 today (using this inflation calculator). That's a lot of money. Fast forward 14 years or so, and that hugely prohibitive cost of entry into the hobby is exactly what inspired me to write my ebook, "The Details of Electric Radio Controlled Aircraft, a Technical Perspective with an Economical Approach," here.

***Subscribe by Email! (via FeedBurner)***

Saturday, May 14, 2016

BattleBots Season 2 "Buzz" Fire Drone for Team Caustic Creations, with Team Interviews & fire-shooting Videos


Subscribe by Email! (via FeedBurner)

By Gabriel Staples 
Written: 14 May 2016
Last Updated: 11 June 2016
Update History:
11 June 2016 - updated article intro below, and added the big Battlebots photo below, since BattleBots just posted it a few days ago. Also added team photo & link to buy our T-shirts on the BattleBots store.

Related Articles:

I'm the creator of a fire-shooting flame-throwing battle drone (multi-copter), "Buzz," who is an air robot hexacopter companion to our ground bot killing machine, Poison Arrow, of Team Caustic Creations (see our team Facebook page here), on ABC's BattleBots Season 2 (see our BattleBots page here, buy our T-Shirts to support us here), which will air on ABC starting 23 June 2016. I'm just one of 5 members on our team. Our main bot is "Poison Arrow." Read below for some crazy-cool fire-shooting drone previews and build drama of Buzz, as well as team & bot interviews made by our sponsor, Arrow.comshowing and discussing both robots.
Photo Source:

Build drama: why's fire gotta be so complicated!?

So, from ~17 Feb. 2016 to 14 April 2016, I worked frantically to get my fire drone, "Buzz," built from scratch and working in time for the BattleBots Season 2 competition, which was filmed in Los Angeles, CA from 15-25 April. It was very very frantic indeed. It was a very difficult project it turned out, and took me approx. 300 hrs before going to the event, in addition to another 100 hrs or so spent working on the vehicle, writing more code, and competing at the event. It also just so happened to be my first ever multi-rotor I put together from scratch (but don't worry, I've been using them for years and I have a lot of background research experience with them). Zach Goff, our team captain, worked with me to size the vehicle too. Putting our experience and skills together for that part was very helpful, as was this motor and prop sizing calculator here.

I meticulously wrote a couple thousand lines of C++ code (some of which I started years ago, before I had the skills to complete it) running on the vehicle in order to give me greater control over it, for future additions and work which I hope to implement later in order to add more autonomy, hopefully for Season 3 next year. While at the event, in my frantic last-minute coding, I was even able to get a serial BlueTooth device working on the vehicle, and I implemented a custom command-line interface, from scratch, to configure parameters on-board the vehicle using my Android smart phone. I was pretty excited about that! :).

So, without further adieu, here's the result of my hard work. This is a GIF I created from a teaser trailer that ABC made for their show. This was pulled from their teaser trailer here, at approximately 1:40. The teaser is pretty awesome; you should watch it!

As you can see, the vehicle is shooting fire. turns out, was pretty stinking hard. Of my 300 hrs spent on the vehicle prior to the event (I actually logged 288.5 hrs in my project spreadsheet, but who's counting), probably *half* of that was spent just on the flamethrower. I ran into *many* problems, and each was hard to overcome. It turns out making things burn isn't as easy as one might think...especially when you need it all to be remote-controlled (RC). I had to build custom circuits, write lots of code, do some fancy programming in my Tx running OpenTx, and play with lots of hardware. Needless to say, however, I learned a *lot*...and also ruined, burned up, and destroyed some parts along the way.

***Subscribe by Email! (via FeedBurner)***

Friday, March 18, 2016

Building for BattleBots - with Team Caustic Creations


Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Written: 18 March 2016
Last Updated: 24 March 2016 - added BattleBots 2015 Championship sample video

A Few Other Articles:
Our ground robot & drone (multicopter) builds for BATTLEBOTS: follow us on social media via the links below!

(What is BattleBots? - here is a sample video below of the championships from last year)

So, aside from my IR remote-controlled car horn/siren project, about which I posted a couple sample videos previously, I have undertaken a new project recently: building an air vehicle for the hit robot fighting TV series, BattleBots, which will be hosted by ABC this year. You can see a sample episode above, which is the final championship fight from BattleBots 2015. I was not a part of that event. For BattleBots 2016, however, I will be participating by building a secondary, fighting drone/air vehicle which will fly and shoot fire.
(see some of my preliminary flamethrowing trials below)

***Subscribe by Email! (via FeedBurner)***

Monday, January 18, 2016



Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Written: 16 Jan 2016
Last Updated: 18 Jan 2016

Related Pages:

-Are you benefitting? Consider giving back.
-Is my website, code, information, etc, valuable? Consider contributing.

Hi, occasionally I get emails from people asking how they can contribute. Tools, equipment, & time cost money. Your contributions help me pay for more projects, buy better tools, get more equipment, have a higher quality of life, better provide for my family, and ultimately produce better content, to benefit you, more often. So, today I am setting up some mechanisms.

Before I continue, though, I thank you for your support!


I do my best to give you useful information, knowledge, understanding, and help on a variety of Radio Control, Arduino, and electronics topics. I strive to write outstanding articles, at a high quality, that are thorough, clear and accurate.

By supporting me, you improve the quantity and quality of my content, while saving yourself valuable time and learning interesting things along the way. I try to share useful information and project knowledge that might otherwise take you many hours to figure out on your own (it certainly took me many hours). I also frequently share and post code samples, and sometimes even full libraries. I save you time, while enhancing your life. Your contributions help me do this. Thank you!

How to financially contribute:
  • Paypal: 
    • 1) Choose an amount from the drop-down menu, then press "Add to Cart." You may then modify the *quantity* to get variable amounts. Ex: add $10, then change quantity to 3 and click "update", to pay $30.

      • Amount
    • 2) Or, click this button, then manually type in an amount on the next page, and click "update" before checking out.
  • Gumroad:
  • Patreon
    • Become a patron. Patreon allows you to pay a fixed amount for each new, significant website article or YouTube video I produce, optionally up to a maximum, fixed amount per month that you specify! This way, you only give me something if I give you something. It allows me to get a more steady income so I can improve both the quality and quantity of the content I produce: 
  • Bitcoin payments (coming later)
  • Flattr (coming later)


***Subscribe by Email! (via FeedBurner)***