Monday, July 11, 2016

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

Advertisement

Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Written: 11 July 2016
Last Updated: 11 July 2016

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.

Advertisement
Functions and code samples. Functions include:
micros()
millis()
delay()
delayMicroseconds()

View timing.py on GitHub.

#timing.py #-create some low-level Arduino-like millis() (milliseconds) and micros() # (microseconds) timing functions for Python #By Gabriel Staples #http://www.ElectricRCAircraftGuy.com #-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) -https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx 2) QueryPerformanceCounter function (Windows) -https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx 3) QueryPerformanceFrequency function (Windows) -https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx 4) LARGE_INTEGER union (Windows) -https://msdn.microsoft.com/en-us/library/windows/desktop/aa383713(v=vs.85).aspx -*****http://stackoverflow.com/questions/4430227/python-on-win32-how-to-get- 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)

END

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

Saturday, July 2, 2016

About Me

Advertisement

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:
-Intro.
-Early Days
-Family
-Education
--Master's thesis downloads
-Resume
-LinkedIn

Introduction:

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

Advertisement

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: https://www.facebook.com/battlebots/posts/10153603634031406

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. That....it 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

Advertisement

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

Contribute

Advertisement

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!

Background:

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: https://www.patreon.com/eRCaGuy 
  • Bitcoin payments (coming later)
  • Flattr (coming later)

END

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

Saturday, January 16, 2016

One of my current projects: Arduino police siren w/simple, custom transistor amplifier/speaker driver circuit

Advertisement

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

A Few Other Articles:
So, a few days ago I got a car horn *and* a car audio speaker to play a siren sound!

In these two videos, I do a quick desktop demo of playing a siren sound through first a "fixed frequency" car horn, and then through a standard car audio speaker, rated at 120W peak, 60W RMS, and 4 Ohms. Using an Arduino, a relatively simple, custom transistor-based amplifier circuit, and the Arduino core tone() function in my code, I drive the horn and speaker to play a siren sound by sinusoidally varying the driving frequency.  I also show the signal to the devices on an oscilloscope, and briefly discuss and hook up a Schottky diode in a "snubber diode" configuration to knock down the inductance-induced voltage spikes created each time the square wave has a falling edge.

First, watch the "fixed frequency" type car horn play a varying-frequency siren sound:



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

Thursday, June 11, 2015

100+V Arduino/AVR Microcontroller Input/Output (I/O) Pin Over-Voltage Protection Using a *Single* Resistor!

Advertisement

Subscribe by Email! (via FeedBurner)
By Gabriel Staples
Written: 11 June 2015
Last Updated: 2 Sept. 2015
Update History (newest on top):
-Added "Upfront Caveat", 2 Sept. 2015
-Added lots of extra info, & the Figures, 21 July 2015

Related Articles:

Here I present a pin protection method for very high and low input voltages that I learned from Atmel themselves, in their Application Note "AVR182: Zero Cross Detector."

If you've read my article titled "Arduino Power, Current, and Voltage Limitations" you know that the pin input voltage limits are as follows:
Maximum Input Voltage: Vcc + 0.5V, or +5.5V for a 5V Arduino
Minimum Input Voltage: -0.5V

However, if you simply add a single resistor in series with any input pin, you can protect it against higher or lower input voltages, with some caveats!

Ex: simply by placing a 10k resistor in series on an input pin, you get input voltage protection up to +15.5VDC and down to -10.5VDC. With a 100k resistor you get input voltage protection up to +105.5VDC, and down to -100.5VDC. Keep reading to learn more.

WARNING: 
-FOR YOUR PERSONAL SAFETY, WHEN USING THIS TECHNIQUE, I RECOMMEND THAT YOU DO NOT WORK WITH INPUT VOLTAGES GREATER THAN APPROXIMATELY 100VDC OR 20VAC UNLESS YOU KNOW WHAT YOU ARE DOING AND HAVE READ ALL OF MY WARNINGS HEREIN, INCLUDING THE ADDENDUM AT THE END OF THIS ARTICLE. 
-REGARDLESS OF WHAT INPUT VOLTAGES YOU ARE USING, YOU AND ONLY YOU ARE RESPONSIBLE FOR YOUR PERSONAL EXPERIMENTS, PRODUCTS, DESIGN DECISIONS, AND THE SAFETY OF YOU AND YOUR CUSTOMERS.

Upfront Caveat:
Though this technique may work, and be good for home-projects or quick prototyping, better techniques are recommended, especially if you are producing a commercial product. Redundancy is your friend. Using external, rated clipping diodes is certainly a better option than relying on the internal, integrated and unrated ones. For better protection techniques, including using *external* clipping diodes for redundancy, and adding transient voltage suppression, read more here: Science Prog: Using current limiting resistors on AVR I/O pins. Also see the AVR182 Application Note for references to additional sources to read in order to add extra pin protection.

Background & Concept:

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