Stephen Smith's Blog

Musings on Machine Learning…

Archive for March 2021

Introduction to the RP2040

with 11 comments


The Raspberry Pi foundation recently started shipping the Raspberry Pi Pico, a flexible $4 USD microcontroller board. This is Raspberry’s first foray into the world of microcontroller boards, typically Raspberry Pi’s are low cost complete Linux computers and the microcontroller world has been typically dominated by the Arduino line of products, which are typically based on low cost 8-bit processors. One notable part of this announcement is that the processor included on the Pico is a dual core ARM processor with the System on a Chip (SoC) being designed by the Raspberry Pi foundation. In the past all Raspberry Pis have been based on Broadcom SoCs.

This new processor is the RP2040. Not only is this processor being used in the Pi Pico, but the Raspberry Pi foundation is selling this chip to other board manufacturers to use in their own product. Already many companies and foundations that develop Arduino boards are starting to ship products based on the RP2040, but designed to fit into their own eco-system whether it is Arduino or one of its competitors. For instance Arduino, Pimoroni, SparkFun, and Adafruit have all announced either shipping or near shipping products. I haven’t been able to order a Raspberry Pi Pico yet, since they instantly sold out, but I have been able to buy a similar Adafruit board.

All these RP2040 based boards are under $10USD and all of them have lots of GPIO ports to integrate them into your hardware projects. In this article we are going to look into some of the details of the RP2040 chip itself.

RP2040 Overview

The heart of the RP2040 are dual core ARM Cortex-M0+ 32-bit CPUs that operate at 133MHz, along with 264Kb of SRAM. This may not seem like much compared to regular Raspberry Pis or other common inexpensive computers, but in the microcontroller world this is really good. Most microcontrollers are based on slower 8-bit microcontrollers with only a few k of memory, for instance the Arduino Uno operates at 16MHz and has 6kb of memory. There are a sprinkling of 32-bit based microcontrollers based on various ARM or RISC-V models, but the RP2040 is the first to take these mainstream. Keep in mind that the original Apple II operated at 1MHz on an 8-bit CPU and only supported up to 48kb of RAM, yet it was fully capable of word processing, spreadsheets and arcade like video games. The original IBM PC only operated at 4.77MHz, had a 16-bit processor and upto 640Kb of RAM. This $4 microcontroller has far more computing power than any of these early PCs, so it will be pretty amazing to see what people produce.

The ARM Cortex-M0+ core is a low energy 32-bit processor. My book “Raspberry Pi Assembly Language Programming” covers 32-bit Assembly Language programming for a full A series ARM CPU. The M series ARM CPUs for microcontrollers contain a subset of the processing units in the full A series CPUs. For instance, there is no floating point unit (FPU) and no NEON vector processing unit. Further, it doesn’t use the full 32-bit sized instructions, instead it only uses the so called “thumb” instructions which are 16 bit in size. This means there are only eight 32-bit registers for integer arithmetic and other processing (there is only room for three bits to specify a register). With these limitations, the transistor count is greatly reduced for the CPU, reducing power usage and reducing cost. Even with these restrictions, the RP2040 is powerful enough to run Tensorflow Lite.

The RP2040 is manufactured by TSMC using an old 40nm process. This greatly reduces the cost of the chip, since there isn’t much competition for this manufacturing technology. Apple’s latest chips use a 5nm manufacturing process and there is a long waiting list of companies waiting for capacity.


Typically you program the Raspberry Pi Pico in MicroPython or C/C++ without an operating system. You write your program, compile it and download it to the Pico where it runs as a single program with no operating system. The Raspberry Pi foundation offers full support for MicroPython as well as provides a C/C++ SDK that allows you to compile programs in C, C++ or Assembly Language.

If you are familiar with Arduino and how you program these, then this is exactly how you program the Pico. Which means you need another computer to run the IDE (this could be a regular Raspberry Pi). Then the Pico is connected to this computer via USB.

Of course the Linux folks aren’t sitting still, they take the challenge that Linux should run anywhere quite seriously and have already ported Fuzix, a lightweight Linux to the Pico.

This is more likely to be used for embedded type Linux applications, since connecting monitor, keyboard and mouse are a major challenge that the Pico isn’t designed for.

Will Raspberry Produce Other Chips?

It will be interesting to see if the Raspberry Pi Foundation sticks with Broadcom chips for the regular Raspberry Pis. Will the Raspberry Pi 5 be based on a Pi Foundation designed SoC? If it is, would it allow them to use newer CPU cores? Will it mean they can incorporate an ARM Mali GPU rather than the Broadcom GPU they have been using? Will there be other models of embedded chips beyond the RP2040? Evidently the numbers are significant, the 2 is for the number of cores and the 4 indicates the memory size and then the 0’s are for possible future features. We’ll have to watch Raspberry’s product announcements closely over the next year or two.


The RP2040 is exciting because it could take the microcontroller market from 8-bit to 32-bit, increasing the programming capabilities of all these DIY electronics projects greatly. Not everyone will move to this, since it will also push the price of 8-bit microcontrollers even lower. But perhaps your next microwave or toaster will contain AI software running on an RP2040.

Written by smist08

March 26, 2021 at 10:38 am

Technology Tips for the Backcountry

with one comment


As spring starts and the snow line starts to move back up the mountains, lots of people are planning their hiking and outdoor recreation goals for this new season. With COVID curtailing many of people’s usual indoor activities, we are seeing many new people out on the trails in their brand new hiking boots and other equipment. In this article, I’m going to review some common technologies and techniques to help you stay safe, avoid getting lost, and provide a way to get help if you need it.

This article doesn’t cover other things you need such as sufficient water, food, good hiking boots, warm/waterproof clothes, first aid kit, knife/multitool, bear spray, fire starter, sunscreen, headlamps, and shelter to spend the night.

Technology Breaks

Batteries die, devices can be dropped in a creek and cell phone coverage isn’t good in the Canadian wilderness. Generally it is good to have a backup plan. Knowing how to use a map and compass is a great backup. Even then compasses can fall apart, and a printed map won’t survive getting wet unless plasticized. Here are a few tips to help keep things working:

  • Cell phone battery packs are reasonably inexpensive and light. These provide a great way to recharge your cell phone or other device. Remember to charge the battery pack before a trip and to include the connector cable. Pack the cable and battery together in a ziplock bag to keep them dry. If a device doesn’t have rechargeable batteries, make sure you bring along a spare set of batteries and remember batteries fade even when not in use, so replace these every year. It’s a good idea to carry a separate headlamp or good flashlight, so you don’t need to rely on your phone as a flashlight as this won’t last long and there are more important things to do with your phone.
  • As temperature drops, the internal resistance in batteries increases, reducing their capacity. Typically a battery will only have 50% capacity at -18°C. Keep devices with batteries in your inside pockets so your body heat will keep them warm. Do not keep them in outside pockets on your pack.

  • Have a good shock resistant case for your phone, so if you drop it and it hits a rock, it is ok. Most newer phones are fairly water resistant, but a waterproof case can help. Generally try to keep your device out of the direct rain just in case.

  • Search & Rescue (SAR) statistics show that most lost people are alone. Part of this is that when hiking with a buddy or group, then you have more phones, possibly on different networks, redundancy of equipment and someone there to help if you get stuck or injured.

Let Someone Know Where You Are

If Search & Rescue finds someone within 24 hours of being lost, their chances are very good. Then for each day beyond that the survival statistics fall off rapidly. It is crucial that someone knows where you went and when you are expected back. If no one notices you missing for a week or they don’t know where you went, it can be a life threatening situation. Searching all the trailheads and forest service roads for your car is time consuming and often takes days.

If you hike a lot, just casually telling someone where you are going is probably insufficient. They could easily forget, not really know when you are expected back, confuse the latest hike with a previous hike or not really know which trailhead you went to. A better way is to email or text a message to the person, so they have something to look up. Make sure you include the exact trails you are doing, who you are going with, when you are starting, the trailhead you are parking at and when you are expected back and when to consider you overdue. If your plans change, cancel the hike unless you can update them. It’s a good idea that someone knows what equipment you travel with so SAR knows your capabilities.

There are a couple of apps to help with recording where you are going, that Search & Rescue can also tap into:

AdventureSmart Trip Planner: This is a great app to record the information for your next trip.

Overdue Trip Plan: Another trip planner app, that automates notifying your contacts and includes some offline map and navigation capability.

Prepare to be Offline

If you live in the city, you are used to your mobile phone always working. You can call, text, email or facebook anytime without thinking about it. You don’t have to head very far outside of the city into the backcountry before this stops being so reliable. Even if you can see a large cell phone tower up on the mountain above you, you still may not get coverage. Often when you do a longer hike you will go in and out of coverage as you go up and down and the terrain closes around you or opens up. Here are some tips to deal with being out of coverage. These are both to help you navigate as well as being able to call for help if you need it.

Use 911 to Call for Help

If you need help, call 911 rather than calling a friend. Even if your phone is out of coverage, 911 might still work because it will use any cell network, not just the one you subscribe to. Further the 911 call will include your GPS position, helping SAR get to you directly without having to mount a major search.

Offline Maps

Google and Apple Maps only work when you are online. Besides that they are terrible when you are in the backcountry. They don’t have many trails or landmarks and usually make it look like you are in a green desert. Make sure you use an App with trails, backcountry details and that it downloads the maps to your phone so it can work when out of coverage. Trailforks is a good choice here. More full featured GPS apps like Gaia or ViewRanger are great, but you need to purchase a yearly subscription to download their maps. Another option is to use a standalone GPS such as one of the many Garmin ones.

Satellite Devices

If you really need to stay online, you can purchase a satellite phone. The downside to these is that they are quite expensive and their data plans make regular cell plans look cheap. These are great devices, and will work in many places where cell phones won’t work. But they don’t work everywhere, they need line of sight to their satellite and hence won’t work in gulleys, some valleys and dense vegetation. The good thing is that you usually don’t need to travel far to get reception, on the other hand if you are stuck, you can’t call for help.

 A cheaper alternative are devices like SPOT and InReach. These are satellite devices that can send a selection of messages through the satellite network, but don’t have general communications capability. You can use these to send ok messages, SOS messages as well as let people track your progress on a hike. The subscription fees for these devices is a lot less than full satellite phones and you can often get a discount by calling them.

If you are using one of these devices, they have the capability to track your progress to a website and if you let people know the URL for this map, they can see where you are in real time. If you have one of these devices, make sure you turn on trip tracking at the start of every excursion. This is in case you get in trouble and can’t hit the SOS button, perhaps you fall and hit your head, perhaps you get stuck in a gully. Then SAR can use this map to know your last known position in much greater detail. Chances are you are located at most a ten minutes walk from this last plotted point which allows SAR to find you quicker than starting the search at your car.

Other cell phone apps like Strava and ViewRanger have this capability but can only report when you are in cell coverage. This can still be helpful, as if you are going in and out of coverage it might provide a better last known position than your car helping searchers get to you quicker.


Whenever you travel into the backcountry you need to be prepared for any eventuality. Weather changes quickly, even a minor fall can hurt your ankle, greatly slowing you down. This article just touches on a few things that can help make your outdoor activities safer and give you peace of mind to enjoy the environment.

Written by smist08

March 19, 2021 at 11:10 am

Some Useful Phone Apps for Search & Rescue

with 2 comments


Cell phones have become extremely useful tools for Search & Rescue (SAR) groups providing all-in-one functionality for GPS, maps, camera, communications, reference manuals and even provide an emergency light. This article lists some useful apps to have on your phone to help with SAR activities. Of course, you don’t want to 100% rely on your phone since batteries fail and all equipment can fail in the difficult environments we operate in. That being said, newer phones have longer battery life, are waterproof (to some degree) and in a good case are fairly durable.

Weather and Conditions

WeatherCAN: There are lots of good weather applications as well as the one built into your phone. I like WeatherCAN, but there are lots of good alternatives.

AvalancheCanada: In winter, checking avalanche conditions is crucial to your team’s safety. The Avalanche Canada app is the good one and you should always check the conditions before heading out. Further, be sure to use the app to report conditions as you travel in avalanche terrain.

BC Wildfire: In the summer, there can be wildfires affecting our searches, whether causing us to avoid areas or having our search area obscured by smoke. This app is a good way to keep an eye on what is going on.

First Aid

BCEHS Handbook: This handbook has all our treatment guidelines, so if you have a first aid situation and need to look something up, this is a handy tool to have. Further it saves weight on not needing to have printed books in your pack.

AED: This app lets you locate the nearest AED if you are handling a heart attack. Useful for urban searches as well it is handy outside of SAR.

First Aid: This is the Canadian Red Cross app which contains lots of useful information on common simple first aid procedures.

CPR Tempo: The rate of performing chest compressions is fairly fast and you need to keep it up, even as you get tired. This app is a simple way to get beeps at the correct rate to keep you steady.


Avenza Maps: Most SAR management packages can produce maps in PDF format. Typically, they will mark the search areas on the map and then issue it for the teams. They then send out a QR code which you can scan into Avenza Maps, download the map and use it to do your navigation. I’ve used this on several searches and it is a great way to divide up an area for the individual teams.

Gaia GPS: I blogged on Gaia GPS last week. One of the good general GPS programs for phones.

Trailforks: Is a simpler navigation program than the full GPS apps and is really great for having all an area’s trails covered. New trails usually show up in Trailforks before anywhere else. Also many groups use Trailforks for reporting trail conditions, so a good place to check on these. I’ve often used this on searches to see all the mountain bike trails, which were missing from the official map I was following.

TrailMapps Sunshine Coast: Often there is a specialty app for your area, in this case a specialty Sunshine Coast trail app which I’ve found useful.

OsmAnd Maps: This is quite a good navigation tool. It is free and anyone is able to update the maps. I find this is good for things like hydro access roads and other obscure, but not official things that can be used as trails.

ViewRanger: is another full featured GPS program like Gaia. I liked it because the yearly subscription was cheaper, it was easier to use a variety of GPS coordinates and is easy on the phone’s battery when recording a track. It recently merged with outdooractive, so I’m not too sure what its future is now.

Strava: This is an app used by athletes and others to record their physical activities. This is useful for SAR, since if a subject uses Strava then you can get a clue as to where they like to go. Strava also can create a heatmap of where people record, and then search managers can use this when calculating Probability of Area (PoA).

The Strava Heatmap for the Gibsons Area

Utilities & Reference

Inclination: This app lets you use your phone to measure a slope’s inclination. This is useful when judging avalanche risk. It also is important to know when you need to use a safety line on a stretcher when the slope is greater than 20°.

BCSARA Mobile App: This app contains all our BCSARA reference material. It also has utilities to convert between GPS coordinates as well as providing a compass.

RADeMS: Response Assessment and Decision Making Support is our standard tool for evaluating risk. You answer a set of questions on what you are contemplating and get back a risk score to help with your decision making.

YouTube: If you are stuck on something, chances are YouTube has a video to walk you through it.

Phone Builtin Functions

Flashlight: the phone’s builtin flashlight can be useful if your other light sources have failed, but use this as a last resort since your battery is better served for other purposes.

Messenger: Your phone’s texting app is a great way to send in photos and other info to command if you have cell reception.

Camera: Make sure you take a picture of any clues.

EMail: Another low priority communication mechanism.

Compass: a quick way to see your direction and to copy your GPS coordinates to the clipboard (to paste into say messenger).

Maps: Often Apple or Google maps are best for urban searches.

Browser: If you are online, you can look up pretty much anything.

Clock: Set timers and alarms. Perhaps to remember to check in with command.

Phone (and Facetime): often best to phone command. Especially for confidential info when you don’t have a secure radio channel.


Modern cell phones are amazing devices and if there is some sort of use you can think of, chances are someone has already created an app for that. Most (but not all) of the apps mentioned here are free. I’m sure there are tons more useful apps and would love to hear about them in the comments below. However, you don’t want too many apps, as it’s better to have a smaller set of apps that you regularly use so you are familiar with them and don’t have to figure out something new when you are in the middle of a stressful SAR call.

For SAR make sure you can make do when you are offline. You don’t want to rely on having good cell coverage.

Written by smist08

March 12, 2021 at 11:05 am

Using Gaia for Search & Rescue

with 2 comments


Gaia is a navigation program for Apple and Android smartphones. It mimics the functionality of standalone GPS units, but then adds functionality utilizing the extra capabilities most phones include these days. There are lots of articles and youtube videos on how to use Gaia for trip planning and following trails and I won’t cover that here. This article is more about the use cases that Search & Rescue (SAR) teams typically use in a GPS. This article assumes some familiarity with using a standalone GPS and SAR practices, and then very little knowledge of Gaia. I use an Apple iPhone 11, so this article will feature screenshots from the Apple version, but the Android version should be similar.

Installation & Setup

You need to install and set up Gaia first before using. You don’t want to do this part at 3am on a callout. First you need to install Gaia GPS from the Apple App store. Search for “Gaia GPS” and then press the “Get” button to install it.

My screen says Open rather than Get because I already have Gaia installed.

Notice the second item is a subscription for more stuff. The crucial part for SAR is offline access. With the free level, you cannot download maps to use the program when you don’t have a cell data connection. For SAR this is a showstopper. If a SAR group uses Gaia, it probably has a team license and SAR management can provide you with a link that will connect you to the SAR account.

Create Account

After you install Gaia, the first time you run it, you will be prompted to create an account or link to your Facebook account. Use either method to create your Gaia account. This will give you basic access to the program. If your SAR group provided a link to click to connect to their account, you can do that now to connect your Gaia account to the SAR account to get full access. If you don’t have this, then you will need to buy a premium subscription account.

Download Maps for Offline Use

The next thing to do is to download a map of your search region so you can use Gaia offline. The default map is Gaia Topo which is fine for most purposes. If you want to use a different map or set of overlays, you need to select these first before downloading as this process will only process the active map. To download the map, click the ⊕ symbol at the top of the screen.

Select “Download Maps”. This then goes to a map with a resizable rectangle that you can expand to your entire search region. In my case the Sunshine Coast:

You probably also want to do this for any regions you travel to for mutual aid, in my case I’ll download Powell River, Squamish, Whistler, Pemberton and the North Shore. I’m not going to talk about overlays in this article, but if you want these included, they must be selected and active before you choose to download. The file downloaded can be quite large so you need some space on your phone. I would recommend having 1Gig free for maps, which if you have a newer phone, shouldn’t be a big deal. Also perform the download while connected to a good Wifi connection so it is faster and you don’t use up your monthly data cap. If maps overlap, Gaia is reasonably smart and won’t download duplicate data so you don’t need to be careful in how you tile these (ie there is no penalty for overlapping maps).

Configure Units

Next go into “Settings”, the important part is that the units are correct for your purposes.

In SAR, you will probably need to return to this menu repeatedly. Often on a search we need both UTM and lat/long coordinates and have to return here to switch back and forth. If we are working with Marine SAR then we may want to use nautical distance units for that particular search. If we travel to the US for mutual aid, we may even need to use Imperial units.

Power Saving

You should also check the power options. I turn off the option to keep the screen on, as this wastes battery. I need to record tracks, but for the most part my phone lives in my pocket and I’m not looking at the screen.


As you use Gaia, your phone is going to ask security questions, which you generally want to allow. A key one is you want to allow Gaia to always be able to access the GPS, if you choose the option to only access the GPS when using the app, then you are going to have holes in your GPS tracks when you switch to other apps, say to send a message or answer an email.

Basic Usage

Recording a Track

SAR Management always requires a recording of where you traveled so these can all be combined in a master map showing search coverage. The standard for providing these is a GPX file. There is an “Record” button in the upper left of the screen. Remember to hit this before heading out on your search. When recording it changes to a timer showing how long it’s been recording. When you return to command, tap this box again and choose “Finish Track”. It’s a good idea to give this track a meaningful name on the next screen. It will then show you the track. Tap the three dots in the upper right to get a menu:

Select export and then GPX. Next choose eMail and enter the email address of your SAR manager. Much easier than doing this with a standalone GPS.

If you want to include pictures with this file, then you need to save the track and all the pictures in the same folder. To do this create a new folder before starting out and then save everything for the day to this folder. This may or may not be helpful.

Getting my Position

Of course you can get your current position from the phone’s compass app, this is handy to copy to a text and send, but is in lat/long and not very easy to read out over a radio. In SAR we tend to use an abbreviated form of UTM coordinates, so we can give our location over our radio using six digits. You can configure Gaia to show your location by tapping one of the three info boxes at the top and choosing coordinates in one of them.

Then on the radio, I can give my position as 632733. In reality, our radios transmit our location back to command on a regular basis, so I haven’t had to do this on a real callout, but this was frequently requested during training exercises.

Setting a Waypoint

If you hit the ⊕ sign at the top of the screen, you have two ways to create a waypoint.

Scenario one is to enter a marker of where you found a clue or a point you want to make note of for some reason, in this case choose “Add Waypoint (My Location)” and then enter a meaningful title and description.

The other scenario is SAR Management radioing you and asking you to go to some point on the map. The easy way to do this is to hit plus, choose “Add Waypoint”, then the next screen defaults to your current coordinates, that you can edit to the coordinates you’ve been given. Next enter a description, then the waypoint will appear on the map and you can figure out how to get to it.

Once you create a waypoint, if you tap it, you can tap the info icon and open it, from here you can add notes, or even ask Gaia to guide you to the waypoint. You can also edit the waypoint if you need to move it or rename it.


This was a quick start to Gaia for SAR practitioners. Gaia is a large and sophisticated program, where we only touched on a few aspects of what it can do. The best way to learn a program is to use it and to experiment with it. You don’t want the first time you do something to be during a stressful search in the middle of the night. Gaia isn’t meant to completely replace standalone GPS’s, but a key to SAR success is redundancy so if one piece of equipment fails, you aren’t stuck. Often the cell program is easiest to use, since it has extra functionality like being able to email your track in to command.

Written by smist08

March 5, 2021 at 11:36 am

Posted in Uncategorized