Hacking the Pebble Smart Watch: Part 2 – The Pebble APIs and Runtime Environment

In our last post we took a tour of the Pebble hardware platform. In addition to the hardware, there’s the Pebble operating system and run-time environment. I haven’t found a lot of details yet in my wanderings through the Pebble documentation on the internals of what is being referred to as “PebbleOS”, but judging from what is exposed through the developer documentation it would appear to be a fairly traditional small footprint embedded O/S, bootloader and associated communications manager. If I were a betting man I’d be wagering that all this was based on a customized port of the ARM version of the Linux kernel, but I’ve yet to find any evidence of that one way or the other.

What we can conclude is that PebbleOS includes a library of functions that are made available to developers as a set of APIs (Application Programming Interfaces) that are capable of performing a wide range of tasks. As you’ll see shortly, the dev tools include header files that allow you to hook into individual routines from the APIs that will be linked at runtime when your App is loaded and run. This allows individual programs to be much smaller, as they can make use of shared code libraries that are already stored on the watch in persistent memory.

The Pebble developer documentation includes details on the current set of APIs that are made available to your programs. These include a range of graphical and user interface components, a set of what Pebbles calls “Foundation” APIs (which provide access to things like the clock timer, help with packaging and transporting data between the Pebble and your smart mobile platforms and logging functionality for monitoring and debugging your App from your smart mobile environment). There is also an implementation of the Standard C library, which provides such tools as math, memory management and string formatting routines. There’s even a set of routines that allow you to display bitmap images, text and perform simple animation.

Here’s one cautionary note – if you’re already an experienced embedded systems programmer or someone familiar with the Standard C Library you shouldn’t be surprised to find a few things missing or incomplete at this point and to be fair the Pebble folks have been pretty clear that the SDK is going to be evolving over time.

A couple of specific things I’ve noted as missing so far include not having access to all of the underlying hardware functionality and the lack of any way to save data to persistent memory to allow you to store state across shutdowns or restarts of your App. This can be a pain if users have to reenter settings each time you start the App, but it’s theoretically possible to send messages back and forth to a companion smart phone/tablet App on startup that would allow you to get around this limitation. Of course, longer term, the correct way to do this is to allow local data storage, and calls for this echo daily across the developer forum.
You’re going to want to spend some time reading through all the API docs, although it’s certainly going to be easier if you do this in parallel with checking out some of the sample programs for specific examples of each class of functions. We’re also going to be walking through a couple of specific examples later in this series, using them to show you how to set up a program and make some simple modifications to help get you started, as well.

Next up, Implementing a Pebble Program (to come…)

Hacking the Pebble Smart Watch: An Overview of the Pebble Architecture

If you’re going to start writing Pebble Apps, the first thing you need to understand is the basic architecture of your Pebble and how it fits into your current Mobile/Embedded environment.

At one level, the Pebble is simply a small but relatively powerful portable computer, capable of running applications, performing calculations and communicating with the outside world.

As with any computer, the Pebble hardware configuration starts with its CPU. The Pebble is equipped with an STMicroelectronics ARM Cortex-M3 microcontroller chip with 512k of built-in memory, a rated speed of up to 120MHz and a host of I/O options. Additional program storage is provided in the form of an additional 32M of non-volatile Flash memory, which allows your Pebble to store programs and remember things through a power off cycle. There are also multiple means of Input/Output – in the case of the Pebble, this includes an “E-Paper” display with integrated backlight (based upon a 1 1/4 inch Sharp LCD display), a total of four pushbuttons (three of which can be used in your programs), a vibrating motor (primarily used for alerting the wearer when things happen), an integrated 3 axis accelerometer and integrated Bluetooth hardware to allow automatic pairing and communication with your Android or Apple iOS smart phones and tablets.

If you’re a hardware geek here’s something you’ll likely enjoy – the folks over at ifixit.com have done a full teardown of a Pebble, showing you everything that’s on the inside. They’ve also thrown in links to the various component spec sheets. Studying these will certainly lead you to speculate on some future developments Pebble could enable, once they get a little farther along the path.

Now, not all of the integrated hardware is currently available to you as a programmer, but Pebble Central has assured the developer community that more and more functionality will become exposed through APIs as the software environment is built up and fleshed out in the coming months.

Screen resolution is a relatively modest 144 x 168 pixel resolution (backlit, but black and white only, no color) and the available application memory is rather tight (in its current release PebbleOS lets you install a total of up to only 8 apps, and none can be larger than about 25kBytes) but to put this into perspective the the original Apple Macintosh had a Motorola 68000 CPU rated at only 8MHz, a very modest 128kBytes of RAM and a quite modest 512 x 342 pixels screen resolution. Throw in the available Bluetooth link between the Pebble and your smart phone and the 3 axis accelerometer and vibrating motor and you could argue that you’ve actually got access to far more computing power than that first Macintosh desktop machine, and at a cost of $149.99, rather than the original Mac’s $2,495. Even better, it’s battery powered and can run up to a week without recharging…

Macintosh_128k_transparency

The original Apple Macintosh, another harbringer of change…

Okay, in our next post, we’re going to take a look at the Pebble APIs and Runtime Environment.

Hacking the Pebble Smart Watch: Part 2 – Getting Ready to Build some Apps

Okay, so it’s now been a couple of weeks since I began my Pebble Hacking Adventures. As I documented in my first set of postings, the first phase of my quest consisted of acquiring a watch (yup, still harder than you’d think – Best Buy’s currently sold out again throughout Silicon Valley), pairing up the Pebble with my Android smart phone, registering as a developer , finding the Pebble Developer community and and tracking down some useful sample programs and documentation.

Well, once you have all that in hand and have had a chance to study the docs and sample code a bit, it’s time to start getting your feet wet and your hands dirty.

First, let’s get calibrated – I’m assuming you’re interested in being able to develop both Watchface Apps and what Pebble calls Standard Apps for your Pebble Smart Watch (and yes, I’ll be explaining the difference between the two along the way) but I’m not going to assume you’re an experienced embedded systems hacker with years of Linux kernel experience.

This does mean that there’s going to be a fair bit of detail to absorb along the way, so I’m going to try to break it all down into some manageable, “byte-sized” chunks. (rimshot!) This will allow you to skip stuff you already know (e.g. if you’re already a competent C programmer, you don’t need a tutorial on how to declare a function or when to use a semicolon), while at the same time allowing you to more easily refer back to things you may skip in a first pass. I’m also not going to try to write it all myself, and will be providing links off to relevant sources of material as we go. My goal is to be a useful point of contact for all the info you need for your specific project, but once you’ve gone through this you’re going to want to set up a bookmarks folder with the most relevant links to sustain you once you’re into coding your own projects.

So, that’s our goal here. Now, let’s buckle up and get started…

Here’s a few first steps:

More to come…

Hacking the Pebble Smart Watch: Step 5 – Finding some useful sample programs

A Sidebar on Philosophy

The famous philosopher and well know hacker Sir Issac Newton is widely reportedly to have once said “If I have seen further it is by standing on the shoulders of giants” (of course, like so many good quotes you’ll find on the Internet, this one is apparently somewhat suspect, having been traced to a much earlier post by the French Philosopher Bernard of Chartres. Oh well, it’s still a pretty good metaphor for how we do software development, so I’m going to go with it…)

The point, for those who missed it, is that the best way to move ahead with something is to take a look at what others have done before and this is especially true in the world of software. You can spend a fair amount of time reading documentation, correcting typo and generally wasting your precious time, or you can simple grab a known-good, working example of something similar to what you’re trying to accomplish, figure out it’s basic structure and then modifying and tweaking it to bend it to your will. If you want to make rapid progress, the later approach is the only way to fly.

Mining for Gold

You may be starting to see the pattern here. The Pebble folks really want you to be working on Pebble Apps, so they’ve tried to make it as easy as possible. To get you going, they’ve put together a catolog of useful sample programs, covering each aspect of the public APIs (communicating between the watch and your phone, vibrating the watch on signal, handling button presses, etc), as well as a wide range of sample Watchface Apps for all tastes (well, enough to get you going, at least).

Now, even the best-written piece of software is useless without a development environment to build it into something that can be loaded and run on your hardware, but the follow set of examples and demo programs should be enough to give you some idea of what’s possible with the current state of the SDK and associated APIs.

Before we get too deep into this, one more caveat – the Pebble ecosystem is evolving quickly. Pebble’s been pretty upfront about what’s missing (in particular, the lack of persistent storage on the watch, and some missing APIs to such hardware features as the accelerometer) and they’ve also issued clear warning that some things are liable to change in future releases. That’s the price you pay to gain first-mover advantage, but in way of compensation you’ll also get a chance to dialog with the folks actually developing the system and get your requests for enhancements and bug fixes in early. All in all, a fair trade-off I think…

With that as a bit of background, let’s review a couple of useful places to dig up some usable code. First off, there’s the offical repositories put out by Pebble itself. You’ll find pointers to these in the official documentation, but they all live in live GitHub repos, so I’d advise bookmarking these and checking a couple of as soon as you can. Don’t worry if you don’t have a Git client installed at this point, you can navigate the source trees via the web and brad copies of what strikes your fancy. The goal here is not to choose a live project yet, just to get a feel for what’s already available so you don’t try to reinvent the wheel at this point.

So, without further ado, here are a few useful pointers to get things rolling:

And finally for this post, just to refresh your memory (and so you’ll have as many of the most useful links as possible in one place), here are the pointers again to the official API documentation and SDK, as well:

Next up, it’s time to get serious about getting yourself set up with a working software build environment and software repository. Like most things so far, it’ll be easier than you think. But don’t let me spoil the surprise. I’ll update this post with a live link as soon as it’s available. Meanwhile, enjoy your reading…

Hacking the Pebble SmartWatch: Step 4 – Finding the Pebble Developer community

Another easy one. There are several places on the net where I’ve found Pebblers in significant numbers. The forums hosted by Pebble itself are the best place to start. The general interest forums at forums.getpebble.com are a good place to find ordinary Pebble users (if there is such a beast), there’s also subforums for Pebble News, General Support Questions and even a Marketplace where you can post details of your crowd-funded projects or track new offerings to the world..

The Pebble forum site is also the most obvious place to find a Pebble developer in the wild. There are currently four major subforums that might appeal, including the Watchface SDK Install forum, the Watchface SDK Developer Help forum, the General Watchface App discussion forum (the recommended place for announcing your new Apps) and the General Developer Discussion subforum.

The Pebble subreddit is a good place to find Pebble owners, and those still working on getting ahold of one, which makes it a good place to gauge the pulse of the community. There’s not a lot of developer traffic here, but it’s a good place to let people know when you have a new App available and the Pebble folks are among the moderators and post regularly, which makes it another good place for keeping track of changes in the ecosystem.

Here they all are in table form:

Next up on the agenda will be Finding some examples of working software – Meanwhile, Happy Hacking!…

Hacking the Pebble Smart Watch: Step 3 – Register as a developer and find some useful technical documentation

First Thing on the Agenda – Registering as a Developer

This turned out to be another easy one. I had done some homework before scoring my watch, tracking down the developer support website, registering for needed accounts, etc, but this all takes time so the sooner you get started the better.

Fortunately, the Pebble folks are obviously trying hard to encourage as many programmers as possible to join the Tribe. Even if you’re not a “joiner”, you’re going to want to do this so Pebble can keep you informed about updates and to allow you to gain access to the latest documentation, copies of the SDK releases and other useful stuff.

One thing to watch out for here – home base for the Pebble developer support efforts is ”developer.getpebble.com” (and yeah, that’s “getpebble.com” and not ”pebble.com”. There’s going to be a few times along the way that you’re going to want to curse somebody because they didn’t bother to pick up the more intuitive URL, or grabbed only the “.net” domain and not the corresponding “.com”, or otherwise made it just a little bit harder for you to remember all this stuff. Life’s too short to let this get to you – just set everything up as bookmarks in your browser and move on).

Anyhoo, here are a couple of useful links to get you started:

Next Step – Find some useful documentation

If you’re just getting started in your programming career, consider yourself very, very lucky. There’s a lot to learn, but fortunately we’ve finally evolved as a species to the point where literally everything you might need for this quest is now available to you over the net. I do hope you manage to get yourself out of your chair in the next 24 hours, but if you do it wont be because you needed to go anywhere to get something you don’t have for this project (assuming you’ve already got your watch. If you don’t already have that at this point then you’re probably going to have to get out to Best Buy at some point. If you do, I definitely recommend that you call ahead as the damned things still just keep selling out…)

So here’s the stuff you really need to get yourself started:

Learning the APIs

So now you’re a registered developer, it’s time to start learning some new technology, and the place to start is with the official Pebble documentation.

To kick things off I simply printed out the Pebble guides and went through them in order (yup, I’m old school but I like to highlight things, write on the pages and generally go interactive on the content when I’m first trying to absorb something, your mileage may vary). I glanced at the API pages, but didn’t try to absorb them all at once. This proved to be a good call, as the structure of the system starts to become pretty clear as you begin digging through the sample code. Once you’ve done this a bit, you’ll find yourself referring back to the API docs as you need more details. Don’t sweat it and you’ll find yourself up and running in no time.

Remember, the goal here is to get an general idea of the state of Pebble technology to start getting it all into your head. Have a look through what’s on offer here, details of how to find some sample programs will be presented in a follow-up post. So that’s it for now. Next up, Finding the Pebble Community…

Hacking the Pebble Smart Watch: Step 2 – Setting up the Pebble to work with your Phone

After all the pain endured in finding a Pebble, this step should actually go pretty easily. To get started you’ll need to find the appropriate version of the Pebble Smart Phone App for your environment, install it on your phone and pair it with your new watch.
The Pebble Smart Watch is currently supported on two mobile platforms – Android and iOS. I’m currently using an Android-based Motorola Droid as comm device so I toodled off (yup, that’s a real word, too. Here’s proof:) to the Play Store, typed in “Pebble” and grabbed to most recent version of the Pebble Android App.

Once the App’s finished downloading, fire it up and follow the on-screen instructions to Pair and Attach the watch to your phone via Bluetooth. Once you’ve done that, you should check out what’s available under the Settings icon for some useful things you can play with (in the Android App it’s the round gear-shaped icon in the top right corner).

Here is where you can view and adjust your Bluetooth settings, select which types of notifications you’d like sent to your Pebble, twiddle with your Music player settings and most importantly, click on the Install Untrusted Apps option. This will allow you to install your own Apps once you get to that point.

That’s pretty much all there is to setting up your new baby. You’ll find it’s a similar experience with an tablet devices, as well. I confirmed with both a Nexus 10” Android tablet, as well as with both early model and more recent iPads, as well. When working with iOS devices you’ll be going through the Apple App Store, which means you might find yourself having to deal with a few Apple annoyances before you’re done. In my case I had to confirm the credit number I had on file with Apple before they would let me complete the download (yeah, even though it’s a free App) but still, it still only took a couple of minutes to find and install what I needed onto both an early model and more recent iPads.

If you have any problems with any of this setup phase, you can check in at the Pebble Forum Installation thread here:

Once the Pebble App is installed and working with your phone you can use it to send yourself some sample notifications. To do this in the Android universe, select the pull down menu at the top of the App, select “Sample Notifications” and hit the appropriate soft buttons to send yourself a few test messages.

That’s it for this section. Next up, Registering as a developer and tracking down some useful technical documentation

Hacking the Pebble Smart Watch: Step 1 – Obtain a Pebble Watch

Like any great voyage of discovery, this one begins with but a single step. In this case, that first step is actually a little harder than you might think, at least at this early stage of the Pebble adventure.
For those who somehow missed this story (yeah, we know, you’ve been under a rock for the past 18 month and wireless reception has been very poor), the Pebble story first came to the Net’s collective attention when they launched their Kickstarter fundraising campaign. For those who missed it, here’s a link.

Yeah, that’s right – they went out to raise $100,000 and were somewhat oversubscribed – to the tune of $10,266,845 to be precise…

Now, this success had a couple of knock-on effects. First, it clearly demonstrated the world’s interest in so-called wearable mobile technologies. A number of other upstarts are already making noises or demonstrating their own prototypes in this area, and more importantly quite a few famous players have been showing strong signs of jumping into the ring in the very near future. Sony is already shipping its first offering and Google and Apple are both expected to have something out before the end of this year. You can check out the Sony offering here.


But (there’s always a but, isn’t there?) none of these folks are a truly viable alternative to the Pebble just yet. Sony is the closest, with their Android-based offering, but it should really ship with a really big label with the words “caveat emptor” printed on all over it. Early adopters have been reporting significant Bluetooth connection issues and although there is lots of programming support for the general Android platform available there’s really not much of a Sony dev ecosystem yet nor any significant buzz among the developer community. Another drawback is battery life – whereas a Pebble can easily go for a week without recharging, the Sony LCD display means you have to plug it back in after just a three or four days of use (less if you’re making heavy use of the screen).

But don’t take my word for this, here’s a review of the Mark I version.

To their credit, Sony has recently announced a Mark II model which is supposed to be shipping by the Fall. Still, if you’re looking for a brand new, “ready to roll” market for your software offerings, Sony’s just not quite there yet.
And this is where the story gets “interesting” for potential developers (in the “Old Chinese Curse” sense of the word).

I believe it’s fair to say that the single biggest issue facing the Pebble market at the moment is the question of supply. The company has reached volume production and they’re building and shipping units as fast as they can, but obtaining a real live watch is still a major achievement. It’s available at Best Buy (although they’re having trouble keeping them in stock) – folks are just going nuts for it.

As a potential new recruit into the Pebble Tribe, you need to be aware of how this affects you. The fact is, there’s currently no Pebble software emulator available, so you’re definitely going to need to have a watch on hand to allow you to develop, test and debug your code. At the same time, If Pebble’s going to establish itself as the de facto standard in this game, they’re going to have to do it before Google, Apple and Sony can come in a rewrite the rulebook. If they can get enough out there to define the standard, the possibilities for a Pebble ecosystem are pretty darned good.

But…

The bottom line here is that Pebble’s Kickstarter success also raised expectations to incredible heights amongst potential customers. Those 68,929 kickstarter backers represent well over 80,000 presold watches, so when the company had some issues with their first prototypes and missed their initial ship dates some previously eager fans showed signs of serious disgruntlement (yeah, that’s a word – google it).

First units started going out to customers in January and volume production of Black Pebbles now appears to be finally ramping up to speed. Pebble HQ reports that Kickstarter orders for the full range of announced colors have been shipped (White is just hitting the market as I type this). Observers are estimating that they’ve managed to ship over 100,000 units so far and there are reports that they’ve shipping 15,000 more each week. The Pebble market is now very real and growing as fast as new units can be rolled off the line.

To help ease the pain further the company also announced the distribution deal with Best Buy for Black Pebbles, which will hopefully take some of the hassle out of the previous acquisition process (at least for U.S.-based customers). The company’s also just announce their first peripheral (a spare charging cable), which also managed to sell out its initial run within the first day. Frustrating as this might me for us early adopters, it does auger will for sustained interest from the customer base It would also seem to establish Pebble firmly as the market leader in this space (at least for now). If you’re a developer looking for new market opportunities, things are definitely looking pretty good at this point.

So, we’re not quite out of the woods yet. Obtaining a watch is still an exercise in patience (initial shipments to Best Buy sold out within a couple of days) and backlogs are still the order of the day, but given all these developments, it’s probably fair to say things are looking up. As the supply situation to ease over the summer, Pebble has a good chance of establishing its territory before the Big Guys arrive.

Now, if you don’t have one yet and want to get into the game, your best option is probably to make friends with the counter staff at all your nearby Best Buy stores. They have the needed visibility into the store’s inventory system and can tell when another batch is on the road. If they like you, they will hopefully be able to give you a little advanced notice when the next batch is on its way.
(Oh, and here’s a tip – although they’re not supposed to hold product at the counter for you when you phone in an order, I can personally attest to the fact that they can sometimes go grab one for you to confirm it’s in stock and then “take a while to return it to inventory”. Just saying…)

So that’s the story on tracking down your very own Pebble Smart Watch. Next up, Pairing up your new Pebble Smart Watch and configuring it to work with your phone

Hacking the Pebble Smart Watch: Part I – My First Week as a Pebble Software Developer

So I got my first Pebble watch (a black one) about a week ago after haunting Best Buy in the days leading up to the official retail launch date. I’ve had a red one on preorder for a while, but don’t expect to see it for another month or two, so when I heard about Pebble’s new Best Buy distribution deal I was pretty stoked. I managed to score mine on the Friday before the “official” launch by trekking up in San Francisco (about an hour’s drive from my house). It was a good day…

Once I’d manage to score one of these supposedly mythical beasts, I embarked straight away upon my first quest – getting myself to that magical moment in time and space where I would have a running program of my own creation installed and working on my new device.

Amazingly enough, I managed to do this in just a couple of days (in fact, from the time I typed my first character into the text editor to the time I had a working watch face installed on the watch was actually just a couple of hours, most of which was spent exploring the toolchain and SDK).

This first project, the “SteamCab Left-Handed Analog Watchface App – Mark I”, may not be the finest example of the Watch-makers art and may not amount to all that much in the grand scheme of things, but it does serve a useful niche market (the left-handed, counterclockwise oriented analog smart watch community) and more importantly, it taught me a lot about Pebble Smart Watch hacking and generally helped me confirm to myself that I was ready to embark upon some of the more ambitious projects I have waiting in the wings.

To reach this major milestone meant a lot of other minor milestones had to have been passed along the way. These included (in roughly the order they occurred), finding a source of technical documentation and developer support, gaining access to a working development environment and finding a way to install a completed Watchface App onto my watch. Of course, once I had a working app, I also needed a way to share it with potential users.

Of course, my voyage of discovery through the world of Pebble is all still very much a work-in-progress, but I did manage to locate some useful sources of information, found some helpful repositories of sample programs and also picked up a few a few new tricks & techniques and generally added to my store of knowledge along the way. It’s also interesting to note that when all was said and done, it turns out that compiling a working program was actually the easiest step of the trip of all (at least, so far…)

So now I’ve reached this first major milestone on my journey of Pebble discovery; the good news for those of you who are interested in embarking upon a similar quest is that I knew when I started I would want to eventually share my voyage with others, so I’ve been taking notes and capturing links along the way. Before heading off on my next adventure, I wanted to stop for a minute to take stock of what I’ve found and share it with the community. Hopefully, this will speed others along the way on your own personal voyage of discovery into the world of Pebble Programming.

A Few Steps along the Way

Here is a list of a few of the dragons I had to slay along the way before I could successfully build and install my first Pebble Watchface App:

Edit (7/30/13): Okay, have now put up the next set of posts in this series. They provide an overview of the Pebble hardware architecture and runtime environment, to help us get ready for our first Apps. Enjoy!

And here’s a list of topics still to come:

  • Set up a software build environment & software repository
  • Successfully compile my first example Watchface App
  • Make some changes to get the functionality/behavior I want
  • Find a way to distribute my App
  • Find a way to get the word out to potential users

Now, this may look like a rather intimidating list, but taking one step at a time it really wasn’t all that hard. Just be methodical, take notes, maybe even keep yourself a journal, and you’ll find yourself there in no time at all. I’m typing as fast as I can, so keep checking back here. As I finish each section, it will turn into a link to the new text.

First up, Finding a Pebble Smart Watch (it’s still harder than you’d might expect).

(About this Blog…)