Building a Pinewood Derby Timer: Finishing the arch and adding the last of the wiring!

Well, I finally finished it! The pinewood derby timer is done. Check it out!

First, I had to finish the wiring for the lights and the sensors, and then I had to finish the arch.

Then, I had to program it. Fortunately, https://www.dfgtec.com/ has a whole section on programming the board, and what settings you should change or adjust for your needs. Super helpful site!

Here is my final code:

/*================================================================================*
Pinewood Derby Timer Version 3.00 – 31 Oct 2016
http://www.dfgtec.com/pdt

Flexible and affordable Pinewood Derby timer that interfaces with the
following software:
– PD Test/Tune/Track Utility
– Grand Prix Race Manager software

Refer to the website for setup and usage instructions.
Copyright (C) 2011-2018 David Gadberry

This work is licensed under the Creative Commons Attribution-NonCommercial-
ShareAlike 3.0 Unported License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
Creative Commons, 444 Castro Street, Suite 900, Mountain View, California,
94041, USA.
*================================================================================*/

/*—————————————–*
– TIMER CONFIGURATION –
*—————————————–*/
#define NUM_LANES 4 // number of lanes

#define LED_DISPLAY 1 // Enable lane place/time displays
//#define DUAL_DISP 1 // dual displays (front/back) per lane (4 lanes max)
//#define LARGE_DISP 1 // utilize large Adafruit displays (see website)
#define SHOW_PLACE 1 // Show place mode
#define PLACE_DELAY 4 // Delay (secs) when displaying place/time
#define MIN_BRIGHT 4 // minimum display brightness (0-15)
#define MAX_BRIGHT 10 // maximum display brightness (0-15)

#define GATE_RESET 1 // Enable closing start gate to reset timer
/*—————————————–*
– END –
*—————————————–*/
#ifdef LED_DISPLAY // LED control libraries
#include “Wire.h”
#include “Adafruit_LEDBackpack.h”
#include “Adafruit_GFX.h”
#endif

/*—————————————–*
– static definitions –
*—————————————–*/
#define PDT_VERSION “3.00” // software version
#define MAX_LANE 6 // maximum number of lanes (Uno)
#define MAX_DISP 8 // maximum number of displays (Adafruit)

#define mREADY 0 // program modes
#define mRACING 1
#define mFINISH 2
#define mTEST 3

#define START_TRIP LOW // start switch trip condition
#define NULL_TIME 99.999 // null (non-finish) time
#define NUM_DIGIT 4 // timer resolution (# of decimals)
#define DISP_DIGIT 4 // total number of display digits

#define PWM_LED_ON 220
#define PWM_LED_OFF 255
#define char2int(c) (c – ‘0’)

//
// serial messages <- to timer
// -> from timer
//
#define SMSG_ACKNW ‘.’ // -> acknowledge message

#define SMSG_POWER ‘P’ // -> start-up (power on or hard reset)

#define SMSG_CGATE ‘G’ // <- check gate
#define SMSG_GOPEN ‘O’ // -> gate open

#define SMSG_RESET ‘R’ // <- reset
#define SMSG_READY ‘K’ // -> ready

#define SMSG_SOLEN ‘S’ // <- start solenoid
#define SMSG_START ‘B’ // -> race started
#define SMSG_FORCE ‘F’ // <- force end
#define SMSG_RSEND ‘Q’ // <- resend race data

#define SMSG_LMASK ‘M’ // <- mask lane
#define SMSG_UMASK ‘U’ // <- unmask all lanes

#define SMSG_GVERS ‘V’ // <- request timer version
#define SMSG_DEBUG ‘D’ // <- toggle debug on/off
#define SMSG_GNUML ‘N’ // <- request number of lanes

/*—————————————–*
– pin assignments –
*—————————————–*/
byte BRIGHT_LEV = A0; // brightness level
byte RESET_SWITCH = 8; // reset switch
byte STATUS_LED_R = 9; // status LED (red)
byte STATUS_LED_B = 11; // status LED (blue)
byte STATUS_LED_G = 10; // status LED (green)
byte START_GATE = 12; // start gate switch
byte START_SOL = 13; // start solenoid

// Display # 1 2 3 4 5 6 7 8
int DISP_ADD [MAX_DISP] = {0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77}; // display I2C addresses

// Lane # 1 2 3 4 5 6
byte LANE_DET [MAX_LANE] = { 2, 3, 4, 5, 6, 7}; // finish detection pins

/*—————————————–*
– global variables –
*—————————————–*/
boolean fDebug = false; // debug flag
boolean ready_first; // first pass in ready state flag
boolean finish_first; // first pass in finish state flag

unsigned long start_time; // race start time (microseconds)
unsigned long lane_time [MAX_LANE]; // lane finish time (microseconds)
int lane_place [MAX_LANE]; // lane finish place
boolean lane_mask [MAX_LANE]; // lane mask status

int serial_data; // serial data
byte mode; // current program mode

float display_level = -1.0; // display brightness level

#ifdef LARGE_DISP
unsigned char msgGateC[] = {0x6D, 0x41, 0x00, 0x0F, 0x07}; // S=CL
unsigned char msgGateO[] = {0x6D, 0x41, 0x00, 0x3F, 0x5E}; // S=OP
unsigned char msgLight[] = {0x41, 0x41, 0x00, 0x00, 0x07}; // == L
unsigned char msgDark [] = {0x41, 0x41, 0x00, 0x00, 0x73}; // == d
#else
unsigned char msgGateC[] = {0x6D, 0x48, 0x00, 0x39, 0x38}; // S=CL
unsigned char msgGateO[] = {0x6D, 0x48, 0x00, 0x3F, 0x73}; // S=OP
unsigned char msgLight[] = {0x48, 0x48, 0x00, 0x00, 0x38}; // == L
unsigned char msgDark [] = {0x48, 0x48, 0x00, 0x00, 0x5e}; // == d
#endif
unsigned char msgDashT[] = {0x40, 0x40, 0x00, 0x40, 0x40}; // —-
unsigned char msgDashL[] = {0x00, 0x00, 0x00, 0x40, 0x00}; // –
unsigned char msgBlank[] = {0x00, 0x00, 0x00, 0x00, 0x00}; // (blank)

#ifdef LED_DISPLAY // LED display control
Adafruit_7segment disp_mat[MAX_DISP];
#endif

void initialize(boolean powerup=false);
void dbg(int, const char * msg, int val=-999);
void smsg(char msg, boolean crlf=true);
void smsg_str(const char * msg, boolean crlf=true);

/*================================================================================*
SETUP TIMER
*================================================================================*/
void setup()
{
/*—————————————–*
– hardware setup –
*—————————————–*/
pinMode(STATUS_LED_R, OUTPUT);
pinMode(STATUS_LED_B, OUTPUT);
pinMode(STATUS_LED_G, OUTPUT);
pinMode(START_SOL, OUTPUT);
pinMode(RESET_SWITCH, INPUT);
pinMode(START_GATE, INPUT);
pinMode(BRIGHT_LEV, INPUT);

digitalWrite(RESET_SWITCH, HIGH); // enable pull-up resistor
digitalWrite(START_GATE, HIGH); // enable pull-up resistor

digitalWrite(START_SOL, LOW);

#ifdef LED_DISPLAY
for (int n=0; n<MAX_DISP; n++)
{
disp_mat[n] = Adafruit_7segment();
disp_mat[n].begin(DISP_ADD[n]);
disp_mat[n].clear();
disp_mat[n].drawColon(false);
disp_mat[n].writeDisplay();
}
#endif

for (int n=0; n<MAX_LANE; n++)
{
pinMode(LANE_DET[n], INPUT);

digitalWrite(LANE_DET[n], HIGH); // enable pull-up resistor
}
set_display_brightness();

/*—————————————–*
– software setup –
*—————————————–*/
Serial.begin(9600);
smsg(SMSG_POWER);

/*—————————————–*
– check for test mode –
*—————————————–*/
if (digitalRead(RESET_SWITCH) == LOW)
{
mode = mTEST;
test_pdt_hw();
}

/*—————————————–*
– initialize timer –
*—————————————–*/
initialize(true);
unmask_all_lanes();
}
/*================================================================================*
MAIN LOOP
*================================================================================*/
void loop()
{
process_general_msgs();

switch (mode)
{
case mREADY:
timer_ready_state();
break;
case mRACING:
timer_racing_state();
break;
case mFINISH:
timer_finished_state();
break;
}
}
/*================================================================================*
TIMER READY STATE
*================================================================================*/
void timer_ready_state()
{
if (ready_first)
{
set_status_led();
clear_displays();

ready_first = false;
}

if (serial_data == int(SMSG_SOLEN)) // activate start solenoid
{
digitalWrite(START_SOL, HIGH);
smsg(SMSG_ACKNW);
}

if (digitalRead(START_GATE) == START_TRIP) // timer start
{
start_time = micros();

digitalWrite(START_SOL, LOW);

smsg(SMSG_START);
delay(100);

mode = mRACING;
}

return;
}

/*================================================================================*
TIMER RACING STATE
*================================================================================*/
void timer_racing_state()
{
int lanes_left, finish_order, lane_status[NUM_LANES];
unsigned long current_time, last_finish_time;
set_status_led();
clear_displays();

finish_order = 0;
last_finish_time = 0;

lanes_left = NUM_LANES;
for (int n=0; n<NUM_LANES; n++)
{
if (lane_mask[n]) lanes_left–;
}

while (lanes_left)
{
current_time = micros();

for (int n=0; n<NUM_LANES; n++) lane_status[n] = bitRead(PIND, LANE_DET[n]); // read status of all lanes

for (int n=0; n<NUM_LANES; n++)
{
if (lane_time[n] == 0 && lane_status[n] == HIGH && !lane_mask[n]) // car has crossed finish line
{
lanes_left–;

lane_time[n] = current_time – start_time;

if (lane_time[n] > last_finish_time)
{
finish_order++;
last_finish_time = lane_time[n];
}
lane_place[n] = finish_order;

update_display(n, lane_place[n], lane_time[n], SHOW_PLACE);
}
}

serial_data = get_serial_data();

if (serial_data == int(SMSG_FORCE) || serial_data == int(SMSG_RESET) || digitalRead(RESET_SWITCH) == LOW) // force race to end
{
lanes_left = 0;
smsg(SMSG_ACKNW);
}
}

send_race_results();

mode = mFINISH;

return;
}
/*================================================================================*
TIMER FINISHED STATE
*================================================================================*/
void timer_finished_state()
{
if (finish_first)
{
set_status_led();
finish_first = false;
}

if (GATE_RESET && digitalRead(START_GATE) != START_TRIP) // gate closed
{
delay(500); // ignore any switch bounce

if (digitalRead(START_GATE) != START_TRIP) // gate still closed
{
initialize(); // reset timer
}
}

if (serial_data == int(SMSG_RSEND)) // resend race data
{
smsg(SMSG_ACKNW);
send_race_results();
}

set_display_brightness();
display_race_results();

return;
}
/*================================================================================*
PROCESS GENERAL SERIAL MESSAGES
*================================================================================*/
void process_general_msgs()
{
int lane;
char tmps[50];
serial_data = get_serial_data();

if (serial_data == int(SMSG_GVERS)) // get software version
{
sprintf(tmps, “vert=%s”, PDT_VERSION);
smsg_str(tmps);
}

else if (serial_data == int(SMSG_GNUML)) // get number of lanes
{
sprintf(tmps, “numl=%d”, NUM_LANES);
smsg_str(tmps);
}

else if (serial_data == int(SMSG_DEBUG)) // toggle debug
{
fDebug = !fDebug;
dbg(true, “toggle debug = “, fDebug);
}

else if (serial_data == int(SMSG_CGATE)) // check start gate
{
if (digitalRead(START_GATE) == START_TRIP) // gate open
{
smsg(SMSG_GOPEN);
}
else
{
smsg(SMSG_ACKNW);
}
}

else if (serial_data == int(SMSG_RESET) || digitalRead(RESET_SWITCH) == LOW) // timer reset
{
if (digitalRead(START_GATE) != START_TRIP) // only reset if gate closed
{
initialize();
}
else
{
smsg(SMSG_GOPEN);
}
}

else if (serial_data == int(SMSG_LMASK)) // lane mask
{
delay(100);
serial_data = get_serial_data();

lane = serial_data – 48;
if (lane >= 1 && lane <= NUM_LANES)
{
lane_mask[lane-1] = true;

dbg(fDebug, “set mask on lane = “, lane);
}
smsg(SMSG_ACKNW);
}

else if (serial_data == int(SMSG_UMASK)) // unmask all lanes
{
unmask_all_lanes();
smsg(SMSG_ACKNW);
}

return;
}
/*================================================================================*
TEST PDT FINISH DETECTION HARDWARE
*================================================================================*/
void test_pdt_hw()
{
int lane_status[NUM_LANES];
char ctmp[10];
smsg_str(“TEST MODE”);
set_status_led();
delay(2000);

/*—————————————–*
show status of lane detectors
*—————————————–*/
while(true)
{
for (int n=0; n<NUM_LANES; n++)
{
lane_status[n] = bitRead(PIND, LANE_DET[n]); // read status of all lanes

if (lane_status[n] == HIGH)
{
update_display(n, msgDark); smsg_str(“Dark”); smsg_str(n);
}
else
{
update_display(n, msgLight); smsg_str(“Light”); smsg_str(n);
}
}

if (digitalRead(RESET_SWITCH) == LOW) // break out of this test
{
clear_displays();
delay(1000);
break;
}
delay(100);
}

/*—————————————–*
show status of start gate switch
*—————————————–*/
while(true)
{
if (digitalRead(START_GATE) == START_TRIP)
{
update_display(0, msgGateO);
}
else
{
update_display(0, msgGateC);
}

if (digitalRead(RESET_SWITCH) == LOW) // break out of this test
{
clear_displays();
delay(1000);
break;
}
delay(100);
}

/*—————————————–*
show pattern for brightness adjustment
*—————————————–*/
while(true)
{
#ifdef LED_DISPLAY
set_display_brightness();

for (int n=0; n<NUM_LANES; n++)
{
sprintf(ctmp,”%04d”, (int)display_level);

disp_mat[n].clear();

disp_mat[n].writeDigitNum(0, char2int(ctmp[0]), false);
disp_mat[n].writeDigitNum(1, char2int(ctmp[1]), false);
disp_mat[n].writeDigitNum(3, char2int(ctmp[2]), false);
disp_mat[n].writeDigitNum(4, char2int(ctmp[3]), false);

disp_mat[n].drawColon(false);
disp_mat[n].writeDisplay();

#ifdef DUAL_DISP
disp_mat[n+4].clear();

disp_mat[n+4].writeDigitNum(0, char2int(ctmp[0]), false);
disp_mat[n+4].writeDigitNum(1, char2int(ctmp[1]), false);
disp_mat[n+4].writeDigitNum(3, char2int(ctmp[2]), false);
disp_mat[n+4].writeDigitNum(4, char2int(ctmp[3]), false);

disp_mat[n+4].drawColon(false);
disp_mat[n+4].writeDisplay();
#endif
}
#endif

if (digitalRead(RESET_SWITCH) == LOW) // break out of this test
{
clear_displays();
break;
}
delay(1000);
}
}
/*================================================================================*
SEND RACE RESULTS TO COMPUTER
*================================================================================*/
void send_race_results()
{
float lane_time_sec;
for (int n=0; n<NUM_LANES; n++) // send times to computer
{
lane_time_sec = (float)(lane_time[n] / 1000000.0); // elapsed time (seconds)

if (lane_time_sec == 0) // did not finish
{
lane_time_sec = NULL_TIME;
}

Serial.print(n+1);
Serial.print(” – “);
Serial.println(lane_time_sec, NUM_DIGIT); // numbers are rounded to NUM_DIGIT
// digits by println function
}

return;
}
/*================================================================================*
RACE FINISHED – DISPLAY PLACE / TIME FOR ALL LANES
*================================================================================*/
void display_race_results()
{
unsigned long now;
static boolean display_mode;
static unsigned long last_display_update = 0;
if (!SHOW_PLACE) return;

now = millis();

if (last_display_update == 0) // first cycle
{
last_display_update = now;
display_mode = false;
}

if ((now – last_display_update) > (unsigned long)(PLACE_DELAY * 1000))
{
dbg(fDebug, “display_race_results”);

for (int n=0; n<NUM_LANES; n++)
{
update_display(n, lane_place[n], lane_time[n], display_mode);
}

display_mode = !display_mode;
last_display_update = now;
}

return;
}
/*================================================================================*
SEND MESSAGE TO DISPLAY
*================================================================================*/
void update_display(int lane, unsigned char msg[])
{

#ifdef LED_DISPLAY
disp_mat[lane].clear();
#ifdef DUAL_DISP
disp_mat[lane+4].clear();
#endif

for (int d = 0; d<=4; d++)
{
disp_mat[lane].writeDigitRaw(d, msg[d]);
#ifdef DUAL_DISP
disp_mat[lane+4].writeDigitRaw(d, msg[d]);
#endif
}

disp_mat[lane].writeDisplay();
#ifdef DUAL_DISP
disp_mat[lane+4].writeDisplay();
#endif
#endif

return;
}
/*================================================================================*
UPDATE LANE PLACE/TIME DISPLAY
*================================================================================*/
void update_display(int lane, int display_place, unsigned long display_time, int display_mode)
{
int c;
char ctime[10], cplace[4];
double display_time_sec;
boolean showdot;

// dbg(fDebug, “led: lane = “, lane);
// dbg(fDebug, “led: plce = “, display_place);
// dbg(fDebug, “led: time = “, display_time);

#ifdef LED_DISPLAY
if (display_mode)
{
if (display_place > 0)
{
disp_mat[lane].clear();
disp_mat[lane].drawColon(false);

sprintf(cplace,”%1d”, display_place);
disp_mat[lane].writeDigitNum(3, char2int(cplace[0]), false);

disp_mat[lane].writeDisplay();

#ifdef DUAL_DISP
disp_mat[lane+4].clear();
disp_mat[lane+4].drawColon(false);
disp_mat[lane+4].writeDigitNum(3, char2int(cplace[0]), false);
disp_mat[lane+4].writeDisplay();
#endif
}
else // did not finish
{
update_display(lane, msgDashL);
}
}
else
{
if (display_time > 0)
{
disp_mat[lane].clear();
disp_mat[lane].drawColon(false);
#ifdef DUAL_DISP
disp_mat[lane+4].clear();
disp_mat[lane+4].drawColon(false);
#endif

display_time_sec = (double)(display_time / (double)1000000.0); // elapsed time (seconds)
dtostrf(display_time_sec, (DISP_DIGIT+1), DISP_DIGIT, ctime); // convert to string

// Serial.print(“ctime = [“); Serial.print(ctime); Serial.println(“]”);
c = 0;
for (int d = 0; d<DISP_DIGIT; d++)
{
#ifdef LARGE_DISP
showdot = false;
#else
showdot = (ctime[c + 1] == ‘.’);
#endif
disp_mat[lane].writeDigitNum(d + int(d / 2), char2int(ctime[c]), showdot); // time
#ifdef DUAL_DISP
disp_mat[lane+4].writeDigitNum(d + int(d / 2), char2int(ctime[c]), showdot); // time
#endif

c++; if (ctime[c] == ‘.’) c++;
}

#ifdef LARGE_DISP
disp_mat[lane].writeDigitRaw(2, 16);
#ifdef DUAL_DISP
disp_mat[lane+4].writeDigitRaw(2, 16);
#endif
#endif

disp_mat[lane].writeDisplay();
#ifdef DUAL_DISP
disp_mat[lane+4].writeDisplay();
#endif
}
else // did not finish
{
update_display(lane, msgDashT);
}
}
#endif

return;
}
/*================================================================================*
CLEAR LANE PLACE/TIME DISPLAYS
*================================================================================*/
void clear_displays()
{
dbg(fDebug, “led: CLEAR”);

for (int n=0; n<NUM_LANES; n++)
{
if (mode == mRACING || mode == mTEST)
{
update_display(n, msgBlank); // racing
}
else
{
update_display(n, msgDashT); // ready
}
}

return;
}
/*================================================================================*
SET LANE DISPLAY BRIGHTNESS
*================================================================================*/
void set_display_brightness()
{
float new_level;

#ifdef LED_DISPLAY
new_level = long(1023 – analogRead(BRIGHT_LEV)) / 1023.0F * 15.0F;
new_level = min(new_level, (float)MAX_BRIGHT);
new_level = max(new_level, (float)MIN_BRIGHT);

if (fabs(new_level – display_level) > 0.3F) // deadband to prevent flickering
{ // between levels
dbg(fDebug, “led: BRIGHT”);

display_level = new_level;

for (int n=0; n<NUM_LANES; n++)
{
disp_mat[n].setBrightness((int)display_level);
#ifdef DUAL_DISP
disp_mat[n+4].setBrightness((int)display_level);
#endif
}
}
#endif

return;
}
/*================================================================================*
SET TIMER STATUS LED
*================================================================================*/
void set_status_led()
{
int r_lev, b_lev, g_lev;

dbg(fDebug, “status led = “, mode);

r_lev = PWM_LED_OFF;
b_lev = PWM_LED_OFF;
g_lev = PWM_LED_OFF;

if (mode == mREADY) // blue
{
b_lev = PWM_LED_ON;
}
else if (mode == mRACING) // green
{
g_lev = PWM_LED_ON;
}
else if (mode == mFINISH) // red
{
r_lev = PWM_LED_ON;
}
else if (mode == mTEST) // yellow
{
r_lev = PWM_LED_ON;
g_lev = PWM_LED_ON;
}

analogWrite(STATUS_LED_R, r_lev);
analogWrite(STATUS_LED_B, b_lev);
analogWrite(STATUS_LED_G, g_lev);

return;
}
/*================================================================================*
READ SERIAL DATA FROM COMPUTER
*================================================================================*/
int get_serial_data()
{
int data = 0;

if (Serial.available() > 0)
{
data = Serial.read();
dbg(fDebug, “ser rec = “, data);
}

return data;
}
/*================================================================================*
INITIALIZE TIMER
*================================================================================*/
void initialize(boolean powerup)
{
for (int n=0; n<NUM_LANES; n++)
{
lane_time[n] = 0;
lane_place[n] = 0;
}

start_time = 0;
set_status_led();
digitalWrite(START_SOL, LOW);

// if power up and gate is open -> goto FINISH state
if (powerup && digitalRead(START_GATE) == START_TRIP)
{
mode = mFINISH;
}
else
{
mode = mREADY;

smsg(SMSG_READY);
delay(100);
}
Serial.flush();

ready_first = true;
finish_first = true;

return;
}
/*================================================================================*
UNMASK ALL LANES
*================================================================================*/
void unmask_all_lanes()
{
dbg(fDebug, “unmask all lanes”);

for (int n=0; n<NUM_LANES; n++)
{
lane_mask[n] = false;
}

return;
}
/*================================================================================*
SEND DEBUG TO COMPUTER
*================================================================================*/
void dbg(int flag, const char * msg, int val)
{
char tmps[50];
if (!flag) return;

smsg_str(“dbg: “, false);
smsg_str(msg, false);

if (val != -999)
{
sprintf(tmps, “%d”, val);
smsg_str(tmps);
}
else
{
smsg_str(“”);
}

return;
}
/*================================================================================*
SEND SERIAL MESSAGE (CHAR) TO COMPUTER
*================================================================================*/
void smsg(char msg, boolean crlf)
{
if (crlf)
{
Serial.println(msg);
}
else
{
Serial.print(msg);
}

return;
}
/*================================================================================*
SEND SERIAL MESSAGE (STRING) TO COMPUTER
*================================================================================*/
void smsg_str(const char * msg, boolean crlf)
{
if (crlf)
{
Serial.println(msg);
}
else
{
Serial.print(msg);
}

return;
}

A little long for posting here, but I wanted to post any changes I had made in case it helps someone else! Now the timers work, alternating between places and time per track/car! This was a really fun project, and I highly recommend it to anyone looking for a fun electronics project to work on.

I might still dress it up a bit, but it is fully functional as is, now.

Linux – keep it simple.

Building a Pinewood Derby Timer: Wiring in the displays

Now that I have the displays mounted on the pinewood derby timer, it was time to wire them in. I still don’t have lights or sensors in yet, but I thought I could just hook up the displays for now. It seemed to work well!

I am using the schematics per the https://www.dfgtec.com/ website. Fortunately, the creator of the schematics, David Gadberry was kind enough to give it a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License, so guys like me can tinker with it!

Linux – keep it simple.

Building a Pinewood Derby Timer: 3D printing some display covers

Well, I decided to print a few display covers to go around the LED displays. This covers up the unsightly hole that I cut from the box, and seems to “class up” the displays a bit. I like the way they turned out. If I could post files here, I’d post the gcode and openCad files, but the free version of WordPress doesn’t work well that way.

Either way, took me only two tries to find a style I liked, and a couple hours total to complete this part of the project.

Linux – keep it simple.

Building a Pinewood Derby Timer: The Box for the “Arch”

As I have been constructing this Pinewood Derby Timer, I needed some sort of box or enclosure to make the top of the arch. So I took apart a junk piece of equipment and cut out holes for the LED displays to go into it. I also drilled some holes for the LED’s to shine out the bottom and some holes for the Arduino card USB interface and power adapter plug on the side.

The box was originally black, and I tried to paint it white. Unfortunately, all the paint peeled, and I ended up grinding it down to bare metal. I’m not sure if I should paint it or not now. I guess I’ll have to see the end result.

I also am not sure if I’ll just put some sort of “face” on it, or fake front to cover it up. The holes didn’t cut perfectly rectangular, so I want to cover that up somehow. I’ll have to think on it. Maybe I can use the ol’ 3D printer to come up with something.

Linux – keep it simple.

Building a Pinewood Derby Timer: Setting up the LED displays

So one of the driving components (pun intended) of the derby timer is the LED displays. I went with the smaller ones from Adafruit, as we wouldn’t need a second power supply if we go this route, and I’d like to keep the unit as simple as possible.

You have to solder the displays to the backer board, and then you have to solder jumper pins across them to serialize each display. If you don’t do this part, your displays all show the same thing! I found that out the hard way! So be sure to solder those little jumpers. For convenience, the PDT website: https://www.dfgtec.com/pdt

has a reference table:

PDT Lane # PDT Lane # I2C Address # Jumpers
A0 A1 A2
1 1 F 0
2 2 F 1 x
3 3 F 2 x
4 4 F 3 x x
5 1 B 4 x
6 2 B 5 x x
3 B 6 x x
4 B 7 x x x

Key: – = open, x = shorted; F = front, B = back

This is really handy. I really appreciate all the work they put into this, and it is fun to build along with a guide that covers about 95% of the process!

Linux – keep it simple.

Building a Pinewood Derby Timer: Getting the schematics and parts list…

A local church group that I attend needed some help with an Awana project. They use a pinewood derby track for racing cars, and they needed a timer built for it. I don’t attend the Awana club usually, and I was not present for the races last time they held them, but I guess they borrowed a track and timer for those races. Now they bought their own track, and need a timer for it.

I priced the times out online, you can buy some nice pre-made ones for about $350-$400. That’s a lot of money. After a little research, I found we could make one for about $85! So, here I am, building a timer.

I found a lot of reference material out there for making your own timer, but the best by far was here: https://www.dfgtec.com/pdt 

It is a great and informative website that uses an Ardiuno Uno powered configuration with several parts from Adafruit and elsewhere. They have done all the heavy lifting on the build and, best of all, their schematics were open source! So, I went with it.

5

They sold some of the parts on their website, and others you had to get elsewhere, but it was very clean and informative. They sold this PDT shield for the Arduino, and then you have to solder all the parts onto it, which was pretty fun to do, as the shield made everything a lot easier to maintain.

Now I just have to finish putting it together!

Linux – keep it simple.

LTE Project renamed “Bone Phone”!

Well, today is my last post on the LTE project. After showing it to my co-workers, it has now been renamed the “bone phone” because of it’s unique shape and color! I’ve also included the README.md at the end of this post with the full story.

To God be the glory, I learned a lot, and made a lot of functions with this phone. The main points are:

  • Send Text messages to any valid number
  • Receive and read text (SMS only) messages from anyone
  • Reply or delete text messages
  • Turn LTE on/off
  • Turn GPS on/off
  • Get your current location
  • Send your current location to someone else via text
  • Compass heading (must be moving to be accurate, based on GPS)
  • Status Bar with battery, GPS, cellular, and messages stats
  • Current local time

There was a lot more things that I wanted to do with this project. unfortunately, I ran out of memory:

Sketch uses 26938 bytes (83%) of program storage space. Maximum is 32256 bytes.
Global variables use 1567 bytes (76%) of dynamic memory, leaving 481 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

As you can see from the warning, I’m running out of dynamic memory, or ram. I’ve tried adding a few more things, but anything I add tips it over the edge. Even just a few bytes added seems to make the device slow down so much that it is unusable. You are supposed to leave 512 bytes for running the program, and I’m only leaving 481, which slows it down a bit. But, be sure to check out the project on my GitLab for all the files, the pictures, videos, and 3d printer cad drawings and program! It’s all up for you to work on and improve!

Thanks for following along with me on this project! It’s been a really great learning experience! Not only that, but to God be the glory, it even works! You can read more about it in the readme if you’d like. This readme also includes operating instructions. (It’s easier to read by following the link to the mark down document, but I’ll post it here in case you need it.)

# LTE project (nickname: “Bone Phone”)

You can read more about this project on my blog: https://thealaskalinuxuser.wordpress.com
Just search for “LTE project” to see how you can build this open source hardware texting phone for yourself!

This phone can send and receive text messages. Runs off of a 9 volt battery, and has six buttons.

# Operating instructions:

1. Turn on the Bone Phone by flipping the power switch to the “on” position.
2. Once it boots up, you will be presented with the main screen. On every screen, use the numbered button that corosponds to the menu item to select it.
3. Any screen that has you input text or numbers, use the buttons to navigate, 1 is up, to scroll through the numbers or letters, 2 is down, to scroll through the numbers and letters. Whatever letter or number you select is not saved to that spot until you use button 3 (left) or button 4 (right), at which point the letter/number is saved/entered.
4. Some screens tell you to push the select button (button 5) to do special functions. If needed, the screen will display the action you should take.
5. At any time, you can press the “home” button (button 6), which will take you back to the main menu.

# Features

– Send/receive text messages
– Turn on/off data or gps
– View GPS location and send as text
– Compass heading screen if GPS is on
– View network info.
– Using serial over USB, you can do many more features such as download web pages, upload to the web, and more.

# Notes

– I tested this with StraightTalk and Hollogram.io simcards. Both worked, but only the hollogram card would allow data if using the serial over USB connection. Both worked for texting.
– When sending a text to a number, you need either of these two formats: +19078675309 or 19078675309. Some phones will not accept unless you have the “+” sign in front of the number. So far, all phones accept the text when you use the “+” sign.
– The device has 2 batteries. One 9 volt battery, which is disposable, and non-chargable. The second battery is a 3.7 volt battery for the modem, which is charged by power from either board input or the 9 volt battery. The power battery percentage from the phone on the status bar is actually for the modem battery, and doesn’t tell you how much battery power you have left in the 9 volt battery, unfortunately.
– The serial over USB works, and you can talk to the board that way, sending and receiving texts, etc.
– The included truth table outlines the different screens and button combinations.
– The bone phone was also supposed to have a mini browser/ftp/http get/put method, as well as a game, but I ran out of memory on the device. Come on, I only had 32 kb of space and 2 kb of ram to work with!

# About – Or, Why “bone phone”?

Well, the design is somewhat dog bone treat shaped, to protect the buttons. Add to that the fact that the original that I 3d printed was white, it did look like a big bone. While showing it to my co-workers one day, one of them said it’s a bone. One then said it was a bone phone. They then all started laughing and we nicknamed it the bone phone.

I built this phone so I can learn about cell phones, c and c++ programming, and work with open source open hardware on a project. This bone phone met all those goals. This bone phone cannot make phone calls, but can send or receive texts.

# Hardware Components

The main board is an Arduino Uno (or knock off), and a Botletics LTE shield, both of which are open source hardware. There is also a Nokia 5110 screen, a slider (on/off) dpst switch, and 6 momentary switches, made by QTEATAK. There were also 6 550 ohm resistors, and a 3.7v lithium cell phone battery that I took out of an old HTC sense cell phone, but any 3.7volt LiPo/Li-ion battery would do.

I also included the files for the 3d printed case that I made. I used a glue gun and glue sticks to hold most of the components and wiring in place. Please see my website for tutorials about how it was put together.

The hardware used was specifically selected because it is all open source hardware.

“Open source hardware is hardware whose design is made publicly available so that anyone can study, modify, distribute, make, and sell the design or hardware based on that design.”

# License

My portion of the software is licensed under the Apache2.0 license:

Copyright 2019 by AlaskaLinuxUser (https://thealaskalinuxuser.wordpress.com)

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The software includes three libraries:

– The Adafruit Phona Library – Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution. Which was modified by Botletics, maintaining the BSD license.
– The PCD8544 Library – The MIT License (MIT), Copyright (c) 2013 Carlos Rodrigues <cefrodrigues@gmail.com>
– The Arduino software serial library – GPL2.0

Linux – keep it simple.

LTE Project: SMS, read and reply!

Of course the Botletics shield that houses the modem was able to receive sms messages the moment I put a sim card in it, but now I can read them on my device! That’s right! Using nothing but the interface and buttons on the device, I can select which message to read, I can view it, and then reply or delete it!

Originally, I was going to have a scrolling screen that you could use the buttons to scroll through and read the text messages. This had several advantages, like being able to see a conversation flow. However, it had some disadvantages too. Namely, I don’t have enough memory left on this thing to hold the messages in the Arduino’s ram.

That said, I needed to just read the message and display it to the screen. I already have a buffer for sending a text message, and a buffer for what phone number to send it to (2 char arrays, the message one is 140, and the phone number is 21). This actually worked out in my favor greatly. With the read screen, you get to choose a message number to read, so I made a small int to hold that number and you can use up and down to change it, or move it by 10 with left and right.

Once you settle on the message to read, you press select, which then reads that message from line into the phone number send char array, and the from message into the send message char array. These are simply displayed on the screen.

With that done, it is actually really easy to delete the message, since you have a message number already, so selecting to delete it, it already knows which one to delete!

Also, replying becomes easy, since the send to phone number is already saved in the send to phone number char array! Also the text message is saved their too, so you can read the message you were sent while you write the new message. I think it is great! The only problem is this: if your wife texts you and says “what should we have for dinner tonight?”, when you hit reply, you have to overwrite that whole message so you can say, “tacos”. So I’m not sure, I may want to blank it out instead, but for now, it’s pretty hand for testing, since I can just hit reply and send the same message back for testing purposes.

Be sure to check out the entire commit for all the good details I missed here!

Linux – keep it simple.

LTE Project: Sent a text message!

Today was a great day for my LTE project! Today I sent a text message using only the buttons on the device itself! It was great to be able to do that from the gui/interface without the need for a serial over USB connection!

So, how does it work? Well, you can check out the entire commit on my GitLab, but I’ll highlight the main parts here. First, I needed a way to type with only 6 buttons, one of them permanently being the “home” button, and one always being the “select/ok” button. So really just 4 buttons. With that in mind, I made a simple interface that I’ve seen before: Up/Down to cycle through the letters/numbers, and Left/Right to move which place you are typing at.

To make that work, I added an array of characters that you can cycle through, like so:

char letterNumbers[91] = {'0','1','2','3','4','5','6','7','8','9',' ','A','B','C','D','E','F','G',
  'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e',
  'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','`','~','!',
  '@','#','$','%','^','&','*','(',')','_','+','|','-','=',';',':',',','/','.','<','>','?'};

Notice that not every keyboard character is there. You have the forward slash, but not the back slash, due to an issue with char. I’m sure I can work it in, but I needed to get it working first, then I can edit it more later.

Then, I use a variable called curPos to mark which spot in the message you are, and numLetter to hold which number of the 91 characters you are trying to use. It looks like this:

case 30:{ // Screen 5 – Enter phone number screen.
// Up one character
if (numLetter >= 91){
numLetter = 0;
} else {
numLetter++;
}
break;
}
case 35:{
// Down one character
if (numLetter <= 0){
numLetter = 91;
} else {
numLetter–;
}
break;
}
case 40:{
// Left one position
if (curPos <= 0){
curPos = 0;
} else {
sendText[curPos] = letterNumbers[numLetter];
curPos–;
}
break;
}
case 45:{
// Right one position
if (curPos >= 21){
curPos = 21;
} else {
sendText[curPos] = letterNumbers[numLetter];
curPos++;
}
break;
}

It allows you to wrap around from character 91 back to character 0 in the list. Then when you press left or right, it saves the character you chose, say “A” in the spot where you were! It’s a little cumbersome, but it actually works!

The only thing I wonder is if the left button should be like delete, and leave a blank space instead of writing the current character and going left. I’m not sure which works better. I suppose a smart person can actually write the entire text backwards if they mess up and want to retype it…. maybe not.

It can be a little confusing, because it doesn’t save the letter/number/punctuation you have chosen until you move left or right, which appears like it is there, but it is not saved until you move off of it. You also can’t read what is under the “cursor” because it always displays the current chosen character you want to write. I’ll look at ways to fix that, but for now, it’s pretty functional, just not very pretty.

Linux – keep it simple.

LTE Project: Button it up.

Now that I shoved all the wires in there and soldered in the connections for the buttons, I was able to close the case. It still opens, you just have to unscrew the 4 screws to take it apart.

With that, I’ve also made progress on the button reading and programming. As we saw before, the program uses a “truth table” where based on the math formula of (btn# + screenNumber)*screenNumber = menu option, we can calculate all possible outputs and assign them to operations or values.

So, this is a compilation of four different commits:

  1. Update the truth table and screens.
  2. Adding button reading.
  3. Screen updates.
  4. Some small updates.

You can check out all of the above commits to see the process, but here I’ll cover the main part. This is the button reading function.

int read_LCD_buttons(){               // read the buttons
  adc_key_in = 0;
    //adc_key_in = analogRead(A0);       // read the value from the sensor 
    Serial.print("anolog0:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnRIGHT;
    //adc_key_in = analogRead(A1);       // read the value from the sensor 
    Serial.print("anolog1:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnUP;
    adc_key_in = analogRead(A2);       // read the value from the sensor 
    Serial.print("anolog2:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnDOWN;
    adc_key_in = analogRead(A3);       // read the value from the sensor 
    Serial.print("anolog3:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnLEFT;
    adc_key_in = analogRead(A4);       // read the value from the sensor 
    Serial.print("anolog4:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnSELECT;
    adc_key_in = analogRead(A5);       // read the value from the sensor 
    Serial.print("anolog5:"); Serial.println(adc_key_in);
    if (adc_key_in > 550)   return btnBACK; 
    return btnNONE;                // when all others fail, return this.
}

At first, I have it log everything to serial so I can see what is happening. Essentially, I took a wire from 3.3vdc that goes to the button. Then the button goes to the analog input, with a jumper going to a resistor to ground. That way, when you are not pushing the button, then the analog pin is not floating, and reads 0. When you push a button, that input reads around 700. So, I put the threshold at greater than 550. This seems to work fairly well.

The only problem is that I didn’t arrange the buttons the way I thought that I was programming them to work. Rather than swap the button wires physically, I just re-ordered them in my program, saying one was two, etc.

Here is the call inside the loop, asking for which button is pressed:

int waiting = 0;
menuNumber = 0;
while ( waiting < 30 ){
waiting++;
delay(10);
lcd_key = read_LCD_buttons(); // read the buttons
// TESTING ONLY // Serial.print(lcd_key);
switch (lcd_key){

case btnUP:{
menuNumber = (1+screenNumber)*screenNumber;
break;
}
case btnDOWN:{
menuNumber = (2+screenNumber)*screenNumber;
break;
}
case btnLEFT:{
menuNumber = (3+screenNumber)*screenNumber;
break;
}
case btnRIGHT:{
menuNumber = (4+screenNumber)*screenNumber;
break;
}
case btnSELECT:{
menuNumber = 255;
break;
}
case btnBACK:{
menuNumber = 256;
break;
}
}
// TESTING ONLY // Serial.print(menuNumber);
}

The above call checks every 10 milliseconds to see if you pressed a button. After 30 checks, it continues through the process and refreshes the screens, etc. This works out to be about a half second, due to the length of the program. There is a small window of about a tenth of a second, where pushing a button doesn’t do anything, but I’ve found in test runs that it was really rare that pushing a button didn’t respond immediately.

If you don’t do this, it is refreshing the screen about 30 times a second as it rips through the program, and there is only a fraction of a second where pushing the button actually works. There is probably a better way to do this, but this works really well for my program.

Now I just need to make it send and receive text messages!

Linux – keep it simple.