This project was created out of a need to motivate oneself to be physically active. When we tracked our physical activity, we noticed that there is very minimal/lack of physical activity during the weekends, especially during the winter season. We decided to build something that would act as a source of motivation to stay physically active.
"Sitting is the new smoking"Our jobs involve sitting at our desks for most of the day and it is quite natural to not move from our desks for hours. According to the World Health Organization (WHO), a minimum physical activity of 150 minutes in a week is required to stay healthy. Almost every physical activity tracker sets the daily physical activity target to 10,000 steps/day.
Hence, we decided to build something that serves as a visual aid to our daily step goal.
- Our first step was to determine if it's possible to download data logged by our Fitbit trackers. Fitbit provides an API that makes it easy to download your personal data. We signed up for a developer account, downloaded the API keys and wrote a simple python script (Fitbit's python client is available from here) to fetch the data:
try:
now = datetime.datetime.now()
end_time = now.strftime("%H:%M")
response = client.intraday_time_series(
'activities/steps',
detail_level='15min',
start_time="00:00",
end_time=end_time
)
except Exception as error:
print(error)
else:
str_steps = response['activities-steps'][0]['value']
print(str_steps)
try:
num_steps = int(str_steps)
except ValueError:
return -1
return num_steps
- We used a Raspberry Pi Zero W to run the script. The script fetches data every 15 minutes.
- Our next step was selection of display element that has a "retro effect" to it. We decided to go with Sparkfun's 6.5" seven segment display. The wiring of the seven segment display and its interface to the Arduino was relatively easy since it is well documented by Sparkfun (setup tutorial available from here).
- The next step was to assemble the seven segment displays into the shadow box (obtained from a local hobby store).
- Now, the Raspberry Pi fetches the physical activity information and the Arduino drives the segment displays. The next step was to implement a serial port interface to interface the Raspberry Pi Zero and the Arduino.
- We came up with a format to transmit a message from the Raspberry Pi Zero to the Arduino. The Raspberry Pi transmits any information to be displayed with a preceding letter 'S'. For e.g.: In order to display the number '11000' on the display, the Raspberry Pi transmits it in the following format: 'S11000'.
def serial_write(serial_client, goal, steps):
"""
Write steps to serial port
"""
if steps >= 0:
display_value = goal - steps
if display_value < 0:
display_value = 0
message = 'S' + str(display_value)
serial_client.write(bytes(message, encoding='utf-8'))
- The Arduino listens for incoming serial port data. It parses all incoming strings and determines its validity (i.e. if the incoming message is preceded by the letter 'S'):
if(Serial.available()){
steps = 0;
char c = Serial.read();
if(c == 'S'){
while(Serial.available()){
c = Serial.read();
steps = (steps * 10) + (c - '0');
}
Serial.println(steps);
showNumber(steps);
}
}
- If the string is valid, the string is converted into a number and seven segment displays are driven by the Arduino to display the number
void showNumber(long value)
{
long number = abs(value); //Remove negative signs and any decimals
for (byte x = 0 ; x < 5 ; x++)
{
int remainder = number % 10;
postNumber(remainder, false);
number /= 10;
}
//Latch the current segment data
digitalWrite(segmentLatch, LOW);
digitalWrite(segmentLatch, HIGH); //Register moves storage register on the rising edge of RCK
}
- The final step was to assemble the Raspberry Pi Zero and the Arduino on the back of the shadow box. The visual aid is ready!
Once we put the display together, we had to determine whether our visual aid counts up to the step goal or count down from the step goal. For example: Let's consider a scenario where you have clocked 8500 steps (against a daily goal of 10,000 steps) in a day.
- If we were to display the actual steps clocked, it could be tempting to call it a day since 8500 steps is closer to the daily goal.
- If we were to display the steps left for the day (in this case, it is 1500 steps), we were tempted to bring it down to zero.
We got a chance to exhibit our project at different Maker Faires across the country and it was sheer fun!
Comments