NerdKits - electronics education for a digital generation

You are not logged in. [log in]

Support Forum » TRACTOR PULL SLED MONITOR

April 26, 2009
by JKITSON
JKITSON's Avatar

I NEED TO BUILD A SPEEDOMETER AND DISTANCE MEASURING MONITOR.

I CAN PROVIDE A SIGNAL FROM A MAGNETIC SENSOR THAT SENDS A PULSE EVERY TIME A TOOTH ON A GEAR PASSES IT.

NEED TO CALCULATE SPEED UP TO 5 MPH ie 2.8 MPH.

NEED TO CALCULATE DISTANCE UP TO 250 FEET.

HOW DO I CONVERT THE SIGNAL FOR THE AT168?

THANKS JIM

April 27, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Jim,

Do you have more information about the magnetic sensor? Is it a "Hall effect sensor" with a digital output, or something else? If you have a digital output, you can just connect it to any free I/O pin. Otherwise, you'll have to do something more analog, possibly involving the ADC.

Once you have the signal, you can try to count how many pulses arrive, and this will be directly proportional to distance. For your speed measurement, the simplest thing would probably be to count how many pulses arrive in a certain time window.

You also might have to look into "debouncing" your input unless the analog part has sufficient hysteresis. That means that you don't want noise to make it look like many pulses are happening when really it's just in the middle of a transition.

Let me know if that helps and if you have a model number or datasheet for the magnetic sensor.

Mike

April 27, 2009
by JKITSON
JKITSON's Avatar

THANKS I WILL GET MORE INFO ON THE SENSOR.. JIM

May 05, 2009
by JKITSON
JKITSON's Avatar

Hi Mike,

The sensor has no name or part #. It was purchased for a replacement pickup for a tach. in a motorhome.

It is a 3/4 x 2 3/4" threaded houseing with a round magnet in the center. There are 2 leads coming out of the unit.

When i connect one to ground (neg buss) and the other to the input a/d that the temp sensor used and flash metal bar past the sensor i get a numeric reading on the lcd of approx. .90 to 1.50.

Hope this helps..

Jim

May 05, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Jim,

I was able to find these two PDFs which describe this type of sensor: http://woodward.com/pdf/ic/82510.pdf and http://woodward.com/pdf/ic/02010.pdf. Does this look like your device?

The way these sensors work is to have a permanent magnet embedded inside along with a coil of wire. The magnetic field lines from the magnet all have to make it from the north pole back to the south pole, but depending on whether a gear tooth is nearby, the field strength will change. A time-varying magnetic field is detected by the coil as a voltage.

I think the first step to take is to mount the sensor and to run your motor at various speeds, and then to use a multimeter (in AC voltage mode) to measure the voltage and (if possible) frequency of the signal. The frequency will be the frequency at which the gear/flywheel teeth are passing by, and my guess is that the AC voltage will be proportional to this frequency. Measure at a few data points to be sure. Once you have an idea of how big the signal is, we'll be able to help you figure out whether any amplification is needed to get that kind of signal into the microcontroller.

Mike

May 06, 2009
by JKITSON
JKITSON's Avatar

OK THANKS WILL DO JIM

May 14, 2009
by JKITSON
JKITSON's Avatar

HI MIKE

I HAVE FOUND THIS OMROM E2E-X10E1 SENSOR. OMRON SPEC. SHEETS SEEM TO BE GOOD. IF THIS LOOKS GOOD TO YOU TO USE I WILL BUY 2 OF THEM (ONE FOR SPARE)

THANKS JIM

May 19, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Jim,

I haven't worked with that kind of sensor before, so I'm a bit hesitant to convey too much confidence, especially for a $70 part! The first thing I notice from the datasheet is that the supply voltage required is roughly 12-24V or 10-30V for the different models. That's a lot more than the 5V supply used for the kit, and it also means that sensor output voltage will be very high when there is no object present.

Basically, I see a sensor that has three wires: one for ground, one for supply voltage (maybe +12V), and one open-collector output. You'll see this "open-collector" term frequently in sensors and sometimes in other digital components. It just means that in the "on" mode, the voltage at that node is pulled to ground (like a closed switch), and in the "off" mode, no current is drawn, so it's effectively a floating voltage. However, if you were to connect it directly to the microcontroller, a current would flow, because the open-collector output will try to stay around the sensor's supply voltage of +12V, and the microcontroller's input pin will cause a great deal of current to flow to prevent that voltage from rising above +5 volts. To deal with that, I think the easiest thing to do is to put in a resistor in series with the microcontroller input pin, such that the maximum current limits itself to some reasonable, non-harmful value. For example, with a 100K resistor, you'd have 12-5=7 volts across it, for a current of 70 microamps, which is small enough that you're not going to cause much heating or other damage.

Mike

June 06, 2009
by JKITSON
JKITSON's Avatar

HI MIKE I THINK I HAVE MABY MADE IT TO 3rd GRADE IN "C" PROGRAMMING.... HAVE THE PROGRAM MOSTLY WORKING EXCEPT I CAN'T SEEM TO GET A FLOATING VARIABLE TO PRINT ON THE LCD, ONLY WHOLE NUMBERS. I DON'T SEE WHERE YOU ADDRESS NUMBERS WITH DECIMAL POINTS IN YOUR LCD LIBRARY..

I NEED TO DISPLAY xxx.xxx and x.xxx

THANKS JIM

June 06, 2009
by mcai8sh4
mcai8sh4's Avatar

Is this what your after :

fprintf_P(&lcd_stream, PSTR("number : %.2f"), decimal_number);

where decimal_number is a double. This will display x.xx use %.3f for x.xxx for xxx.xxx use the same (numbers before the decimal point are displayed anyway.

If this is not what your after - post a little code snippet, so we can see what you're doing.

June 06, 2009
by JKITSON
JKITSON's Avatar

HI THANKS ALOT. WORKS PERFECT I SET IT FOR 3 AND JUST WHAT I WANT.. MY NEXT PART IS WRITING CODE TO COMPUTE MILES PER HOUR AND TRAP & HOLD MAX SPEED OBTAINED.

HAVE THE RESET FEATURE WORKING AND THE HOLD INFO FEATURE WORKING.

THANKS AGAIN FOR THE FAST REPLY

JIM

June 06, 2009
by mcai8sh4
mcai8sh4's Avatar

Glad it worked! Once you have it calculating MPH, max speed shouldn't be a problem. I'd guess at a simple if statement, along the lines of

double max_speed = 0;
...routine calculating speed in MPH...
if (speed > max_speed)  
    max_speed = speed;
....

The > is for '>' it wont let me enter that in the code on this forum - should read (speed > max_speed)

I don't really know your setup so I can't help with the MPH calculations. I would imagine you'd have to something like know the distance moved per signal, then using the number of signals per second work out the MPH. You could use the example realtime clock tutorial to get the seconds, then the rest should be straight forward. Like I say, this may not work with your setup, just an idea.

June 06, 2009
by JKITSON
JKITSON's Avatar

HI AGAIN I WILL PUT THE REALTIME CLOCK PROGRAM IN AND GET IT WORKING....

I AM USING THE CALCULATION OF 1 TOOTH COUNT = .037 FEET. I WILL USE A VARIABLE FOR THE .037 SO IF IT CHANGES OR IS DIFFERENT JUST CHANGE THE VARIABLE...

HAVE BEEN TRYING TO WORK OUT THE CODE ON PAPER FOR THE FORMULA OF: RATE=DISTANCE/TIME.

RATE NEEDS TO BE IN MILES PER HOUR.

DISTANCE IS CURRENTLY IN FEET.

TIME WILL HAVE TO BE SCALED TO 1 HOUR I THINK TO MAKE THINGS WORK...

ANY HELP WOULD BE APPRECIATED.

JIM

June 07, 2009
by mcai8sh4
mcai8sh4's Avatar

I've just got out of bed (had a big night, so not quite sober yet, so expect errors), but it should be quite easy to calculate MPH with what you've told us.

For starters, I would use

#define DIST_TOOTH = 0.037

Then you have a constant that can easily be altered (unless you want to alter this value with the program running).

Then having the number of pulses (tooth count) and seconds (or 100th seconds) you can then work it out thus :

1 mile = 5280 feet and speed = dist / time

so if you had 100 pulses over 1 second speed would be :

MPH = ( (100*DIST_TOOTH) / 5280 ) / ( 1 / 3600 ) = ~2.52 MPH

To break this down

100 pules (per second in this example) multiplied by the dist per pulse (0.037) = 100*0.037 = 3.7 feet per second

to convert this into miles, divide by 5280 (number of feet in a mile) = 0.000700758 miles

Perhaps define feet per mile as a constant as well.

Then to get your hours, use

number of sec elapsed (in this case 1) / 3600 (number of second in an hour) = 0.000277778

To check you've got the maths right, it is quick and handy to use google calulator, as this can take care of the units for you. eg

Go to google (www.google.com <- yeah, like I needed to give you the address) and in the search box type our example above, as in

(100 * 0.037) feet / 1 sec in mph

Click search and the first result should be your answer.

So from this you can alter the equation you can alter the equation to suit your needs, then slap it all in a little function, conv_mph(), and you're laughing.

June 07, 2009
by JKITSON
JKITSON's Avatar

WOW FOR SOMEBODY WHO WAS OUT ALL NITE YOU ARE FANTASTIC,,,,

I APPRECIATE THE INFO.. HAVE THE REALTIME CLOCK IN MY PGM AND WORKING...

NOW TO TRAP HOW MANY COUNTS IN 1 SECOND... THEN THE REST IS SIMPLE MATH..

AFTER I GET THIS WORKING I WANT TO INTERFACE THIS TO A WIRELESS UNIT VIA THE SERIAL PORT. WILL NEED ANOTHER MICROCHIP FOR THE REC. END ALSO.

YOUR SYSTEM IS GREAT...

THANKS AGAIN FOR FANTASTIC SUPPORT. JIM

June 07, 2009
by mcai8sh4
mcai8sh4's Avatar

no problem. to be honest, I don't find maths too bad, but getting my head around this AVR thing... well, that's tricky.

I'm amazed it worked, I had to spend a few hours in bed this afternoon to get rid of the hangover! Word of warning - Never do maths when drunk!

To reiterate : Remember folk's, don't drink and derive!

June 07, 2009
by wayward
wayward's Avatar

Nothing to add to mcai8sh4's excellent post; just a shortcut for Firefox users:

the Search box to the right of the address bar can be used for quick Google calculations as well. You'll have to set the search engine to Google, if it isn't already, and then either click in the search box, hit Ctrl-K or Ctrl-L TAB to select it. Type/paste your formula et voilà, a dropdown box opens with the result — you don't even have to press Enter. Praise Google search suggestions!

Sometimes you may have to add a final "=" at the end, if Google doesn't recognize your formula as such.

June 07, 2009
by JKITSON
JKITSON's Avatar

WELL HAVE DROVE MY SELF NUTS ALL DAY TRYING TO USE THE TIMER AND COUNT TEETH ON GEAR. GUESS I HAVE NOT MADE IT TO 4th GRADE YET...

ANY HELP ON PROGRAM STRUCTURE TO GET THE COUNTS IN SAY 50/100 OF A SECOND WOULD BE NICE...

THANKS JIM

June 08, 2009
by mcai8sh4
mcai8sh4's Avatar

Depending on how far you've got - I may be able to help, although we may be getting near my limits here.

Have you got the chip to register a 'pulse' from the gear? Does it change the state of one of the pins?

If so, there are several methods you can look at.

1) A simple if loop - so that if the pin is grounded you can increment a gear_count variable, then compare this number after say one second.

2) set up a pin change interrupt on the pin - when the pin alters state it then runs a function that increments the gear_count variable, then you can compare this. <- I think this is the better option, but more difficult to implement (for me at least).

After you've compared the gear_count - reset the time to zero and start again. The realtime clock example counts up in 100ths of a second. So something along the lines of

if (the_time == 100)
{
    speed = conv_mph(gear_count);
    gear_count = 0;
    the_time = 0;
}

This simply checks until one second has passed, then sends the gear_count to the conversion function, which returns the speed given the gear_count per second (in the post above, gear_count would replace 100). Then reset the_time (so it starts counting the next second) and reset gear_count (so the count doesn't accumulate).

Once you have speed then you can compare it with your desired speed and increase/decrease as required.

There are many ways to achieve the above, and this is by no means elegant, but the theory's there.

I hope this gives you some ideas as to how to continue.

If it helps when I have a bit of free time, I'm going to have a play with the 'pin change interrupt', I'll post the code and a quick explanation, as I feel it could be useful for a number of things. (this may be next week though - I'm snowed under at work)

Keep us all posted on how you get on.

June 08, 2009
by JKITSON
JKITSON's Avatar

THANKS

WILL PLAY WITH THE IDEAS...

I HAVE ALREADY PROGRAMMED A "LATCH" SO THAT I ONLY COUNT 1 COUNT PER TOOTH. I FOUND THAT THE MCU WAS SO FAST THAT IT COUNTED ABOUT 42 COUNTS PER TOOTH.

MY LATCH IS WHEN THE INPUT PIN GOES LOW (0) I ADD 1 COUNT AND THEN SKIP COUNTING UNTIL THE PIN GOES HIGH (1). THEN DO IT OVER.. WORKS..

ONE NOTE WHEN I TRIED TO SET "the_time" VARIBLE TO 0 IT IGNORED ME AND CONTINUED TO COUNT ON UP. I HAVE "the_time" DISPLAYED ON THE LCD SCREEN.

THANKS AGAIN FOR THE HELP AND IDEAS...

JIM

June 09, 2009
by mcai8sh4
mcai8sh4's Avatar

Hmm, I'm just using

the_time = 0;

and it resets it no problem (the time is declared globally as volatile int32_t the_time;

Try making sure that your reset line in definatly being ran. If it's in a loop, check that the conditions are being met so the program enters the loop (if that makes sense)

June 09, 2009
by JKITSON
JKITSON's Avatar

OK WILL DO

IF IT WILL RESET MAKES THIS EASIER...

THANKS JIM

June 12, 2009
by JKITSON
JKITSON's Avatar

I WOULD LIKE TO USE SOME 3" 7 SEGMENT LED INDICATORS...

HOW WOULD I INTERFACE 2 SETS OF NUMBERS X.X AND XXX.XX.

I CAN GET A BUNCH OF MC74450P BCD DECODE DRIVER CHIPS!!!!!

THANKS JIM

June 16, 2009
by JKITSON
JKITSON's Avatar

HI

I NOW HAVE MY UNIT COMPUTING DISTANCE AS XXX.XX FEET

AND MILES PER HOUR AS X.XX.

I HAVE THE HOLD FEATURE WORKING AND THE RESET FEATURE WORKING...

MY MAGNETIC INPUT IS YET TO BE INSTALLED ON THE SLED....

STILL NEED HELP WITH THE ABOVE POSTING.. WANT TO USE SOME BIG (3") SEVEN SEGMENT LCD DISPLAYS. I AM LOST AT THIS POINT AS TO HOW TO INTERFACE THEM.

I JUST FINISHED PUTTING ALL THE COMPONENTS ON A PERM. PC BOARD AND CHECKS "OK"

YOU "ALL" HAVE BEEN SUPER IN SUPPORT AND HELP.

THANKS JIM

June 18, 2009
by mcai8sh4
mcai8sh4's Avatar

Jim - sorry it took a while, I've been away. If you're still having difficulty with the 7-seg displays, then maybe this link will help : 7 segment explained

There's other bits on 7-seg diaplys on this site as well. To be honest, there's quite a few interesting bits on that site - worth spending 15 mins on.

June 30, 2009
by JKITSON
JKITSON's Avatar

HI

THANKS FOR THE INFO ON 7 SEGMENT LCD'S. AT THIS POINT I AM PUTTING THEM ON HOLD. TO MUCH DESIGN AND TO LITTLE TIME...

I WILL USE A SECOND NERDKIT FOR THE RECIEVE END.

I NEED THE CODE TO SEND TWO VARIABLES ie XXX.XX AND XX.XXX TO THE SERIAL PORT. I WILL THEN INTERFACE THE SERIAL PORT TO A SMALL WIRELESS TRANSCEIVER AND THEN A SECOND TRANSCEIVER TO RECIEVE AND INTERFACE TO THE SECOND NERDKIT WITH LCD SCREEN.

THANKS JIM

July 27, 2009
by JKITSON
JKITSON's Avatar

HI mcai8sh4

AFTER A MONTH OF TRYING I GOT THE SERIAL CODE FIGURED OUT...

I AM HAVING A REAL PROBLEM MAKING A OUTPUT PORT OPERATE A RELAY. I HAVE SOME NEW 5VOLT COIL MINATURE RELAYS BUT CANT SEAM TO GET THE COMMANDS RIGHT TO TURN THEM ON OR OFF.

int ready;

DDRB |= (0<<PB1); // OUTPUT GREEN SLED READY STROBE

if(ready) PORTB |= (1<<PB1); // TURN GREEN READY STROBE ON else PORTB |= -(1<<PB1); //TURN GREEN READY STROBE OFF

THIS IS MY CODE FOR SETTING UP THE OUTPUT PORT PB1 AND THE LOGIC TO TURN THEM ON AND OFF. I HAVE ONE SIDE OF THE RELAY TO GROUND AND THE OTHER SIDE TO PORT PB1

ANY IDEAS THANKS JIM

July 28, 2009
by Capt
Capt's Avatar

int ready;

DDRB |= (1<<PB1); // OUTPUT GREEN SLED READY STROBE

if(ready) {

PORTB |= (1<<PB1); // TURN GREEN READY STROBE ON

}

else {

PORTB |= -(1<<PB1); //TURN GREEN READY STROBE OFF

}

Pleas post some images of you work :)

July 28, 2009
by mcai8sh4
mcai8sh4's Avatar

To turn off PB1, I'd use :

PORTB &= ~(1<<PB1);

Capt : Jim's doing a similar idea to you to count revolution speed - well worth looking into how he's doing it!!

Keep us posted Jim!!

July 28, 2009
by Capt
Capt's Avatar

Damn, didn't read the his comment at PB1. You're right mcai8sh4 :)

I know, that's why im at this thread ;)

July 28, 2009
by JKITSON
JKITSON's Avatar

HI BY PUTTING THE BRACKETS IN AS YOU SHOW AND USING HIS CODE THEY NOW WORK FINE.

I WAS READING PAGES 73 & 74 IN THE ATMEGA168 MANUAL..WOW VERY CONFUSING..

HOW DO I GO ABOUT POSTING PICTURES OF MY ASSEMBLY ON THIS FORUM?

DO YOU WANT ALL MY CODE? I AM AT ABOUT 242 LINES AT THIS POINT.

THANKS FOR THE HELP..

JIM

July 29, 2009
by Capt
Capt's Avatar

You could post your code at http://nerdkits.pastebin.com/ remember to click on forever under the "How long should your post be retained?" line.

You probably need to use some images host.

http://www.freeimagehosting.net/ http://www.imageshack.us/

What if every member here could have an images gallery? So that we could have like 3-4 images each of our nerdkits projects?

July 31, 2009
by JKITSON
JKITSON's Avatar

HI CAPT

HAVE BEEN OUT OF TOWN FOR A FEW DAYS...

IF YOU HAD A GALLERY OF SOME TYPE MY WIFE TAKES A LOT OF PHOTOS FOR A TRACTOR MAGAZINE WE PUBLISH SO WOULD BE EASY FOR US...

THANKS FOR THE INFO.

PS.....HAVE YOU TRIED THE ATMEGA328 YET??????

THANKS JIM

August 11, 2009
by JKITSON
JKITSON's Avatar

I NEED SOME HELP ON THE CODE TO READ FROM A SERIAL DEVICE AND INPUT INTO ATMEGA168 THEN DISPLAY ON SCREEN.

I AM OUTPUTING FROM ONE ATMEGA168 VIA SERIAL TO A WIRELESS RADIO.

THE OTHER WIRELESS RADIO IS CONNETCED TO A SECOND ATMEGA AND SCREEN.

THIS IS MY CODE FOR OUTPUT:

      // write message to serial port
      if(serial >= 20) //SLOW DOWN THE TIMES DATA IS SENT TO SERIAL PORT 
            {
        printf_P(PSTR("%.3f  "), max_speed); //SEND THESE 3 VARIABLES TO THE SERIAL PORT
        printf_P(PSTR("%.3f  "), travel);
            printf_P(PSTR("%.3f  "), speed);
        serial = 0;
            }
            else serial++;

THIS IS WORKING TO THE SCREEN ON MY PC.

THANKS JIM

August 12, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Jim,

You should be able to use the scanf_P function to essentially reverse what you have sent. I would recommend that you change your sending code to include a newline:

printf_P(PSTR("%.3f %.3f %.3f\n"), max_speed, travel, speed);

because this way it will be clear where one group of three starts and ends. And then, on the other MCU, you could use something like this to read the ASCII bytes from the serial link and turn them back into floating point variables:

double max_speed, travel, speed;

scanf_P(PSTR("%f %f %f\n"), &max_speed, &travel, &speed);

The ampersands before each variable mean that the compiler should give the scanf_P function the memory address of those variables instead of their contents, so that the scanf_P can fill those variables all at once. Please give this a try and let us know if it works! Sounds great to be communicating wirelessly between two kits.

Mike

August 12, 2009
by JKITSON
JKITSON's Avatar

WOW THANKS

I WILL TRY YOUR SUGGESTIONS AND LET YOU KNOW.

JIM

August 14, 2009
by JKITSON
JKITSON's Avatar

TO MROBBINS

I SET UP THE printF AND COULD NOT GET ANY DATA TO MY PC TERMINAL PGM. I FOUND THAT I HAD TO PRECEED EACH VAR. WITH (double) THEN THE DATA CAME THROUGH TO THE PC.

NOW....PIN 2 ON MCU IS REC. AND 3 IS XMT.

DO I CONNECT THE XMT ON MY RADIO TO REC ON MCU?

I DID BOTH ENDS WITH A CROSSOVER CONNECTION. NO DATA FLOW.....

ANY IDEAS?

THANKS JIM

August 14, 2009
by JKITSON
JKITSON's Avatar

HI ME AGAIN

MY BRAIN JUST WOKE UP.... THE RADIOS ARE 19200 BAUD AND I STILL HAVE NERDKITS AT 115000. WILL TRY MY HAND AT SETTING UP NERDKITS TO 19200 AND LEAVE THEM THERE. MY PROGRAMMING WILL BE A BIT SLOWER BUT THAT IS OK...

JIM

August 15, 2009
by JKITSON
JKITSON's Avatar

HEY YOU ALL

THE TWO NERDKITS ARE COMMUNICATING.....

I FOUND ALL I HAD TO DO WAS ADD THE FOLLOWING LINE AFTER THE uart_init(); LINE

UBRR0L = 47; //NOTE 47 IS FOR 19200 AND THE "0" IN UBRR0L IS A "ZERO" NOT AN "OH"

THIS ONLY CHANGES THE BAUDRATE TO 19200 WHEN MY PROGRAM RUNS BUT DOES NOT CHANGE THE 115200 FOR PROGRAMMING...

WHEN I CHANGE ANY DATA ON THE MASTER THE REMOTE FOLLOWS WITH ALMOST NO DELAY.

I DID HAVE TO USE A CROSS CABLE ie XMT TO REC AND REC TO XMT.

NOW I HAVE TO FINISH MOUNTING IN ENCLOSURES AND PUT ON THE SLED.

JIM

August 19, 2009
by JKITSON
JKITSON's Avatar

THIS IS THE COMPLETED MASTER UNIT FOR THE SLED alt COMPLETED UNIT

August 19, 2009
by JKITSON
JKITSON's Avatar

LETS TRY THIS LINK LINK TO IMAGE

August 19, 2009
by JKITSON
JKITSON's Avatar

LETS TRY THIS LINK AGAIN

FINISHED

September 06, 2009
by JKITSON
JKITSON's Avatar

HERE IS THE INSIDE WIRING OF THE MASTER UNITHERE IS THE WIRING OF THE REMOTE UNIT

JIM

September 06, 2009
by mcai8sh4
mcai8sh4's Avatar

Jim, Thats looking great!!

The whole thing is impressive, but the icing on the cake has to be the wireless part.

Great work.

What kind of range can you get with the wireless?

September 06, 2009
by JKITSON
JKITSON's Avatar

I AM GOING TO MOUNT THE UNITS ON THE SLED TOMORROW AND DO THE FINAL TESTS AND FINAL CALIBRATION BY PULLING THE SLED 200 MEASURED FEET AND ADJUST MY CONSTANT IN THE PROGRAM TO MATCH A READOUT OF 200 FEET. SO FAR IN TESTING I HAVE BEEN 400 FEET APART AND STILL WORKS.

I WILL COMPILE A LIST OF THE ACTUAL PARTS ie RADIOS AND WHERE I PURCHASED THEM.

JIM

September 06, 2009
by rajabalu21
rajabalu21's Avatar

Jim,

The pictures look great. All the best for the field test.

-Raja

September 13, 2009
by jsukardi
jsukardi's Avatar

Jim, do you have a chance to compile list of the parts? For the wireless part, do you just pull it off a PC USB (USB is basically an advanced version serial port) wireless adapter? How do you configure the Authentication for the wireless?

Johannes

September 13, 2009
by JKITSON
JKITSON's Avatar

THE TRANSCEIVERS I USED ARE IN THE 433 MHZ FSK. THEY USE RS-232 SERIAL INPUT & OUTPUT. THESE ARE OPEN UNITS WITH NO AUTHENTICATION. THEY USE 3.3 TO 4 VOLTS POWER.

THE SERIAL OUT PUT FROM THE 168 CHIP (PINS 2&3) GO DIRECT THE THE RS-232 INPUT & OUTPUT ON THE RADIOS. THEY WORK AT 19200 BAUD SO YOU HAVE TO SET YOUR PROGRAM TO USE 19200 TO COMMUNICATE.

SO FAR THEY WORK GREAT

I BOUGHT THEM FROM http://www.sure-electronics.com/ PART #GP-GC010 UNDER 18.00 FOR THE PAIR.

HOPE THIS HELPS

JIM

September 18, 2009
by IvonV
IvonV's Avatar

So, Jim when you program, do you remove the wireless from the header and replace it with the programming unit or did you figure a way to daisy chain the programming header with the wireless and address each component serially?

September 18, 2009
by JKITSON
JKITSON's Avatar

I PURCHASED EXTRA 4 PIN HEADERS AND CABLES FROM NERDKITS. THIS WAY I PLUG THE SERIAL INTO THE USB FOR PROGRAM DOWN LOADS THEN INTO THE RADIO LINK FOR NORMAL OPERATION...

THIS WAS THE SIMPLE WAY FOR ME TO DO IT...

HOPE THIS HELPS

JIM

September 20, 2009
by IvonV
IvonV's Avatar

Yes, thanks for the response Jim.

Has anyone tried connecting multiple serial devices to the MCU (maybe even including the programming header)? That's a discussion or project or tutorial I'd like to see.

September 28, 2009
by dangraham
dangraham's Avatar

Hi Jim, I am trying to get my first project off the ground, well running anyway:)

POST

What system have you used to measure the output of your sensor and give you speed? I am using a latching type hall sensor with north/south magnets. I am thinking of using ICP1 and timing either the on or off periods.

Any help would be great, thanks.

October 09, 2009
by JKITSON
JKITSON's Avatar

FOR DANGRAHM

SORRY FOR THE DELAY.. HERE IS MY CODE FOR MAKING A "LATCH" TO ONLY GET 1 COUNT PER TOOTH ON MAGNETIC SENSOR. ALSO THE CODE FOR COMPUTING SPEED IN MILES PER HOUR. YOU WILL NEED TO INCLUDE IN THE BEGINNIG OF YOUR PROGRAM THE "REAL TIME CLOCK" LIBRARY AND ROUTINE.

if(latch) goto latch_test; //latch ckt is to allow only 1 count per tooth //from the magnetic sensor on drive line.

if(b3) count = count; //if input is high leave count same else {count++; gear_count++; //if input is low add "1" to count latch = 1;}

latch_test:

// take 100 samples and compute MPH!

if (mph_time >= 100) //RUN LOOP FOR 1 SECOND (100 CYCLES) AND COUNT THE THEETH { // FROM THIS WE COMPUTE MILES PER HOUR speed = ((gear_count * tooth_distance) / 5280) / .0002777; //.0002777 = 1/3600 (3600 SECONDS IN AN HOUR)

mph_time = 0; gear_count = 0; }

if(speed > max_speed) max_speed = speed; //UPDATE max_speed IF speed IS GREATER

if(b3) latch = 0;

travel = count * tooth_distance; //increment by distance traveled for each tooth count

HOPE THIS IS SOME HELP JIM

November 23, 2009
by JKITSON
JKITSON's Avatar

I AM BUILDING A NEW REMOTE READOUT. I NEED ONE MORE OUT PUT PIN ON THE ATMEGA 168. HOW CAN I CHANGE PIN1 FROM "RESET" TO BE A NORMAL OUTPUT PIN?

I THINK I SAW WHERE IT IS DEFINED IN ONE OF THE LIB'S THAT WE CALL IN THE BEGINNING BUT HAVE NOT BEEN ABLE TO SPOT IT AGAIN..

THANKS JIM

November 24, 2009
by pbfy0
pbfy0's Avatar

I think to use PC6 as an i/o you need some kind of programmer to program the fuses. To use PC6 as i/o, you set the RSTDISBL fuse (the fuses would end up being lfuse: 0xF7 hfuse: 0x55 efuse: 0x01).

I wrote a library (untested) to use a 7-segment display. here and here, that might work.

November 24, 2009
by JKITSON
JKITSON's Avatar

HERE IS A PARTIAL SCHEMATIC OF THE 8 DIGIT DISPLAY I NEED. YOU CAN SEE THAT I NEED TO CHANGE PIN 1 (RESET) TO AN OUTPUT PIN TO CONTROL THE LAST DIGIT.

Schematic of 8 digit display

November 26, 2009
by pbfy0
pbfy0's Avatar

for the first source this would work better (it uses a string in PGM instead of in RAM).

November 29, 2009
by JKITSON
JKITSON's Avatar

TO pbfy0

YOUR CODE LOOKS GREAT... I SEE HOW YOU CONTROL EACH SEGMENT etc.

WHAT I DON'T SEEM TO BE ABLE TO SEE IS HOW I CAN "MULTIPLEX" THIS TO CONTROL 8 SEVEN SEGMENT DISPLAYS FROM 1 MCU....

MORE INFO WOULD BE APPRECIATED

THANKS JIM

November 30, 2009
by pbfy0
pbfy0's Avatar

Sorry, I didn't think you needed so many, and you can't multiplex.

November 30, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hey Jim,

Instead of having one pin of the microcontroller for each /EL (or on your diagram LE/STROBE) line, how about adding a chip like the 74HC164, which is a serial-in, 8-bit-out shift register. You could control it with just 2 pins from the microcontroller (one data and one clock), and then you would have each one of the outputs connected to a LE/STROBE of each 7-segment decoder. You basically want to have all of the /EL lines be high except for one at any given time, so you could shift a single zero around as needed.

This might also let you use something more like pbfy0's approach without the '4511 BCD-to-7seg decoder chips.

Just a thought...

Mike

November 30, 2009
by JKITSON
JKITSON's Avatar

MIKE

THANKS FOR THE DIFFERENT VIEW. I THINK I WILL TRY THIS ROUTE..

ALSO---- MANY THANKS TO YOU FOR YOUR SUGGESTIONS ON "EXPRESSCH AND PCB" PROGRAMS. THEY ARE FANTASTIC... I GOT MY FOUR PC BOARDS LAST WEEK AND THEY WERE PERFECT..

I WILL REDRAW MY SCHEMATIC USING THE 74HC164 AND POST FOR YOUR REVIEW. THEN WILL START THE PROGRAMMING. I THINK I WILL HAVE TO RETAIN THE 4511 REGISTERS AS THEY RETAIN THE LAST VALUE AND KEEP IT DISPLAYED UNTIL THE NEXT DATA UPDATE.

YOUR KITS AND FORUM ARE THE BEST I HAVE FOUND AND USED.

THANKS AGAIN FOR THE HELP

JIM

November 30, 2009
by JKITSON
JKITSON's Avatar

TO MIKE HERE IS AN UPDATED SCHEMATIC. I THINK THIS IS WHAT YOU WERE THINKING ABOUT.

version2

JIM

November 30, 2009
by JKITSON
JKITSON's Avatar

WILL TRY TO GET A GOOD IMAGE THIS TIME----

!(http://s192.photobucket.com/albums/z235/justjudy_photos/?action=view&current=SLEDREMOTEDISPLAY-1.jpg)

JIM

December 01, 2009
by pbfy0
pbfy0's Avatar

the image format should be like this:

![alt](url)

and the alt is necessary.

so here's the image:

version 2 JKITSON: I think you were linking to a PHP page, and not just the image.

December 01, 2009
by JKITSON
JKITSON's Avatar

THANKS ALOT

I LET MY MIND READ THE [alt name] AS BEING AN ALTERNATE OPTION..

NEXT TIME I WILL TRY TO GET IT RIGHT.

THE "EXPRESSCH" PROGRAM FOR DRAWING SCHEMATICS IS VERY GOOD. TOOK A WHILE TO LEARN HOW TO USE IT.

THANKS AGAIN TO ALL OF YOU FOR SUPER HELP....

JIM

December 03, 2009
by JKITSON
JKITSON's Avatar

HI AGAIN

AS YOU CAN SEE FROM MY SCHEMATIC I HAVE THE HARDWARE PRETTY WELL ORGANIZED...

NOW TO PROGRAMMING.. I HAVE TWO VARIBLES WITH DATA, "TRAVEL" FOR DISTANCE TRAVELED WHICH IS A INITALIZED AS A DOUBLE. IT CAN HAVE A VALUE LIKE 159.48. I NEED TO BREAK "TRAVEL" DOWN TO 5 INDIVIDUAL INTEGERS EACH ONE WITH THE FIRST DIGIT, SECOND,,,,,, .

HOW DO I PARSE THE "DOUBLE VARIABLES" 1 DIGIT AT A TIME AND SAVE TO AN INTEGER?

HAVE BEEN READING MY SECOND EDITION BOOK BUT IF IT IS THERE I DONT KNOW WHAT TO LOOK FOR..

THANKS JIM

December 04, 2009
by pbfy0
pbfy0's Avatar

maybe

sprintf_P(str, PSTR("%g"), travel);
sscanf_P(str, PSTR("%1u%1u.%1u%1u"), &d1, &d2, &d3, &d4, &d5
December 04, 2009
by JKITSON
JKITSON's Avatar

PBFY0

THANKS I WILL GO TO THE BOOKS AND STUDY, THEN TRY SOME CODE....

THANKS AGAIN JIM

December 05, 2009
by JKITSON
JKITSON's Avatar

PBFY0

YOUR SUGGESTIONS SURE HELP. AFTER MANY HOURS IN THE BOOK AND TRYING CODE I CAME UP WITH THIS MUCH PGM.I AM USING ICC-WIN32 TO DEVELOP AND TEST PROGRAMS ON SCREEN BEFORE TRANSFERING TO WINAVR AND THE ATMEGA 168.

HERE IS THE CODE THAT TAKES A 5 DIGIT 2 PLACE DECIMAL NUMBER AND BREAKES IT DOWN INTO 5 INDIVIDUAL SINGLE DIGIT VARIABLES.

NEXT PART IS CONVERTING EACH SINGLE DIGIT VARIABLE TO 4 BIT BINARY....

include <stdheaders.h>

int main() { int d1, d2, d3, d4, d5; //variables to hold the individual values of the variable travel int d6, d7, d8; //variables to hold the individual values of the variable speed int i; double travel, speed; char str[6]; //define str variable to be a max of 6 characters travel = 193.56; //set the value of travel for testing, in use the max will be less than 250.99 speed = 2.98; //set the value of speed for testing, in use the max will be less than 9.99

sprintf(str, ("%g"), travel * 100); //shift digits left 2 times and convert the integer to a char
sscanf(str, "%1u%1u%1u%1u%1u", &d1, &d2, &d3, &d4, &d5); //parse the first 5 digits and store them in d1..d5

sprintf(str, ("%g"), speed * 100); //shift digits left 2 times and convert the integer to a char
sscanf(str, "%1u%1u%1u%1u%1u", &d6, &d7, &d8); //parse the first 3 digits and store them in d6..d8

printf("%2u %2u %2u %2u %2u \n", d1, d2, d3, d4, d5); //print the individual value of each
printf("%6.2f \n", travel); //print the value of travel

printf("%2u %2u %2u \n", d6, d7, d8); //print the individual value of each
printf("%4.2f \n", speed); //print the value of speed
December 06, 2009
by pbfy0
pbfy0's Avatar

here's a better formatted version, also with some edits:

#include <stdheaders.h>
#include <avr/pgmspace.h>
// make sure you include <avr/pgmspace.h>, I don't know what's in <stdheaders.h>

int main() {
uint8_t d1, d2, d3, d4, d5; //variables to hold the individual values of the variable travel
uint8_t d6, d7, d8; //variables to hold the individual values of the variable speed
int i;
double travel, speed;
char str[6]; //define str variable to be a max of 6 characters
travel = 193.56; //set the value of travel for testing, in use the max will be less than 250.99
speed = 2.98; //set the value of speed for testing, in use the max will be less than 9.99

sprintf_P(str, PSTR("%5.2g"), travel); //shift digits left 2 times and convert the integer to a char
sscanf_P(str, PSTR("%1u%1u%1u.%1u%1u"), &d1, &d2, &d3, &d4, &d5); //parse the first 5 digits and store them in d1..d5

sprintf_P(str, PSTR("%5.2g"), speed); //shift digits left 2 times and convert the integer to a char
sscanf_P(str, PSTR("%1u.%1u%1u"), &d6, &d7, &d8); //parse the first 3 digits and store them in d6..d8

printf_P(PSTR("%2u %2u %2u %2u %2u \n"), d1, d2, d3, d4, d5); //print the individual value of each
printf_P(PSTR("%6.2f \n"), travel); //print the value of travel

printf_P(PSTR("%2u %2u %2u \n"), d6, d7, d8); //print the individual value of each
printf_P(PSTR("%4.2f \n"), speed); //print the value of speed
December 06, 2009
by pbfy0
pbfy0's Avatar

should be:

#include <stdheaders.h>
#include <avr/pgmspace.h>
// make sure you include <avr/pgmspace.h>, I don't know what's in <stdheaders.h>

int main() {
uint8_t d1, d2, d3, d4, d5; //variables to hold the individual values of the variable travel
uint8_t d6, d7, d8; //variables to hold the individual values of the variable speed
int i;
double travel, speed;
char str[6]; //define str variable to be a max of 6 characters
travel = 193.56; //set the value of travel for testing, in use the max will be less than 250.99
speed = 2.98; //set the value of speed for testing, in use the max will be less than 9.99

sprintf_P(str, PSTR("%5.2g"), travel); //shift digits left 2 times and convert the integer to a char
sscanf_P(str, PSTR("%1u%1u%1u.%1u%1u"), &d1, &d2, &d3, &d4, &d5); //parse the first 5 digits and store them in d1..d5

sprintf_P(str, PSTR("%5.2g"), speed); //shift digits left 2 times and convert the integer to a char
sscanf_P(str, PSTR("%1u.%1u%1u"), &d6, &d7, &d8); //parse the first 3 digits and store them in d6..d8

printf_P(PSTR("%1u %1u %1u %1u %1u \n"), d1, d2, d3, d4, d5); //print the individual value of each
printf_P(PSTR("%6.2f \n"), travel); //print the value of travel

printf_P(PSTR("%1u %1u %1u \n"), d6, d7, d8); //print the individual value of each
printf_P(PSTR("%4.2f \n"), speed); //print the value of speed

if you want actual digits. %2u will do 2 digits, so since the numbers only will only be one digit, you should use %1u

December 31, 2009
by JKITSON
JKITSON's Avatar

Here is the code i finally came up with.... turned out to be very simple to pad the leading blank spaces in a variable with zero's...

Now to programming the conversion of binary 4 bit word to individual variables and set the outputs to 1 or 0....

define F_CPU 14745600

include <stdio.h>

include <math.h>

include <stdlib.h>

include <avr/io.h>

include <avr/interrupt.h>

include <avr/pgmspace.h>

include <inttypes.h>

include "../libnerdkits/delay.h"

include "../libnerdkits/lcd.h"

include "../libnerdkits/uart.h"

int main() {

// start up the LCD lcd_init(); FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home();

int d1, d2, d3, d4, d5;     //variables to hold the individual values ofthe 
                                      variable  travel
int d6, d7, d8;             //variables to hold the individual values of the
                                      variable  speed
//int x1, x2, x3, x4;       //variables for the binary data lines to display

char *a[10];                //ARRAY FOR STORING BINARY CODED DEC.
                                              DIGITS
        a[0]="0000";
        a[1]="0001";
        a[2]="0010";
        a[3]="0011";
        a[4]="0100";        //ARRAY NOT USED AT THIS TIME
        a[5]="0101";
        a[6]="0110";
        a[7]="0111";
        a[8]="1000";
        a[9]="1001";

double travel, speed;
//char bin[4];      //bin variable to be a max of 4 characters 
char str[7];        //str variable to be a max of 7 characters
char spd[5];        //spd variable to be a max of 5 characters          
travel = .13;       //set the value of travel for testing, in use the max
                              will be less than 250.99
speed = .08;        //set the value of speed for testing, in use the max
                              will be less than 9.99

while (1) {
//WHEN YOU USE THE "0" IN THE sprintf_P FUNCTION IT PADS THE LEADING BLANKS WITH 0...

sprintf_P(str, PSTR("%05g"), travel*100);  //shift digits left 2 times and pad
                                                 the leading digits w/0 to make
                                                 a 5 digit string 
sscanf_P(str, PSTR("%1u%1u%1u%1u%1u"), &d1, &d2, &d3, &d4, &d5); //parse the
                                                    5 digits and store them in d1..d5

sprintf_P(spd, PSTR("%03g"), speed * 100); //shift digits left 2 times and pad
                                                 the leading digits w/0 to make
                                                 a 3 digit string
sscanf_P(spd, PSTR("%1u%1u%1u"), &d6, &d7, &d8); //parse the first 3 digits and
                                                       store them in d6..d8

  lcd_home();
  fprintf_P(&lcd_stream, PSTR("TRAVEL: %3.2lf"), travel);

  lcd_line_two();     
  fprintf_P(&lcd_stream, PSTR("PARSED: %1u %1u %1u %1u %1u"), d1, d2, d3, d4, d5);

  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("SPEED:%1.2lf"), speed);

  lcd_line_four();
  fprintf_P(&lcd_stream, PSTR("PARSED: %1u %1u %1u"), d6, d7, d8);

} return (0); }

December 21, 2011
by JKITSON
JKITSON's Avatar

The time has come to improve my design. I think i need to implement interrupts on my signal input. I have changed 3 times on sensors and now am using a infrared sensor on the sprocket. I am having a hard time getting my mind around interrupts. I think I need to trigger on slope change, either way is ok. I only need a pulse to indicate change

Any comments would be appreciated.

Thanks NERDKITS for your system and the time invested in all of us...

Jim Kitson

January 16, 2012
by JKITSON
JKITSON's Avatar

Hi.. I got the (PCI) interrupt to finally work. Well kind of!! I see where there are two interrupts that you can trigger on hi, low, rise, or fall. These ports are used by the lcd display. Is there any way a pin_change_interrupt be made to trigger on rise or fall of signal?

Thanks Jim

January 31, 2012
by JKITSON
JKITSON's Avatar

I need to have pin's 4 & 5 on mcu for interrupts. They are now used by the LCD screen. What do I have to change to move the screen wires to some other pins on the mcu? I have looked at the lcd.c but not sure where to change. Any help appreciated. Thanks Jim.

January 31, 2012
by mongo
mongo's Avatar

Hey Jim,

It has been a while since I had time to mess with mine but I never did get the 433 MHz txrx to talk. I just re-read the thread and I caught something I missed a while back... That little board between the NK and the transceiver is an RS232 converter, isn't it? That may be what has been throwing me all this time.

January 31, 2012
by JKITSON
JKITSON's Avatar

MONGO That board is a 3.3volt power supply. The first radios I purchased were 3.3v only. I now have a pair that are 5v. Use a cross over connection. tx to rx. Mine works to about 1000 feet. Have one problem of data shifting 1 character on rec. I shifted my software in the rx unit and all works...Jim

February 01, 2012
by Rick_S
Rick_S's Avatar

You could go I2C with the LCD that only uses two lines of your micro-controller (SDA & SCL). Here is a link to that thread. The library I created is a few posts in. This is a great way to cut down the number of connections required by the LCD.

Rick

February 01, 2012
by JKITSON
JKITSON's Avatar

Rick

I don't think there is enough program space left to add SPI along with my existing SLED program. SPI would be a good idea otherwise. Thanks for the info. I read the posts and will have to read them many more times to get a better grasp of SPI.

Thanks Jim

February 01, 2012
by Ralphxyz
Ralphxyz's Avatar

That's I2C Rick is referring to not SPI. His I2C library works great even for someone with limited capacities like myself.

If you are running out of program space there are a couple of Master/Slave multi processor threads here published in the past year.

One also uses I2C.

And another uses SPI

Both of these were contributed by Noter (who we miss).

Using one of these methods you can have a intelligent port expander. I think you can use 20 pins on a slave for I/O and also do parallel processing.

Ralph

February 01, 2012
by JKITSON
JKITSON's Avatar

Ralph

I got a little off track on my last post. Thanks for correcting me.

What I really need is int0 and int1 ports (pins 4 & 5) so I can trigger an interrupt on the rise of a trigger (tooth on sprocket). Using regular pin change interrupts I get two interrupts for each tooth. This slows my program operation two much. I am using pcint13 (pin 28) at this time and program works but two slow.

Thanks Jim

February 01, 2012
by mongo
mongo's Avatar

Jim, The units I have are CyR2196R

Is that the same? I have been able to get data to them but nothing comes out the receiving end.

Do they take TTL or RS232 signal? I have been trying TTL in both polarities to no avail.

The paperwork that came with them says 5V.

February 01, 2012
by JKITSON
JKITSON's Avatar

Mongo, THE SERIAL OUT PUT FROM THE 168 CHIP (PINS 2&3) GO DIRECT THE THE RS-232 INPUT & OUTPUT ON THE RADIOS. MINE WORK AT 19200 BAUD SO YOU HAVE TO SET YOUR PROGRAM TO USE 19200 TO COMMUNICATE. I cut & pasted this from a previous post. Mine were RS-232. Had to use cross over wiring ie tx to rx. Make sure you change the baud rate in your program to match the radio's baud rate. The line of code for mine was UBRR0L = 47; Jim

February 02, 2012
by mongo
mongo's Avatar

So far, I have only been generating data through the USB port and into the transmitter. I set the USB port to 19200 and can watch the signals go into the transmitter but there does not appear to be anything at the receiver end. Translating the TTL signal from the USB adapter, (USB/TTL) is done with a transistor so that a high on the TTL line is inverted to a low at the transmitter. and VS/VSA. I can see the signals on the scope at one end but nothing at the other. Maybe I should be using RS232 levels instead of TTL levels?

February 02, 2012
by JKITSON
JKITSON's Avatar

I use the RS232 xmt/rec from pins 2&3 on the 168 to the radio. I use a second radio and a second 168 to rec the data & display on screen.

HUMBERTO: I have been looking at the lcd.c & am having problems figuring out where to make the changes to free pins 4 & 5, then change to some other pins. Any ideas.....

Thanks Jim

Post a Reply

Please log in to post a reply.

Did you know that inductors try to keep their current constant over short periods of time? Learn more...