The Sports Clock – Update #2

I’ve started working on the software aspects of the sports clock. The code for the sports clock are in three parts:

  • iOS App
  • Spark Core code
  • Node.js Backend

To store the data for each clock, I’m using Parse (soon to be shutdown so I need to migrate the database when I have more time).

Screen Shot 2016-03-26 at 2.16.50 PM.png



The Node.js backend code listens for events emitted by the Spark Core. It then fetches from the database the MLB team that the user wants to get scores for. Then,  I use the MLB API to get the scores for any live games where the team is playing.

The MLB scores api is at For every day, there is a file named masterscoreboard.json that contains all the games for the day.

For example, on March 26, 2016, the masterscoreboard.json would be located at

You can then search through the JSON file to find any relevant games. Each game contains a property called game_data_directory that has a path to files for the game. For example it could be something like: /components/game/mlb/year_2016/month_03/day_26/gid_2016_03_26_detmlb_phimlb_1. To get the data for that game, you can tack on to the path so the url is like:

In this directory, you’ll find all kind of helpful files containing info about the game. Linescore.json (example shown below) was the best choice for me.

Screen Shot 2016-03-26 at 3.08.24 PM.png

I deployed the backend through Heroku.

For easy retrieving of MLB scores, I made my own npm package: mlb-scores. To install it, simply type:

npm install mlb-scores

Spark Core


To control the LED matrixes, I used the ledmatrix-max7219-max7221 for the spark core. I have a method called setScore() that is called by the server whenever the spark core asks for a score.

Since Heroku will auto sleep your code after a while, the spark core pings the server every few minutes to keep it awake. This is done through a Particle.publish() which is connected to a webhook.

Screen Shot 2016-03-26 at 3.05.39 PM.png

I used the ParticleDev app on OSX to upload and flash code to the Spark Core and used command line to view the serial messages from the Core. The default serial monitor in ParticleDev took 100% cpu power so I used the CLI instead.

The code is available at my Github:

iOS App

I also built an iOS app that allows the user to change which team they want their spark core to be configured with. It uses cocoa pods to install dependencies for the Parse and Spark frameworks.

Screen Shot 2016-03-26 at 2.46.56 PM.png

Heres a screen shot of its current state:

Simulator Screen Shot Mar 26, 2016, 2.55.08 PM.png



Screen Shot 2016-03-26 at 3.08.24 PM.png

The Sports Clock – #1 (Goals)

It’s Maker Faire Season Again!

The Sports Clock is a project I’m working on for Maker Faire Bay Area 2016. It will look like a regular digital clock, but will be internet connected and display sports scores when your favorite teams are playing.

The Sports Clock will be very useful since it allows people to stay updated with their favorite team’s game while not adding any additional distractions like a radio, tv, or smartphone would. It feels terrible when your favorite team is playing but you have to do work, and the Sports Clock solves this by allowing you to be fully focused on your work (no multitasking!) but still fully connected to your teams.

Primary Objectives of the Sports Clock:

  • Build a backend to serve up sports scores
  • Build an internet connected clock with a LED matrix display to  display sports scores
  • Build an iOS app to control which team’s score your clock will display

The PiDrone Update #7 (Maker Faire 2015)

Maker Faire 2015 was a great event as always. Quite a lot of people saw my project and examined it closely.

I also got a chance to roam the fair after I finished by exhibition time slot. It was unfortunate that the giant tesla coils of ArcAttack were not able to make it. The Game of Drones competition was quite boring (the drones kept getting stuck in the netting) but the Power Racing Series was quite entertaining to watch. Many of the 3D Printer companies got pushed over from the Main Expo hall to a more dismal tent.

Some pictures taken by the Pi Drone’s onboard camera:




Some more pictures:



Before Maker Faire, I was also able to add Maps functionality to the drone using Apple’s MapKit (Google Maps requires more complex set up).

The app gained the additional features of being able to center on the user’s current location and see the position of the drone on the map.

Screen Shot 2015-06-14 at 10.13.59 AM


The code to create the map and the drone marker

Setting the image of the drone marker

Centering on the user’s location

Asking the user for location data permission

Updating the position of the drone marker

Download the XCode Project: PiDrone

The Python Server code and the iOS code are now available on Github too:

The PiDrone Update #6

With a bit more work, I’ve created a companion iOS app for the Drone and also given it WiFi capabilities (it formerly ran on ethernet).

The iOS App

The PiDrone’s iOS app is completely written in Swift and retrieves live data from the drone by fetching JSON data from a webpage every quarter second.  Download it: PiDrone

Screen Shot 2015-04-25 at 4.02.00 PM

Current Features Include:

  • Altitude, Speed, Yaw, Pitch, and Roll measurements displayed
  • Displays WiFi speed (amount of time it takes for the request to be made)
  • Arming and Disarming
  • Taking a Picture and saving it to the camera roll
  • Live Stream displayed in a Web View

I currently have two classes, WebModel.swift for accessing the JSON web page, and ViewController.swift to display the stats in a UI from the WebModel

Inside WebModel.swift

Here is the code for synchronously (doesn’t need to be asynchronous since it only takes <0.1 seconds) retrieving the JSON text:

The code for parsing the JSON in to a more accessible swift dictionary:

To invoke some action, such as arming the quadcopter, the code simply access a specific URL on the Pi’s CherryPy web server, which then causes the python code to use the DroneKit libraries to set the quadcopter as armed. I made a simple request method that makes a request to any url asynchronously:

The code for downloading the picture asynchronously and saving it to the Photos library:

To save the picture to the camera roll, I am downloading a still shot provided by the MJPG web application. This process needs to be asynchronous since downloading images takes a significant amount of time and downloading in synchronously causes the button press animation to hang up.

Inside ViewController.swift

The code for displaying the live stream video:

I haven’t quite figured out yet how to center the video feed perfectly with no white space on the screen, so I’m now stuck with having to using the pinch and pan gestures to manually arrange the stream.

To create the nice rounded rect effect around each of the label/buttons, I created outlets to each of the UI elements and a method named roundView which rounds the UIView it receives.

I then individually call roundView on all of the different UIViews I want rounded on the storyboard. I could have also subclassed UILabel and UIButton as UIRoundedLabel and UIButton for cleaner code.

To update the statistics live, I set a NSTimer that “rings” every 0.25 seconds by calling the method update.

A quick look at the Storyboard

Screen Shot 2015-04-25 at 4.03.22 PM

Since none of the Apple UI objects were perfect, I made my own combobox type object for selecting the Flight mode. Its very simple and there is a just a group of other possible flight modes to choose hanging under the current flight mode that are usually hidden.

Screen Shot 2015-04-29 at 5.42.51 PM

When the current flight mode is clicked, the other flight modes unhide themselves, When one of these alternate flight modes are chosen, the group hides again. Instead of updating the current flight mode immediately after the new flight mode is chosen, the program instead waits for the next time update() is called to update the current flight mode when the drone’s flight mode has already been changed.

Next Up:

  • Maps integration with MapKit
    • Location of Drone
    • Location of User
  • Signal Strength

The PiDrone Update #5

Over the past few weeks, I’ve been working hard on the drone side of things for The PiDrone. Right now, I have a CherryPy Web Server running on the onboard RaspberryPi that displays information about the drone and allows you to do basic interactions with it.

On The Drone

The Raspberry Pi is currently connected through a Telemetry Port of the Pixhawk. I took a 6 pin DF13 cable that came with the Pixhawk and stripped of one end to attach the Raspberry Pi friendly connectors. Extra DF13 Cables can be easily purchased on ebay or from 3DR Robotics.

I used this tutorial to set it up.



The Raspberry Pi is powered using a LM2596 DC Adjustable Step-Down Converter that steps the 11V of the LiPo battery down to the 5V required to the Raspberry Pi. I had to set the voltage at 5.25 volts since as the Raspberry Pi drew more current, the voltage would sometimes drop. I discovered that when the voltage drops below approximately 4.96V, the Raspberry Pi will complain with a mini rainbow gradient icon that is usually seen as the splash screen.  Even with the rainbow icon at the corner, the Pi will continue to work, but operation may become unstable and the red power LED will no longer stay on.



I have ordered a nicer 3-amp 12V to 5V module that will hopefully solve the power problems I have encountered. Although the current module is advertised to be able to provide 2 Amps, I think the big gap between 11V to 5V is causing it issues.

To communicate between the Pi and the Pixhawk Flight Controller, I am using 3DR’s brand new open source DroneKit-Python library (installation). Currently, I have a python program that has both CherryPy (web server) and DroneKit code. They seemed to conflict at first, but I solved the issue by initializing the CherryPy server manually with:

To set up the communications with the drone, heres what I did:

Download the full code: pyserver

To start the code, first execute

sudo –master=/dev/ttyAMA0 –baudrate 57600 –aircraft MyCopter

This starts a MAVProxy (command line ground station) connection between the Raspberry Pi and the drone. After a few seconds, the basic information for your drone should be displayed and you should be prompted with something like this when you press enter


If you see something like MAV>, the connection has not been established yet. Try checking the connection wires or restarting the system. Then, type:

module load droneapi.module.api

and to start the server:

api start

The Pi now starts a server at the location

<pi’s ip adress>:9090

To find the pi’s ip address, check out my ssh tutorial. I set up some really simple HTML code (No CSS yet) to control the drone and see stats coming back from it.

Screen Shot 2015-04-25 at 4.04.14 PM

The PiDrone Update #4

Test Flight

I went out and test flew the PiDrone today, and it performed fairly well in some slight winds. Using the “Save Trim” function of the Pixhawk, I was capable of keeping the drone in a relatively stable hover in the air.

I only flew in Altitude Hold and Stabilize modes. Next time, I’ll try out Loiter, which requires a good GPS signal. Out in the park, the Pixhawk gets a GPS signal almost instantly.

Here are the vibration logs:

Screen Shot 2015-04-08 at 5.50.23 PM

The acceptable ranges are:

  • X between -3 and 3
  • Y between -3 and 3
  • Z between -15 and 5

Both the X and Y axis are nearly entering the unacceptable range, which is a little bit worrying. However, the Z axis stays comfortably in the acceptable range most of the time. All three axis appear to suffer from massive spikes around the end of the flight, which is concerning.

To Log Vibrations, change the LOG_BITMASK paramater from default to Default + IMU. Then, when you view the logs, take a look at AccZ, AccX, and AccY under the IMU section. More info here.

I have purchased APC’s new multirotor propellers in an effort to reduce vibrations. They’ll come in a couple days and I’ll try them out. The current propellers and flimsy, unbalanced and not level.



The PiDrone Update #3

Main electronics and avionics have now been installed

Components I’m Using:

Turnigy D3536/9 910KV Brushless Outrunner Motor (US Warehouse)

Turnigy nano-tech 4000mah 3S 25~50C Lipo Pack (US Warehouse)

TURNIGY Plush 30amp Speed Controller

3DR Pixhawk (+ GPS and PPM Encoder)

12×4.5 SF Props 2pc CW and 2pc CCW Rotation (Black)

3DR Cloned Telemetry 915 mHZ

  • Almost everything is velcroed on to the acrylic (it sticks well) including the battery
  • Pixhawk is mounted on a square plate with 3DR anti-vibration foam
  • Most electronics are mounted on middle plate, except for GPS, which is mounted on the top place to reduce interference (no mast).
  • DIY Power distribution system with 10 AWG wire splitting in to 4 sets of 16AWG wire. The battery is connected with 4mm HXT plugs, while the motors and the ESCs are connected via 3.5mm bullet plugs




The cheap plastic props had to be reamed with a prop reamer to fit the 8mm shaft of the prop adapter. Nobody sells a metric prop reamer with a starting shaft size of 6mm (they all start at 1/4″!) I had to use a standard prop reamer that produced horribly off centered shaft holes. I bought a Durbo Prop Balancer and balanced the blades with tape, but I doubt it will do much good.

Next up: Test Flights!

The PiDrone Update #2

I have now completed the new and redesigned laser-cut Acrylic Frame. The old frame was made of 1/8″ aluminum which made it quite indestructible, but also  caused interference with the flight controller avionics. Here are some of the improvements of the new design:

  • Mount for Pixhawk Safety Switch
  • Much, much more working space
  • Mounts for Raspberry Pi  and Pi Camera
  • Support for removable anti-vibration mount



Everything is held together with 4-40 screws, and 1″ 4-40 hex standoffs. The 4 aluminum booms purchased from HobbyKing are sandwiched between the two plates securely.The acrylic turned out to be much bendier than I initially believed, so the frame is “squishy” at some areas.

Download Ai Files: Quad Files


The PiDrone – Update #1

The PiDrone is a drone with a Raspberry Pi onboard that I hope to exhibit at Maker Faire Bay Area 2015.

My Goals for the Project Are:

  • Have the Pi and the Drone communicate through 3DR’s Drone Kit 
  • Have the Pi host a web based ground station
  • Create an iOS Ground Station for the drone

I already have a semi-working drone built up from last summer, but it will require extensive repairs and redesign.


Raspberry Pi Tutorials

Introducing new Raspberry Pi Tutorials:

Raspbian Installation

Using SSH

RaspiCam Live Stream


The Pi is now the best selling British computer of all time!


« Older posts

© 2020 Andrew Ke

Theme by Anders NorenUp ↑