Chronograph update

When I made the smaller screw on sensor that connected to the PC and fed the timing into a PC application, it got me thinking about different types of display that could be used and after a a good look around the net I came across a couple of options.

The first was a 7 segment LED display, these come in different shapes and sizes and could still be quite portable when added to the sensor.

The only problem with these displays is the amount of IO needed to drive them as each of the segments require driving. I then came across the Adafruit 7 display backpack, which takes all the hard work out of controlling the 7 segment displays.
The backpack details can be found here

The device is based on an Holtek HT16K33 chip that controls the LED segments and connects to the Arduino via the I2C bus and has a library that makes sending data to the display easy.

I bought one of the displays from Ebay and stuck it on the side of the sensor tube then added the code to the sketch to send the value for feet/second to the display after sending the uSecond value to the PC.


This would allow the chronograph to be used in conjunction with the PC via the USB lead or remotely with a battery pack, just reading the Feet/Second value.


Showing the feet/Second would require a lookup table to get the power from the velocity and the weight of the pellet, I suppose with a couple of small buttons added you could enter the pellet weight after power-up but before the first shot it could then alternate between the FPS and the power reading every 10 seconds?.

I then tried it out using my CP Sport Co2 pistol and it looks good.

I then used some of that PVC heatshrink, normally used for battery packs, it's really good as it shrinks using a hair drier and is quite hard when cool but can easily be removed with a pair of scissors or a knife.

Ideally I would have liked to use some clear but I only have red or white but surprisingly the LED shows through the PVC quite well.

Things to think about: -

  • Writing the shot data to EEPROM for later retrieval
  • Adding buttons to allow pellet weight to entered
  • put together a battery pack for remote usage
  • Think about power saving schemes
  • Display battery power on power-up?
  • Who knows?
Nano Sketch can be downloaded here you can use it with or without a PC, if you want the PC application let me know in the comments, it's still very BETA.
Fritzing file here.

More about the second option I found later.....

Comments

randy said…
Hi, Nice post thanks for sharing. Would you please consider adding a shout out to my website on your next post? I will return the favor. Please email me back. Thanks!

Randy
randydavis387 at gmail.com

Gadgets
Jak Broadway said…
hi, this is a great read, im interested in the 7 segment one you completed. could you please tell me where you got the opl55c photodiodes from as i cant find them anywhere?
Gadjet said…
Jak,
Have a read of this post
http://gadjetsblog.blogspot.co.uk/2013/07/diy-chrono-shopping-list.html
Towards the bottom I've listed the sources for the leds etc.
g.broomfield said…
hi very intrested in the crony ,just got my first arduino uno and love air guns (shoot field target)this looks like a great project for mointering my gun ,very intrested in the pc software side to plot a string of shots as i am a complete noob when it comes to programming ,growen up on plc,s
not c++ or basic .could you please post a link for the software on your site thank
s3k0 said…
nice blog and projects

can we use a sensor other than opl550?
Gadjet said…
Thanks,
Yes you can use any IR LED and detector, I used the ones with a digital output to save on external signal conditioning circuitry.
You could use a simple phototransistor but it would be an analogue output also make sure that the response time is quick enough.
s3k0 said…
can't waiting my orders from china,
i will give you headache when arrived :)
s3k0 said…
again hi gadjet

i have i2c display like this;
http://www.mauroalfieri.it/en/elettronica/display-lcd-1602-i2c-pcf8574t.html

so how can i make skecth file for this screen thanks
serkan
sekocan at gmail.com
Gadjet said…

serkan,
Not certain what you question is, the page you link to inyour post contains the code for the screen have you tried this code yet?

s3k0 said…
sorry for my newbies question for you..
i bought 16x02 lcd-i2c protocol and on chip says "pcf8574t"
so how looks like code(adress) in skecth file for this lcd
i mean;
// initialize the library with the numbers of the interface pins
//standard LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(7, 8, 6, 5, 4, 3);
that thing only 4 pin 5v,gnd,sda,scl like adafruit i guess but i dont know how to :(

another question;
i had 2 pin ir led and emitter i looked your fritzing draw(7 seg disp) opl550 3 pin (+,logicOut,-)

Does this make a difference?
Gadjet said…
No problem, I was a newbie once.
The I2C interface doesn't use the standard LCD library with all the pins defined.
The I2C LCD uses a different library with just the LCD I2C address specified, i.e. 0x27.
The link to the library is here http://www.robot-italy.com/download/LiquidCrystal_I2C1602V1.zip
Save the library into a folder inside your libraries folder in your Arduino program folder and then you can use the code as shown on the web page link you sent me, it should work, let me know how you get on or if you have more questions.

You could also visit the www.arduino.cc website there is a good forum to get answers and tutorial code.
Gadjet said…
s3k0,
If you are using a two pin IR detector you will need to convert the analog output from the detector to a digital output to feed into the input pin of the 328p, that's the main reason O chase a detector with a digital output.
What is the part no. of the IR receiver you are using?
Gadjet said…
sk30,
Here's a link to some information regarding photodiode circuits.
http://www.fiz-ix.com/2013/04/ir-photodiode-circuit-schematic/

Hope it helps.
s3k0 said…
im using 5mm ir led and emitter,i dont know what are they exaclty :)
http://www.aliexpress.com/item/20pcs-5mm-940nm-LEDs-infrared-emitter-and-IR-receiver-diode-10pairs-diodes-301A/1579718658.html

and screen this;

http://www.aliexpress.com/item/IIC-I2C-1602-blue-LCD-module-provides-libraries-For-Arduino/1062018842.html

http://s27.postimg.org/3r9iz9ttv/IMG_20140416_072842.jpg

http://s27.postimg.org/6mmm64xtv/IMG_20140416_073028.jpg
Anonymous said…
s3k0,
I'm a bit stuck really, the things you need to consider with the ir receiver is the speed, phototransistors have a response time to the changing light level, some are quicker than others, I cannot find the speed of yours in the specification.
Ideally you need to put the receiver in series with a resitor ( as per the Circuits on the page link I posted) and use an oscilloscope to look at the waveform as you pass something in between the emitter and detector.
This is the reason why I used the more expensive detector with the digital output, it's a lot less hassle......
s3k0 said…
finally i got picture on lcd screen :)

edited skecth like this for my lcd;
https://docs.google.com/document/d/1tuZnfQ873t8fuN8SA_UkAH5Sd_z5usaBuBNfiaWjLjo/edit?usp=sharing

now, im trying-stucking :) ir emitter-receviers
Gadjet said…
s3k0,
One other thing about your set-up, the IR emitter/detector should be shrouded to stop IR leakage around the object breaking the IR beam, in my test setup I used a tube with holes in ....

http://3.bp.blogspot.com/-i10QqXOQeDA/URfGY4-MhzI/AAAAAAAALHk/OOKinhG2BHk/s1600/Prototype+tube+setup.jpg
s3k0 said…
again hi there phill,
u said "If you are using a two pin IR detector you will need to convert the analog output from the detector to a digital output to feed into the input pin of the 328p, that's the main reason O chase a detector with a digital output"
yes im using 2 pin ir detector, how can i doing this?
can u draw schema for dummy(me)how exactly
Gadjet said…
s3k0,
This link shows the circuit to try.
http://www.fiz-ix.com/2013/04/ir-photodiode-circuit-schematic/

This will give a varying output for the ADC input but there will be a point at which the level will be seen as a digital 1 or 0, i think it is one third of VCC or below to be a 0 or above two thirds of VCC to be a 1.
You could also feed the signal through a Schmitt Trigger or opamp buffer to get a clean digital output.
It would really be a lot easier to use the same IR detectors that I used...... :-) especially if you're not familiar with electronics.
Gadjet said…
Here are some links that might help.
http://www.boondog.com/tutorials/irled/ir.html

http://www.electroschematics.com/tag/photodiode-circuits/?ModPagespeed=noscript

Hope they help.
s3k0 said…
still can't understood that ir-led-receivers :o
im getting blinking 999fps on screen if am block 1 emitter it is stop while serial monitor tell me 20 us 20 us loop :) somethin wrong but i cant tell u :(

http://www.youtube.com/watch?v=tAWjfIinq3I

can you make Fritzing file for me ?
s3k0 said…
if i will go buy opl550 sensor can i get good result i mean is it work :)
Gadjet said…
Did you try the fritzing file?

Mine works so your should! Just remember the LEDs should be each side of a tube.
s3k0 said…
Still i cant get it work ..can i need change something in skecth file??
Gadjet said…
Go back to basics.
Use the sketch from this post, don't bother with the display just use the serial output. (Add your display code later)

Connect two switches to the inputs (pins 2 and 3 I think) and use the switches to trigger the inputs and make sure the serial data agrees.

Once that works as expected then add the IR triggers but make sure your setup is suitable to get a good break beam trigger.
s3k0 said…
random clicked buttons and results;

Duration 24 uS
Duration 268740 uS
Duration 73940 uS
Duration 24 uS
Duration 20 uS
Duration 20 uS
Duration 20 uS
Duration 20 uS
Duration 88064 uS
Duration 20 uS
Duration 166816 uS
Duration 145036 uS
Duration 91928 uS
Duration 20 uS
Duration 107672 uS
Gadjet said…
I held both switches under my thumb and pressed at the same time (rolling my thumb) in such a way that the trigger 1 input was always pressed slightly before trigger 2 input or one switch in each hand and following a stopwatch press then a second apart.

If the readings look good then the sketch is fine. Next will be to sort out the IR beams.
s3k0 said…
finally i got progress...
all i need was opl550a :) problem solved..
now the next question max fps 999 can i get more ?
Gadjet said…
Great news, you aren't in the UK then if you want more than 999 fps.
I will look at the code tonight but is there a simple check to see if the value is below 999 and only send out data if it is, this can be changed to whatever value you like.
There will be a limitation to how fast the detection will be but I've not figured it out.
Gadjet said…
This is the line in the code
fps = constrain(fps,0,999); //limit fps to plus value upto 999

Also have you set your sensor distance correclty.

unsigned long SensDist = 333333; //Distance between sensors in feet *1000000
s3k0 said…
hi again,
im tested system today so i got 1515fps :) i know its wrong cuz i have mk4is 16grain 875-876fps always
so u said;

Also have you set your sensor distance correclty.

unsigned long SensDist = 333333; //Distance between sensors in feet *1000000
how u got 33333? what is formula this thing can u explain to me thanks...
Gadjet said…
Sorry if you've already said but what's the distance between your sensors, the calc to give 333333 ois for 100mm.
Calc for 60mm =
((60mm/2.54)/12)×1000000= 196850
Hope this sorts it out, this would give 896.4 fps
Gadjet said…
s3k0,
Did you get it working correctly?
s3k0 said…
edited skecth file to for correct trigger distance but i cant test yet, i will let u know when i tested
s3k0 said…
i tested today couple shots i got the 820-805-824fps something wrong but i dont know cuz same rifle with orginal chrony 860-865fps with 13.43 grain(fx t12 with regulator)
Gadjet said…
Seems to be better than before but still not consistent.
PCP with regulator would be more consistent, some things that could be affecting readings: -
the mounting and distance between sensors, I face the emitter detector pair at each other through a 2mm hole to try to make a norrow area of triggering.
The metal tube I use keeps most of the ambient light out.
The holes are exactly through the centre of the tube so the pellets travel through the centre of the beam.
The tube is firmly secured to the barrel.

I must admit I've not really looked at the variance of fps over a string of shots I've been only interested in the power aspect, it's possible that the software could be introducing a variance in the reading, maybe using interrupts to trigger the measurement could improve the consistency, I'll look into it.
Gadjet said…
Another thought, the FPS is quite high, in the UK 760 fps is more usual, with a higher speed there is less time to measure the travel 96uS at 860fps, this would mean a few uS difference would make a bigger change to the indicated fpes.

How far apart are your beams? try increasing them, 100mm maybe, this would give a longer interval making any processor cycle variance less important.
Gadjet said…
96uS/inch that is.
When trying to verify the following section is highlighted "Adafruit_7segment matrix = Adafruit_7segment{}; with the comment stating "'Adafruit_7segment' does not name a type". The highlighted section is in the begining of the sketch just after "#include "Adafruit_GFX.h". Does this need to be changed or am I missing something else in my set up.? Any help would be greatly appreciated. I have little to no experience with Arduino sketch writing but found your design on line and really liked the chronograph characteristics and really wanted to make one. So, I really hope you can ease me through this hang up and get me out shooting. Thanks again for your time and help with this issue.
s3k0 said…
i did another chrono using with attiny2313

http://www.youtube.com/watch?v=zFlcWr1jlRg
Gadjet said…
Brian,
I assume you mean you are getting an error when you compile the sketch, have you downloaded the adafruit libraries and placed them in the library folder? I think your sketch is looking for the library.
Gadjet said…
sk30,
That looks really good,I like the fact that the display is facing you.
any chance of some better pictures or maybe some code , I have some smt attinys kicking around somewhere, I would like to make a pcb including the leds and processor, it would be quite small.
Chronograph said…
This would allow the chronograph to be used in conjunction with the ... ochronograph.blogspot.de
Anonymous said…
Hi

Is it possible to make a sketch of how components are connected to each other ?

Gadjet said…
Sorry, I don't understand, there is a sketch in the post, do you mean something else?
Anonymous said…
Gadjet, thank you for your answer.
I bought the items as below:
Photo sensor OPL550A
IR Emitter LED OP240A
I wonder. Did I should add a resistor?
Gadjet said…
My apologies you are correct, add a resistor to the LED emitters supply as required to limit the current, I should have added them to the circuit.
Anonymous said…
What kind of values ​​should be resistors for LED OP240A?
I'm not an expert in this but I think 160Ω will be good.
The calculation result data http://optekinc.com/datasheets/op240-245.pdf
Is something going to happen if I give a larger resistor 200Ω
Anonymous said…
In my resources I have only 200 ohms.I checked it looks like it works :)
OPL550A do not need a resistor? (Arduino Nano 5V supply)
Anonymous said…
Something works :)

Duration 534040
Duration 224540
Duration 200288
Duration 3414768
Duration 90524
Duration 32500
I move the pen from one to another sensor.
The slower I do it the higher score.
I have to decipher the code. At the same I 'm bad :(
Gadjet said…
Great news.
200 ohms should be fine, the led emitters are very close to the sensors so you could probably use even higher values to save power if running off a battery.
Anonymous said…
In the code I made some changes. You can see them in the link below.
https://drive.google.com/file/d/0B_EqFfSmX6RhY1V2eV8tTWg0eE0/view?usp=sharing
I added fps , mps.
The distance between the sensors should be exactly 60mm?
How accurately do the prototype?
Intuition tells me that it must be the most thoroughly :)
Gadjet said…
Please change the code as you wish and post it so others may use it.
The distance between the sensors is very important, having said that you can make it whatever you wish and then adjust the value code to suit, the greater the gap the more accurate the count but then there will be more deceleration in the pellet over the distance.
I have two sensor tubes, one 60mm and 100mm.
Anonymous said…
I modified the code. I wrote to view fps , mps , jouls .
I wonder how to add a feature that downloads the wage pellets in grams?
https://drive.google.com/open?id=1VLVPHUSnKKl691OgpLndaJ_OxpwaWugRQrbOU3TlQTc
Gadjet said…
Anonymous,
There are several options ...
1. Add the calculation for power in your sketch (formula is in one of my sketches or just google it) and send it out serially.

2. Use some PC software, (link in another one of my posts) to show data and input weight of pellet.

3. Add a Bluetooth serial interface (discussed in another post) and send the time to your phone and use the app to add the weight and calculate the power. (link to app also in a post)

4. add a local LCD display to show FPS and Power.
Anonymous said…
So far I am too weak for points 2; 3
On the web I found a point 2; 3 but no 1
I do not know how to retrieve data from PC console and use the program :(
Gadjet said…
For no. 1 see here for the formula
http://www.pyramydair.com/article/What_is_Muzzle_Energy_August_2003/5

You can get the PC software install here
https://dl.dropboxusercontent.com/u/2253850/PC%20Chrongraph.rar
Unzip and run setup, It's been a long time since I looked a this so there maybe some issues.
Try it and let me know.
Gadjet said…
For no. 1 see here for the formula
http://www.pyramydair.com/article/What_is_Muzzle_Energy_August_2003/5

You can get the PC software install here
https://dl.dropboxusercontent.com/u/2253850/PC%20Chrongraph.rar
Unzip and run setup, It's been a long time since I looked a this so there maybe some issues.
Try it and let me know.
Anonymous said…
Gadjet thanks for your reply
I understand calculations . All I was able to implement.
Now I want to add the weight of pellet from the keyboard.
For instance when the program starts.
Now the weight is entered permanently in code.

The program requires Windows 32bit?
Gadjet said…
OK good.
I'm not sure how to enter the weight into the program, maybe use the serial port and use the terminal in the Arduino IDE to send a value to the Arduino to store in the eeprom?

Yes, 32bit windows
Anonymous said…
"Sorry if you've already said but what's the distance between your sensors, the calc to give 333333 ois for 100mm.
Calc for 60mm =
((60mm/2.54)/12)×1000000= 196850
Hope this sorts it out, this would give 896.4 fps"

If the distance between the sensors is 100mm the result is 328083. Is this the result requires rounding to 333333?
Gadjet said…
Anonymous,
The calculation is correct, I have two sensors 100mm and 60mm, the code I posted was probably for 100mm and I probably adjusted it because the distance wasn't exactly 100mm when I measured it with a digital vernier.

I also used an oscilloscope to check the timing between pulses and compare to the measurement calculated by the sketch.

BTW I've since modified the sketch to use the interrupts but not fully tested it.
Anonymous said…
Photo sensor - OPL-550a and IR Emitter LED OP240A they are arranged in the tube. Elements are spaced apart by 32mm. It Appears That this distance is too big. System oblicza szaleje więcej strzałów w nieskończoność. Did you have a similar problem ?
Gadjet said…
I had a smaller gap than that, about 20 mm apart.
Do you have them either side of a tube or in the open air?
Anonymous said…
I tried many times. In the pipe and the open air . Confirm the action on the open air to 30 mm. The pipe has exactly 32,08mm and no longer works. On the open space it behaves strangely . If the sensors aligned to each other and then increasing their distance then it starts to work on up to 32mm . If the operation of the system with a fixed distance of 32mm sensors do not see. I assumed it would be like the remote control for the TV. At first, the distance was not an problem.
Gadjet said…
Have a look at this post, the idea is to form a beam that will be broken with a pellet, it the sensors are in the open air or too far apart then there will be a wider beam that gets around the pellet.

I use a thick walled tube around 3 to 5mm with an OD of 20mm, this creates a sweet spot for the detector and allows the passing pellet to block the IR light from reaching it.

see picture http://2.bp.blogspot.com/-R3_HMY4XC-k/USFBvyr81hI/AAAAAAAALIM/Khj9x4Qrelw/s320/tube+sensor+section+cut.jpg

Hope this helps.
Anonymous said…
I think that I am doing something wrong . Even if I can cross the two goals on the display I see strange readings. 0.01 ms . It looks as if he did not read fast shots.
Gadjet said…
I can say that I've spaced my sensors 60mm apart and I have no problems detecting shots reliably, the only time I have issues is when I used it on my CO2 pistol and the first couple of shots were way too fast, I pout it down to a fresh CO2 cartridge and CO2 gas causing false detection.
I use it with my PCP with no problems, what tube are you using, material and size and how far apart are your sensors?
Anonymous said…

The distance is 100mm I try to measure the speed of HW97k. Maybe too fast for Arduino Nano.
Anonymous said…
I tried with a ball of paper. The ball is large enough not miss the sensors :) At bigger speed no reads. I tried to Arduino Nano and Leonardo. It is possible to speed up the reading?
Gadjet said…
I wouldn't use a ball of paper, you need to use something solid and opaque so no light can make it through.

I used an aluminium tube (about 20mm OD with 14mm hole) then drilled the two 3mm holes across the tube 60mm apart and fixed the sensors to the sides of the tube I then used a cheap bic pen with the ink tube removed and used it to drop pellets into the aluminium tube so they fell through the centre between the sensors.

You could also use a ball bearing just smaller than the tube internal diameter, this will guarantee that the beams are broken.
Anonymous said…
Can you explain why the distance between sensors counts in such a way?

"Calc for 60mm =
((60mm/2.54"inch")/12"inchy")×1000000"?"= 196850"
Thank you very much
Gadjet said…
OH!now you asking.
If I remember it's all about how many microseconds it takes to travel over the 60mm and also convert from the mm into feet per minute.

60mm divided by 25.4 gives distance travelled in inches = 2.36 inches

divided by 12 to give the part of a foot = 0.197 feet.

The 1000000 is because we're using the microsecond timer.

When the value 196850 is divided by the time taken in microseconds it give the answer in feet per second, if the space between the trigger beams is changed then the value changes to still give the FPS.

Does that help?
Anonymous said…
So that solved the case. Thank you very much!
Gadjet said…
Glad to hear it. By the way which sketch are you using?
Anonymous said…
I got help in another forum to change the code . The device runs faster and there is no problem with the detection of the missile. I added some lines of code but the speed of the program has provided Polish forum www.forbot.pl

#include
#include
#include

#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

#define firstsensor_1 10
#define secoundsensor_2 11



unsigned long time1;
unsigned long time2;
float fps, elap, ms, joule;



float bullet_weight; //The mass of the projectile (gr)
float bullet_weight_kg;

int counter_shots = 0; //After each shot 1++

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {
lcd.begin (16,2); // <<----- My LCD 16x2
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH); // Switch on the backlight
Serial.begin(9600);
pinMode (firstsensor_1, INPUT);
pinMode (secoundsensor_2, INPUT);
digitalWrite(firstsensor_1, HIGH);
digitalWrite(secoundsensor_2, HIGH);
reset_variables();
}


void loop() {
lcd_i2c();

Serial.println("I am waiting for a shot - YOU can shoot!");


while(digitalRead(firstsensor_1) == 0);

while(digitalRead(firstsensor_1));
time1 = micros();


while(digitalRead(secoundsensor_2));
time2 = micros();


printserial();

}


void printserial(){
Serial.print("Shot number:\t");
Serial.println(counter_shots++ );
elap = time2 - time1;
fps = 328083/elap;
Serial.print("FPS\t");
Serial.println(fps );

ms = fps * 0.3048;
Serial.print("MPS\t");
Serial.println(ms );


bullet_weight = 0.51;
bullet_weight_kg = bullet_weight/1000;

joule = pow(2, ms)*bullet_weight_kg/2;
Serial.print("JOULE\t");
Serial.println(joule );
}

void reset_variables() {
time1 = 0;
time2 = 0;
}

opango said…
This comment has been removed by the author.
opango said…
This comment has been removed by the author.
opango said…
hello it's very interesting project, i use Catalex TM1637 7 segment display, can u modified the sketch for the display pliss

i try to make the sensors, the distance of the sensor 0.5 feet, when i modified the sketch using TM1637 display, it says: "error: 'matrix' was not declared in this scope" then what should i do?

thx before
Gadjet said…
Have you loaded the library ?
Have a look here https://github.com/avishorp/TM1637
opango said…
yes, i have loaded TM1637 library,
i just modify for it's display and sensor distance:

#include
#include
#define CLK 2 //can be any digital pin
#define DIO 3 //can be any digital pin
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#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 = 500000; //Distance between sensors in feet *1000000 0.5 feet
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;

.
.
.
.
.

the sensors is not connected yet and i try to verify,
but still unverified:

exit status 1
'matrix' was not declared in this scope

i just wonder where the name 'matrix' came from, is it from Adafruit_7segment matrix = Adafruit_7segment(); properties? if yes, sure there is no connection for TM1637, so the sketch must be change but i don't know how.. i'm newbie and need help



opango said…
This comment has been removed by the author.
opango said…
sorry, missing fonts for

wire.h
TM1637Display.h
Gadjet said…
Looking at the code you posted you are defining the display control pins to the same pins you are using for monitoring the sensors, 2 ad 3.

You need to use different pins for the display
#define CLK 2 //can be any digital pin >>USE ANOTHER PIN
#define DIO 3 //can be any digital pin >>USE ANOTHER PIN

TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

I'm not familiar with the display so I will have to have a look but I cannot do it straight away.
opango said…

finally i could upload the sketch for TM1637! but..
one thing that made me crazy because my display won't power up, several hours thinkin about it huh.. then i check continuity one by one all the cable jumper and found one of the cable jumper is bad, broke in the middle, that's it, after changing the jumper my display finally show up.

i don't have op550 ir sensor, it's difficult to find here in indonesia, so for testing it work or not, i use 2 IR avoidance sensor modules, connect the output to pin 4 & 5. i put that modules on breadboard just 1 inch distance between sensors only just for testing, open air sensors, set the modules potensio just before led indicator lights on then i move my finger +- 1 inch upon sensors as quick as possible for several times. it's works, sensors led indicator blink, and the display shows values. i try to shot with air rifle upon sensors but unfortunately sensors wont detect the pellet, maybe pellet is too small or too fast..

Then i bought IR led and universal IR receivers usually for tv/dvd remote control, set them on breadboard, but shows continuity random values..

may be tomorrow i'll try another type IR sensor


*/
#include Wire.h
#include TM1637Display.h
#define CLK 2 //can be any digital pin
#define DIO 3 //can be any digital pin
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#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 = 500000; //Distance between sensors in feet *1000000 0.5 feet
unsigned long duration = 0; // time between triger 1 and 2
volatile boolean is_timeout = false;


void setup () {
//Serial.begin(57600);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();
}


void loop () {

switch (current_state) {
case WAIT_STATE:
if (digitalRead(Trip_in_1) == LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
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");
display.showNumberDec(500000 / (Trigger_2 - Trigger_1));

}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
is_timeout = false;
//Timer1.stop();
}
Gadjet said…
Good to know you got it working, I hate it when something like that happens when you spend a long time trying to find it.

The reason I use the IR detectors is they are very fast and have a digital output.
Gary lim said…
Hi gadjet!! Nice work... i have some few request.. can you sketch this.. display for fps and then rate of fire using single button.. i know nothing about programming.. i just tinker with electronics... thank you!
Gadjet said…
Thanks, I suppose it's possible to add a button to switch between FPS and rate of fire. I'll have a look at it but I may not be quick at doing it!
Gary lim said…
Thanks Gadjet!
Rob van Duijn said…
Hi Gadjet,

I have a Arduino Nano with a TM1637 with the following commands.

/*

*/

#include
#include "TM1637Display.h"
#define CLK 2 //can be any digital pin D2
#define DIO 3 //can be any digital pin D3
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#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);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();

}


void loop () {


switch (current_state) {
case WAIT_STATE:
if(digitalRead(Trip_in_1)==LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
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");
display.showNumberDec(199475 / (Trigger_2 - Trigger_1));
}

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

But I can't write it to my Arduino Nano. Can you help me what I do wrong.
Gadjet said…
I need a bit more info than that to try and help, are you getting an error from the IDE when you try to program?
Rob van Duijn said…
I have the same parts as you got. Only I have a TM1637 instead of the adafruit.
When I want to upload/verify it to my arduino nano by the arduino web editor.
I got a error ( a red bar) but there is no text on it what is wrong and I can't upload it.
Also have I import the tm1637display.h in the sketch.
Gadjet said…
Rob,
I haven't come across a "red bar" before, do other sketches load OK, have you selected the serial port and the correct arduino board etc.?
Rob van Duijn said…
I just try the Arduino 1.8.1 and it is a compile error.
Do you use another software?
Rob van Duijn said…
Yes I tried youre sketch. And thay was not a problem.
Gadjet said…
OK, You have an include statement at the top of your code that does nothing, remove that.

I downloaded the TM1637Display library and included it and the sketch compiled fine in Arduino 1.8.0, did you install the lbrary correctly?

Here's the code that works for me:

#include "TM1637Display.h"
#define CLK 2 //can be any digital pin D2
#define DIO 3 //can be any digital pin D3
TM1637Display display (CLK, DIO); //set up the 4-Digit Display.

#define Trip_in_1 4 //set light Trigger 1 to pin D4
#define Trip_in_2 5 //set light Trigger 2 to pin D5
#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);
Serial.begin(9600); // use for unmodified BT module
display.setBrightness(0x0f); //Setup 7 Seg Display
pinMode(Trip_in_1, INPUT);
pinMode(Trip_in_2, INPUT);
digitalWrite(Trip_in_1, HIGH); //turn on pullup resistor
digitalWrite(Trip_in_2, HIGH);
display.showNumberDec(8888);
reset_variables();

}


void loop () {


switch (current_state) {
case WAIT_STATE:
if(digitalRead(Trip_in_1)==LOW) {
Trigger_1 = micros();
current_state = MONITOR_STATE;
// Timer1.setPeriod(my_timeout);
}
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");
display.showNumberDec(199475 / (Trigger_2 - Trigger_1));
}

void reset_variables() {
Trigger_1 = 0;
Trigger_2 = 0;
is_timeout = false;
//Timer1.stop();
}
Rob van Duijn said…
Hi Gadjet,
Thank you very much.

The first time I was getting the same problems. I have uninstall al the software.
And I try it again. now it works with my sketch and the sketch of you. The problem was a hard- and software problem of my pc.

But now it is working. Thanks.
Anonimoqlo said…
where can I found the sketch?

Popular Posts

DIY Chrono Shopping list

Chronograph completed - Finally