Stephen Smith's Blog

Musings on Machine Learning…

Archive for February 2021

Programming an Apple Watch

with 4 comments


A cool thing about the Apple Watch is that it’s really a full ARM based computer running a Unix derived operating system that is fully programmable. Although most Apple Watch owners will never write programs for their Apple Watch, as they never write programs for their iPad or iPhone, it is entirely possible to do so using Apple’s Xcode development environment running on a newer Mac. In this article we’ll look a little at the powerful computer that is the Apple Watch and give an idea of how programs or Apps are developed.

The Platform

The Apple Watch contains a whole lot of processing power, combined with a ton of sensors and a nice retina display all packed into a very small package. The processor is a dual core 64-bit ARM CPU with 1Gig of RAM. In the Series 6 watch, these cores are low energy cores from the iPhone 11’s CPU. There is also 32Gig of storage for Apps and data. There is even a mini PowerVR GPU. The touch sensitive display is only 1.78”, but still has a resolution of 448 x 368 pixels. 1Gig may not sound like much RAM, but remember that all the Raspberry Pi’s up to the 3B, only had 1Gig of RAM and ran a full version of Linux quite nicely. For connectivity there is WiFi, Cell, Bluetooth and ultra wideband.

The sensors include: accelerometer, gyro, heart rate, barometer, always-on altimeter, compass, GPS, microphone, SpO2 and VO2max.

That’s quite a bit of computer packed into a small package only weighing 48grams.


The Apple Watch’s operating system is WatchOS which is based on iOS. Programming for WatchOS is pretty similar to programming for iOS and in fact you use the same tools. There is a WatchKit API for watch specific functions and you should keep in mind the Watchs UI limitations when creating Apps. For instance, even though you can do text entry on the watch, you have to draw each character or use the built in speech to text interface, i.e. there is no keyboard.

Typically you develop a WatchApp in parallel with an iPhone App, where the iPhone App provides configuration, setup and does much of the work allowing you to minimize the interface required on the watch. Xcode makes creating these dual Apps easy and in fact you can have separate heads for the Watch version, the Apple TV version, the iPhone version and the iPad version.

In my book “Programming with 64-Bit ARM Assembly Language”, I create a simple iOS App that has a text box, where you enter some text and then it calls an Assembly Language routine to convert the text to uppercase. Alex vonBelow took this example and added support for both the Apple Watch and AppleTV. The Github for this is available here and this program is in Chapter 10.

For most work, you debug by running the application in the iOS/WatchOS simulator. The nice thing about my new ARM based Mac is that the simulator is quite fast, since it doesn’t have to simulate running an ARM CPU on an Intel processor, instead everything is ARM and works quickly. Below is a screenshot of running this uppercase app for the Apple Watch.

The cool thing is that if you know how to write iOS Apps, then you already know how to write Apple Watch Apps (as well as AppleTV Apps). Besides writing code in Objective-C or Swift, you can even write code in 64-bit ARM Assembly Language. Xcode makes it easy to provide separate appropriate screens for each device.

There are tons of books on how to write iOS Apps and all that knowledge works across all the Apple mobile products. The key thing for the Watch is that the UI should be mostly informational and any UI should be limited to just a couple of buttons.

Programming with Objective-C or Swift using the iOS frameworks is fairly complex, it would be nice if there was something simpler like a version of Scratch for WatchOS or a command prompt App, like the one for the iPhone. But at least Xcode creates a reasonable skeleton working App when you create a new project.


The Apple Watch is quite a powerful little computer in its own right. You can program it from Xcode and use nearly all the tools you use for iOS development for the iPhone or iPad. It’s really amazing how much computing power, connectivity and sensors are stuffed into the small watch package.

Written by smist08

February 26, 2021 at 10:40 am

State of Software on Apple Silicon

leave a comment »


Apple Silicon ARM based Macintoshes first shipped back on Nov. 20, 2020. We are now three months later, so I thought I’d review the state of software on these new Macs. Whenever a vendor changes the CPUs in their computers there is typically a lag between the hardware shipping and then software becoming available for the new platform. Apple took a number of extraordinary measures to try to eliminate this lag, to have a lot of software available when the first real hardware shipped. In this article we’ll look at what is available now, what is missing and how the journey seems to be going.

Rosetta and the Early Adopter Program

Knowing that software would be a problem when Apple switched from Intel to ARM for their Macintoshes, they worked hard to produce an excellent Intel emulation program called Rosetta. This allows most Intel based MacOS programs to run as is on the new hardware. I found this to work really well, with a couple of exceptions. One problem is battery life, when I first received my new MacBook Air, there wasn’t a native general media player yet, and running the Intel version of VLC would drain the battery in a couple of hours. Since then a native ARM version of VLC has been released and I’m able to play videos all day without recharging. Another problem is that Rosetta doesn’t emulate Intel AVX vector processing instructions and this prevents some machine learning libraries from running. However, I found most things did work and hence I could get everything I needed done, done.

The other thing Apple did was seed developers with an early prototype Mac Mini using an iPad Pro’s ARM CPU and a beta version of MacOS Big Sur. This allowed developers to get a jump on porting their applications to the new platform. The downside was that this hardware cost US $600 and you had  to sign a heavy nondisclosure along with agreeing to return this hardware when the real thing shipped. This limited the program to mostly larger companies who could easily afford this. At the end Apple provided a $500 Apple store credit if you returned the unit and if this was known at the beginning, more people might have participated.

Native Applications

There are now a large collection of native Apple Silicon applications available including Microsoft Office, Google Chrome, VLC Player and Zoom. Others such as Adobe Lightroom or Parallels virtualization software are available in beta. There is a list of native applications here.

Of course all Apple’s applications are available for the M1 chip including Xcode which gives a pretty robust starting point.

Porting applications from Intel to ARM appears to be fairly straightforward and expect any missing applications (as long as they are still actively developed) to show up soon.

MacOS is based on Unix as is Linux and Mac users are used to all the various Linux applications having MacOS versions as well. A great place to get these is from one of the MacOS package managers like Homebrew. Homebrew has ARM native versions of most open source programs, including GCC and lots of Python libraries.

Xcode installed the LLVM compiler collection and then with GCC you can download and build most open source projects if you really need to, but chances are the folk at Homebrew have beaten you to it.

Another source of native Apps are iOS iPad and iPhone apps, many of these will install on the new Macs and for a lot of things are the best way to go.


If you want to run Linux or Windows on your new Apple Silicon Mac, one way to go is via virtualization. Parallels has a beta version of their software for Apple Silicon and I gave it a try and got a virtualized copy Ubuntu Linux up and running without any problems. The target operating system has to be 64-bit ARM based, which means you can choose from quite a few flavours of Linux.

Although bootcamp isn’t supported on the new Macs, you can run virtualized ARM based Windows using Parallels, but this version of Windows is only available through the Windows Insider program.

Other Operating Systems

There is a large contingent of Linux developers working hard to get Linux running natively on this new Apple hardware. Correlium has Ubuntu Linux running natively, booting either from the SSD or from a USB drive. This version supports much of the new Apple hardware, except it doesn’t use the GPU at all. Asahi Linux is working hard on GPU support, but that is a big job.

Apple is making this job hard but not providing documentation on the low level hardware interfaces, but people are making good progress reverse engineering MacOS.

The good news is that it is possible to run other OS’s like Linux and over time we’ll hopefully see other operating systems in addition to Linux ported as well.

What’s Missing

The big thing missing is support for the GPU and TPU. All the libraries that utilize GPUs for acceleration, won’t use the Apple GPU. This is a huge advantage that nVidia has, that nearly every machine learning library supports acceleration on nVidia GPUs, then next, but still lagging is support for AMD GPUs. 

Apple wants everyone to use their Metal API to access the GPU, but the problem is getting people to do this. Apple has taken a branch of Google’s Tensorflow and is adding Metal support themselves, but they have a bit of a tough road ahead to get good support across the board. They could try to help organizations like OpenCL write their drivers, but I think this will take time.

Another thing is to sort out the installation of systems like Python where there are hundreds of add-on libraries. There are lots of conda virtual installs for the new M1s but most mix and match installs are still a pain, and nowhere near as painless as they are on Intel based MacOS or on Linux.


There has been huge progress in porting software to the new ARM based Macs. There is still work to do, but it appears the new Macs are selling well and there seem to be lots of developers acquiring these new Macs. Anyone serious about iOS development wants these as it is so much easier having your development system running the same processor as your target. The missing pieces are becoming more and more obscure and most of the holes can be filled with programs running under Rosetta. I use my new MacBook for pretty much all my work and find everything I need already there and working really well.

Written by smist08

February 19, 2021 at 11:13 am

Posted in Business

Tagged with , , , ,

Labists Raspberry Pi Kit Review

with one comment


In December, I entered one of those web contests where you like something on social media and for each different like you get an entry to a contest. In this case, the contest was by betanews and the prize was one of three Labists 8Gig Raspberry Pi Starter Kits. The kit includes the Raspberry Pi, a microSD card with Raspberry Pi OS installed, a case, a fan and all the cables you need. You provide a keyboard, mouse and monitor and away you go with a full desktop computer.

Unboxing & Assembly

It came in a sturdy compact cardboard box with cardboard pieces inside to hold everything in place. Each piece was individually wrapped in plastic, which I thought was unnecessary and wasteful. There was a small assembly manual, but it was insufficient and mostly sent you to a youtube link. The problem was that it sent me to the link for a different case, so I needed to google the video for the correct case. The key things you need from the video is which three chips to put the sticky stuff on to attach to the fan and then which two GPIO pins to attach the fan leads to. Everything else was pretty obvious and easy to assemble. The video showed installing the screws with a magnetic screwdriver, but the screwdriver included in the kit wasn’t magnetic and it was too fiddly to install as shown in the video. However, it was easy to start the screws in the fan and then drop the fan in and then tighten the screws.

The Labists box and setup manual.

With all that, I had everything assembled in less than half an hour and turned it on booting into Raspberry Pi OS. Then you answer a few setup questions, namely your timezone and set a new password. After that Raspbian does an operating system update, which took perhaps 45 minutes, then it asked for a reboot and after that I was all up and running.


I bought a 4Gig Raspberry Pi 4 when it first came out. I also bought a kit because the cables were all different from the Raspberry Pi 3. The big problem was that when the Pi 4 first came out, the case vendors didn’t realize that ventilation and cooling were a much bigger issue than for the Pi 3. The case my original Pi 4 came with didn’t have sufficient cooling and ended up not using it as there was better ventilation just not having a case. This case/fan combo is well thought out and provides plenty of cooling so I can use it and so far everything is running well. As an added bonus the dual fan has LED lights that change color as you go along. A huge improvement over what I had before.

A common criticism of the Raspberry Pi is that there is no power switch. The Raspberry foundation says this saves a bit of money and is key to keeping the low end model down at $35. Typically, I connect the Pi and its monitor to a power bar with a switch and then use the switch on the power bar to turn it on and off. The Labist kit’s power supply has a switch on the coard near the Pi unit, this switch is similar to what you find on many lamp’s power cords and I find it really convenient. 

The Raspberry Pi can drive two monitors and this kit came with two video cables, so you can do this without having to order the second cable separately. There are also a number of extra screws and spacers to help attach some of the common addons like breadboards or cameras.

My original 4Gig Pi runs pretty good, previously I had a Raspberry Pi 3 which had 1Gig RAM. The Raspberry Pi 3 would often bog down as it ran out of memory when you accidentally got too many programs running. The 4Gig in the Pi 4 fixed this for me and allowed the Raspberry Pi to run full 64-bit versions of Linux such as my favorite Kali Linux. I haven’t had a chance to stress this new 8Gig Raspberry Pi, but I expect I can run even more programs at once as well as run larger data files.

What Do People Use Raspberry Pi’s For?

The Raspberry Pi is an amazingly small and inexpensive, but powerful desktop computer. It runs Raspbian a version of Linux optimized for this hardware. What do people do with these? Here are a few common uses:

  1. Learning to program. The Raspberry Pi runs pretty much every programming language and is a great place to learn programming.
  2. Browse the Internet. The Pi runs many browsers including Chromium and Firefox for excellent browsing. The Pi has built in Wifi as well as a plug for hard wired Internet.
  3. Perform common office activities like writing, spreadsheets or presentations. It comes with LibreOffice pre-installed and this provides most of the functionality included in Microsoft Office. You can also run the Google online office apps in the browser.
  4. Use it for custom hardware control and programming. The Raspberry Pi has its flexible GPIO ports that can be used to interface the Pi to home automation hardware, control greenhouse watering, lighting and heating systems, control inexpensive robots and much more.
  5. Use it as a Pi-Hole or DNS server.
  6. Use it as a media center.
  7. Use it for gaming. There are amazing retro-gaming systems for the Raspberry Pi, if you buy an inexpensive USB game controller you can run pretty much any retro gaming console or PC game on the Pi.

The Microsoft Controversy

There is a recent controversy with the Raspberry Pi calling home to Microsoft which has pissed off quite a few open source purists. What this is, is that the Raspberry Pi OS now lets you easily install Microsoft Visual Studio Code from its package manager and rather than hosting the code in a Raspberry Pi repository, it directly accesses the Microsoft repository. You can see this being accessed in the following screenshot.

This is a convenience as it is another development environment you can learn on the Pi and there is a lot of good functionality there. However it means every time you check for updates, a Microsoft server is pinged. This means Microsoft can gather the IP addresses of every Raspberry Pi, mostly allowing them to know how many Raspberry Pi’s there are out there. Anyway, if you don’t like this, you can edit the list of repo’s checked or use an alternative version of Linux such as Kali or Ubuntu Linux. I’m not too upset about this, but I do think it looks strange seeing Microsoft referenced every time you do an update.


The Raspberry Pi 4 is an amazing inexpensive but powerful desktop computer. There is tons of software that runs on the Pi and the internet is full of hardware projects you can use the Pi with. The Raspberry Pi 4 was originally released in June, 2019, originally there were a few software problems and overheating problems. Since then all those problems have been fixed and the various Pi kits have been refined with better cases and power supplies. Certainly if you are looking for a complete Raspberry Pi kit, Labists makes a good choice.

Written by smist08

February 12, 2021 at 11:11 am

Apple Watch Series 6 Review

with 3 comments


I recently celebrated another birthday and the present from my wife and some of her family was a brand new Apple Watch Series 6. Basically an Apple Watch is a little tiny iPhone, specialized to be a watch, but like an iPhone it can run Apps and has a lot of computing power. In this article we’ll discuss some of the watch’s salient features and I’ll give my initial impressions.


Sadly Apple uses UPS for shipping, so the watch arrived a few days after my birthday, I already complained about UPS quite a bit here. Unboxing consisted of removing the Apple packaging from the UPS packaging, removing lots of plastic wrap and opening the cardboard boxes within. Inside was the watch, a strap and a charging cable. There were the usual legal bits of paper warning about not changing the battery yourself and beware the choking hazard. There was a piece of paper with a picture and one sentence in 27 languages on how to put the strap on, turn it on and find the user manual on the Apple book store. Installing the strap is easy and it’s designed to be easily interchangeable, which is a nice improvement over my previous Garmin GPS watch where changing the strap was a real fiddly struggle.

Following the instructions to turn the watch on didn’t work, so I attached the charging cable, plugged it in and saw there it was 0% charged. The charging cable has a magnet on one end to attach to the back of the watch and the other is a USB-A connector. There is no included USB-A to AC power plug. Fortunately I have lots of these. Also I’m writing this on a new MacBook Air which does not have any USB-A ports, only USB-C ports, so without a hub, can’t be used, which I found strange that it didn’t come with a cable that would work with other Apple products.


After charging for ten or fifteen minutes, the watch had enough power to work while on the charger. To set it up, you use an iPhone, I have no idea how to do this if you don’t have an iPhone. Basically, if your iPhone is near the watch it detects it and launches the watch app. Then the watch displays a swirling pattern that you point the iPhones camera at. Once you have it correct in the field of view, the phone is paired to the watch. Then you use the iPhone App to go through the various setup steps, which is mostly confirming the EULA and how much access you want the watch to have to your stuff. You can skip most steps and set them up at any time from the App. I chose most of the defaults with a few exceptions:

  • I chose to manually select which Apps to download, otherwise it will install every App on your phone which has an iWatch version.
  • I didn’t enable the feature that would call 911 if the watch detects me falling. I’m worried about false alarms, and so far when I’ve fallen, I’ve been able to get up again.
  • I didn’t enable credit card payment. The watch has NFC and you can wave it over supported credit card devices to pay, but so far I haven’t integrated credit card payments to either my phone or watch.

Once done you are good to go. The watch takes about an hour and a half to fully charge, so when that was done I could put it on and tell time.


The screen is easy to read, it’s always on, but it brightens when you tilt it towards you. I like the ease with which it measures heart rate, I’ve used lots of sports watches with the separate chest strap and those are such a pain that I rarely use it. There are lots of watch faces to choose from and you can easily customize any of them, however figuring out the correct thing to get what you want can be tricky (like displaying your heart rate rather than the heart rate App symbol). Apple hires good graphic designers, so all the faces are appealing and it’s a matter of choice whether you like lots or info or something clean, whether you like analog watch hands or a digital display.

How to run Apps baffled me at first, but once you get the hang of it, it is easy. It helps if you remember the icons of the Apps you use.

The watch is intrusive in some surprising ways, for instance if you don’t get up and move around every hour, it will bug you to do so. Similarly, it can be a bit aggressive on trying to get you to exercise. I’m often surprised by a new beep and notification from the watch. For now I’m ok with it, but I suspect in a week or two this will get old, and I’ll have to figure out how to turn some of these off.

The reason my Garmin watches failed, was that over the years their batteries held less and less charge. My current Garmin started off being able to track a hike of about six hours, but each year it got less, next I couldn’t record a hike, but a two hour bike rides was still ok, and recently it’s a bit problematic even recording a 45 minute run, So far the Apple Watch seems to be able to go for a day and a half between charges. I’m happy with this and I’ll be even happier if this keeps up for a number of years.

There are a lot of upsells associated with the Apple Watch. The Apple fitness App gives you basic functionality on your phone, but wants you to pay $13 or so per month for fitness+, so you have to say no to this a few times. Similarly the Strava App gives you basic functionality, but wants $80 per year for advanced things, the main thing missing being heart  rate tracking (but the basic Apple App does do this). So far I’ve avoided any of these upsells, but I might try the three month free trial for fitness+ at some point.

It would be nice if there were iPad versions of the iPhone iWatch Apps, but either there aren’t or most functionality is missing. It would be nice to be able to use the larger screen, but oh well.

After the first night, when I picked up my watch it complained that there was a new version of WatchOS, but it didn’t install since the watch wasn’t on the charger. No big deal, the next night I put the watch on the charger and went to bed. In the morning it had another error that the install failed because my iPhone wasn’t close enough to the watch. Anyway the third time was a charm, not really sure why the phone needs to be near the watch, since the watch does WiFi.


The Apple iWatch is a fun toy, I like that my watch tells me how much time I have until sunset and what my heart rate is. I’m not sure if this is legal, but I can glance at text messages while driving on my watch. I like the strava App in that I can start/stop activities and see my progress without getting my phone out of its exercise case. I’ve only had it for a couple of days, but I’ll write an update once I’ve been using it for a few weeks.

Written by smist08

February 5, 2021 at 4:57 pm

Posted in Business

Tagged with , , ,