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).

Backend

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 http://gdx.mlb.com/. 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 gd2.mlb.com 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.

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.

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 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

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.

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:

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:

1

2

3

4

5

@IBOutlet weak varvideoStreamer:UIWebView!

url=NSURL(string:"http://\(model.ipadress):8080/stream_simple.html"

let requestObj=NSURLRequest(URL:url!)

videoStreamer.loadRequest(requestObj);

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.

1

2

3

4

func roundView(view:UIView){

view.layer.cornerRadius=8.0

view.clipsToBounds=true

}

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.

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.

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.

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.

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:

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

STABILIZE>

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 drone.py

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.

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:

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.

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

Before

After

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.

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.