Finally the DIY Chronograph meets Android

Yes, I finally got a Bluetooth serial adapter to connect to my Arduinos.

I bought it off Ebay for £5, just search for HC-06 Bluetooth adapter but be aware that it comes with and without the mounting PCB.  The one in the picture comes with the back PCB which handles the level shifting from 5 to 3.3V as the transceiver itself is 3.3V not 5V and the connections are a bit small and difficult to solder to.

The connections are 5V, GND, TX and RX, the baud rate comes set to 9600 but can be changed using a terminal console and AT commands also the name and pass code can be changed, the default pass code is 1234.

Once this was connected to my Arduino I put together a little sketch to simulate some shot data, a loop counting from 300 - 340 incrementing by one every 5 seconds (saved a lot of pellets ;-))

I've did attach the transceiver to the sensor tube (as seen in part6) for a quick trial with the pistol and it worked fine.

Next came a couple of days writing the Android app using the App Inventor site, this is what it looks like
First you power up the transceiver and pair it to your phone, the same way you would any other device then enter the data: pellet weight, the distance between the sensors, pellet name and then press calculate.
Once the calculations have been done and stored you can press the top right button to select the paired device, it shows up as "invor" or similar, if you've not renamed it, I renamed mine "Chrono1"

Once selected press the top left button to connect, when connected the shot data should appear in the Shot, FPS and FPE boxes with the average and max. data showing below.

If you tick the speech box then the FPE value will be spoken out loud to you by your phone, the quality of this function may vary between phones.

Also, I'm not an App developer, this is my first App therefore there could be other issues like screen resolution etc. I wrote this for my Galaxy S4 and haven't tried it on any other phones so I'm interested in any feedback.

It can be downloaded here.

1st Feb 2016 - Link to the AI2 aia file here and the APK file here.

I found another AI2 project I did, the only problem is that when you first start it there is an error but if you press the back button and add the settings and then exit it works OK the next time. you can try it here, AI2 Gallery link to app here

I intend to add other features in the future like multiple speech options and logging shot data to memory etc. it depends how popular it is.

Comments

cengiz akgun said…
Thanks for the post. I had trouble with finding ardunio sketch. Can you help me find a valid download link?
What is the memory capacity of android apk? How many shot results i can store?
Thanks for your help.
Gadjet said…
This comment has been removed by the author.
Gadjet said…
This comment has been removed by the author.
Gadjet said…
Arrrgh! I keep making a mess of the post.

Hi,
What do you want to do with the Arduino sketch, a chronograph.

I'm not sure about how many shots but I would think it would be quite a lot, depending on the phone memory etc.

Currently the app doesn't save the shots anywhere just display them, if I remember right, it's been a while...
cengiz akgun said…
Thanks for quick reply. My ardunio is on the way and i am new with it. So if you can share your sketch it would be great.
Many thanks
cengiz akgun said…
hello
l m Mesure f-PS rifle barrel
I and Ardunio mini pro Bluetooth
I want To mesure with andioid APK
Need Arduino mini pro sketch compilation
To perform the measurement by making
Apk need him running with chronograph
Which skech ardunio mini pro
No english is writing google translate
I would like you thank you for your interest
Thank you very much if you help
Gadjet said…
I hope this helps, any questions just ask.

/*
Sketch to measure the time in uSeconds between two IR sensors being triggered
and sending the result to the serial port.
Use with the PC application to display results

Version 0.1
Phil Grant 25/04/13
*/
#define Trip_in_1 2 //set light Trigger 1 to pin D2
#define Trip_in_2 3 //set light Trigger 2 to pin D3
#define WAIT_STATE 0
#define MONITOR_STATE 1
#define OUTPUT_STATE 2

unsigned long Trigger_1 = 0;
unsigned long Trigger_2 = 0;
volatile unsigned int current_state = WAIT_STATE;
char my_oldSREG; //to hold status register while ints are disabled
unsigned long SensDist = 196850; //Distance between sensors in feet *1000000 60mm
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;


void setup () {
Serial.begin(57600);
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
reset_variables();

}


void loop () {
switch (current_state) {
case WAIT_STATE:
if(digitalRead(Trip_in_1)==LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
}
break;
case MONITOR_STATE:
while(digitalRead(Trip_in_2)==HIGH); //loop until the Trigger goes LOW && !is_timeout
if(!is_timeout)
Trigger_2 = micros();
current_state = OUTPUT_STATE;
break;
case OUTPUT_STATE:
//if (Trip2 > Trip1) {
output_serial_info();
reset_variables();
current_state = WAIT_STATE;
//}
break;
}
}

void output_serial_info() {


// Serial.print("Duration\t");
Serial.println((Trigger_2 - Trigger_1));
//Serial.println(" uS");
}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
//is_timeout = false;
}



Zzz... Zzz... said…
Can you please share your App Inventor project (.aia) i want to change FPS to m/s
Gadjet said…
You can get it here
http://gallery.appinventor.mit.edu/#page%3DApp%26uid%3D1144001%26label%3DBluetooth%20Chronograph%20Link

but it's the App inventor classic not the App inventor 2.

I'm working on creating an .aia version in app inventor 2.
Zzz... Zzz... said…
Thanks Gadjet ;)
Anonymous said…
Excellent project Gadjet! I have the HC06 and Nano working (no sensors yet) with Android Apk you wrote, but how can I change the "text-to-speech" vocal announcement in the apk from FPE to FPS? I would like it to announce FPS (velocity) only.

I used APKtool to decompile the apk file, but I cannot find any files that I can edit for text-to-speech options.

Thank you.
tomsz said…
Follow up for above on changing FPE announce to FPS. I downloaded appinventor folder zip, and found in "src" folder a file "Screen1.scm" that has the code I think. But I am in Windows. I think it needs to be edited in Android Environment (Virtual Box in Windows?) and "build" again into apk?
Gadjet said…
tomsz,
I have added a link to the bottom of the post to download the appinventor2 source file.
visit http://ai2.appinventor.mit.edu/ signup it's free and import the aia file.

It speaks FPS out of the box.

You can then edit it as you wish, I've also added a link to the APK file.

I've not tried these files as they are conversions from appinventor1 which has been closed.

Let me know if they work or not!

Cheers.
Gadjet said…
I've added a third link to a new AI2 app I had been working on, this one gives the option to speak FPS, FPE or shot count.

You can also get it to beep on every 10th shot and write the shot string to a file.

Now it was quite a while ago I was working on this so it may not work perfectly, I can't remember how I left it.

It does give an error when first started but if you press the backup button you can then add some settings information and click "Calculate/Close" it should work OK from then on.
tomsz said…
Gadjet, really appreciate the quick reply and the information. I have some gaps in my knowledge, and I may be testing your patience with my long text below, but this is what I have so far:

My setup:
Nano+HC06 connected to Windows PC running Arduino IDE and using Android phone 5.0 via bluetooth. The Sketch on the Nano is "Distance between IR sensors" is the simple Version 0.1 Phil Grant 25/04/13 (D2/D3 triggers). The sensors are on the way, so for now hard coded the value of 200us for serial printout as trigger2-trigger1 value. Not sure who to wire two switches for trigger, so instead I pulled the High (5V) output by D2 and D3 separately with 150ohm resistor to ground to simulate pellet passing, but it gave random values like 404838992, 34499922, etc at the PC Arduino Serial Terminal. So ended up using 200us hard code for now with a 4s delay.

Your Apk software:
Bluetooth worked flawlessly in all cases. The first version of Chrono.apk that has only one "Speak" checkmark and NO "Combro" checkmark....worked, This one only announces FPE and not FPS. Values like 404838992, 34499922 crash it.

The version with "Speak" checkmark and also the "Combro" checkmark option did not work. It connects via Bluetooth, but no data coming(?), and would not even crash. I would have loved to see the Combro option work. Can one run the Combro serial cable TX/RX/GDN to the Nano's TX/RX/GND and still use the HC06 to transmit the Combro data? I know the Combro uses decimal ASCII numbers, so I think only this version of your phone apk could interpret the incoming ASCII from the HC06.

The third version works with the work-around you noted. This has the three "Speak" options for "Shot", "FPS", and "FPE", "10 shots" and has "write" checkmark option. It worked with the 200us fake data, but zero when sending values like 404838992, 34499922. It only announces one "Speak" data at the time even if all checkmarks are selected, no big deal. But, not sure how the "write" feature works. Will check for a log file later in the phone's app folder.

I managed to setup your latest AI2 app on MIT App Inventor. I need to dwell in much much deeper how this AppInvevtor system works if I would want to change/add more features in the future. At times like this when I realize how little I know :)

Thank you for your guidance and the time you take out the help. This is an amazingly versatile project and I hope to contribute as I am slowly filling the gaps in my knowledge.
Gadjet said…
Tomz,
Basically switching the inputs to ground will trigger the inputs but do it in the right order.
The output is a single value in uSeconds which is around 300 to 400 uSeconds depending on the distance between the sensors but manually pressinf switches will give you a much longer delay.
I used a simulator sketch to send values whilst working with the app

void setup() {
Serial.begin(9600);
}
void loop() {
for (int i=300; i<= 400; i++){
Serial.println(i);
delay(5000);
}
}

Yes only one speak option will work at a time, there was something to do with the queuing of the speech requests I never got around to fixing.

let me know how you get on I don't mind helping out.
tomsz said…
Thanks Gadjet. The simulator loop helped with making sure the electronics is not the problem. Do you have the AI2 files to the latest APK? The one with the "10 shot" count. The only AI2 file you had linked was the one with the "combro" option and I cannot get that to work on my Android phone. AppInventor is something I never knew about, so started on the tutorials. When I pulled up the "combro" AI2 file in AppInventor it had no "warnings" but had a yellow triangle caution about "block should be connected to and event or procedure". I got rid of it by just adding a no-purpose input module, but didn't get me anywhere.
Gadjet said…
Tomsz,
I've added a link to the AI2 app in the AI2 gallery, this should allow you to open the app directly in the appinventor site.
tomsz said…
Thanks Gadjet! Opened the AI2 from the Gallery. Based on that I was able to go back to the "Combro" version of the AI2 that was not working as an APK and fixed it by simply reattaching the "Clock-timer...do" module to the "if then" main program blocks. Did an APK "build" and now the "combro" APK works to on the phone. I hope to incorporate the "combro" module into the latest AI2 with the "10 shot" feature.

One question: I have the actual Combro Chrono with the DB9 serial and the Serial-to-USB adapter. How do I interface the DB9 or the USB side to the HC06? Do I need Arduino between to accept the data sent by the Combro and then send it to the HC06?

Thanks again!
Gadjet said…
I think you connect the serial TX and RX from the DB9 connector to the TX/RX of the HC06 and the combro sends a value in uSeconds, all the app does is divide this value by 4 because the Combro uses a 4MHz clock instead of 16MHz like the Arduino.
I've never used a Combro with it but someone else did and said it worked OK, let me know if it works OK.

Don't forget to cross the TX RX.

TX==>RX
Cobro HC-06
RX==>TX
Gadjet said…
Sorry it too out the spaces and I mis-spelled Combro .....
tomsz said…
Thank you Gadjet for the lighting fast reply! Will test with the Combro tonight (EST). My sensors supposed to arrive as well today or tomorrow :)
tomsz said…
Gadjet,

Not sure how, but I managed to reverse engineer the two AI2 files and updated version 3.0 with a couple of features and added back Combro support. I pushed it back to the Gallery as "Bluetooth_Chrono_v3_1", giving you credit for the app and noted my minor revisions. Still has the start up problem, I think it's expecting a value but getting zero. Must be during the start up sequence.

- Added "Combro" support
- Added "magazine capacity" selection option for empty beep sound. Or select type in any number so it beeps after X number of shots (and repeats).
- Changed some font sizes larger (worked on my Moto E, but may not work on all phones)
- Expanded Fps to four digits and FPE to 3 digits lengths

Thank you again! Hope I can soon test with real sensors instead of the simulation loop.
Gadjet said…
Tomsz,
Great news, some of the things I was thinking of doing but never go around to it.

Hope you get the sensors working OK, let me know how it goes.
tomsz said…
Gadjet,
The sensors are still not here, so I was working on the Combro interface. I managed to get the correct 8-bit ASCII code showing up on my PC serial terminal, for example 00002812 for 280fps and 00000972 for 810fps. But I think in order to send that data to be read by your program the zeros need to be stripped out: 000002812 => 2812 or 00000972 => 972. Any idea what is that called? Or how to do it in the software coding of the Nano?
Gadjet said…
Tomsz,
Interesting question, I don't own a Combro so I've never used the SW with one, someone else did and fed back that it worked.
Without looking into the App I would think that the value would be treated as an integer and therefore would ignore the leading zeros in any calculation, have you tried connecting the serial output from the combro to the HC-06 ?

I wouldn't feed it into the nano because the value is displayed on the combro?? I would only feed it into the HC-06 so I could get it to my phone.
tomsz said…
Gadjet,
Thanks for the quick reply. I don;t see who the HC06 can transmit/receive without being written to with a serial command. But I tried it anyway with the HC06's RX directly connected to the Combro's TX, all GND and VCC common, pulled up. Didn't work. So I ended up finding a code that converts a String to Integer by removing the leading zeroes just like you mentioned. Then ran the Combro into a SerialSoftware port on the Nano, converted to an integer and sent it out o the hardware Serial of the Nano that is connected to the HC06 RX. It sent the right data to the Android phone to your app.
Gadjet said…
That's strange, as far as I know the HC-06 is a serial to bluetooth convertor and the serial output from the Combro should be the same as the serial output of the Nano, I don't think it requires any level shifting, did you try the TX/RX switched around and did you common the grounds together?
tomsz said…
Gadjet, I tried the Combro TX connected directly to the HC06 RX and TX both, but no data is sent. I suspect it has to do with Master and Slave setup for the HC06. I need to did deeper on this. I suspect that my HC06 is slave by default. May be an AT command...
tomsz said…
Yep, the HC06 is a "slave only" device I just read. So I need an HC05 that can be set for either.
Gadjet said…
When the sketch sends serial data to the hc06 it just sends the number. The master slave is to do with the Bluetooth setup. The only thing I can think of is maybe the baud rate.
Gadjet said…
Try here for some info
https://arduino-info.wikispaces.com/BlueTooth-HC05-HC06-Modules-How-To
Gadjet said…
This comment has been removed by the author.
tomsz said…
Thank you, will dig into it. I used 9600 baud N81 everywhere to avoid issues.
Unknown said…
jesus christ, you are so messy...just put one under one project schematic and scetch!!! I kill myself for searching those two!
Unknown said…
This comment has been removed by the author.
iman rezaei said…
Can I use OPL-550 ALTERNATIVE, for example TSOP1138 or HS0038 PHOTOTRANSISTOR?!
TANKS ALOT
Gadjet said…
iman,
I cannot be certain but I would say no to the TSOP1138 or HS0038 as these are specifically designed for TV remote control receivers, they may work but I cannot say that they would. The OPL-550 is the only one I've found that is fast enough and has a digital output, maybe you could find a phototransistor fast enough but you would need to process the analog output signal to feed the processor.
iman rezaei said…
tanks, but I can't find any alternative of OPL-550.
I'm not expert in electronics circuits design. I want to make it for my pcp air rifle regulator tunning.
help me :)
iman rezaei said…
Hi again, Haven't any idea?!
iman rezaei said…
tanks, but excuse me, I can't find any alternative of OPL-550.
I'm not expert in electronics circuits design. I want to make it for my pcp air rifle regulator tunning.
help me :)
Gadjet said…
Hi,
I am not aware of an alternative, why can you not use an OPL-550 ?
iman rezaei said…
Hi, i'm living in Iran.
Its a new and not common element in the domestic stock. we can't buy any thing from web world markets.
its my problem.
:(

Popular Posts

Chronograph update

DIY Chrono Shopping list

Chronograph completed - Finally