PDA

View Full Version : First timer...building a remote controlled vehicle



.n0rig.
- 15th January 2009, 21:48
I have a science Olympiad tournament coming this month and for my project I am going to build a remote controlled vehicle. I can probably do the motor and turning part. But I need someone to help me with the transferring of data to the the pic chip in the controller (12F or 16F prob.) to the one the car (12F or 16F).

maybe using the technique found under the "five-button V2 transmitter and receiver (old)" heading at http://jap.hu/electronic/codec-v4.0.html

Please, please help me on this. Thank you by the way :D

okay, I will be using either a 12F683 pic chip or a 16F684. I have two zilog transreceivers and IR detectors and stuff. Here are the links for some of the things I bought:

transceiver - https://www.mouser.com/Search/ProductDetail.aspx?R=ZHX1810MV115TH2090TRvirtualke y69200000virtualkey692-ZHX1810MV115TH29

Infrared Emitter/Sensor Assemblies SMD Slotted Optical Switch
https://www.mouser.com/Search/ProductDetail.aspx?R=QVE00033virtualkey51210000vir tualkey512-QVE00033

I will try to buy whatever you guys suggest as long as you have tried it before and you know that it works. Please help out.


The major thing I would need help with would be button debouncing as it does not seem to work with if then statements for me and how to send data to the another pic (either the 12F or 16F above) using the transceiver. Maybe code examples, links, and anything that can help me out would be great.

thank you all!

deadline? Jan 27th !!!! :(

elec_mech
- 15th January 2009, 23:29
.n0rig.,

I can't speak too much to the IR transmitter you're looking at, but I can point you in the direction of some other options. If time and ease outweigh cost, one option is to use a pre-built transmitter/receiver pair that uses standard serial data, like:

http://www.parallax.com/Store/Accessories/Communication/tabid/161/CategoryID/36/List/0/Level/a/ProductID/111/Default.aspx?SortField=ProductName%2cProductName

You need both the transmitter and receiver. The link above takes you to a deal where you save a little money by buying two of each, but also on that page, below the picture, is a link to the transmitter and receiver by themselves. Unfortunately, I haven't used these personally (yet) but they use a simple serial interface like serout. The code provided isn't in PBP, but it is a form of BASIC, so it will help get you started. If memory serves, I think you'd use serout2 on the transmitter side and serin2 on the receiver side. That's it! No figuring out how to encode or decode IR signals. Plus, you'll get much better range (~500') and not nearly as much interference and noise as you would with IR.

If you're hooked on IR and want to keep it cheap, I'd search the forum for using a standard TV remote control with a simple IR detector. I did that many moons ago, so it ain't too hard to figure out. In that way you don't have to spend additional time building a transmitter and writing code for it.

Now, if you're ambitious, another option is to interface with a wireless Playstation 2 controller. Again, you don't have to build a controller or write software for the remote, because it's already done. Additionally, the PS2 has analog joysticks, so you could have your car's speed and steering controlled proportionately, assuming you have the supporting motor controls. In other words, instead of pushing one button to move the car forward at one set speed, you could push up on the joystick and as the stick was moved forward, the car would increase it's speed. It's a digital output, so you don't have to go so far as to use the ADC on the PIC. Check out this post for a little more info: http://www.picbasic.co.uk/forum/showthread.php?t=10386

This will likely take the most time to program and debug however and as you're on a tight schedule, I leave it for you to decide which, if any of these, suit your needs best. I hope this helps.

-Tony

.n0rig.
- 16th January 2009, 01:56
thanks tony, I figured the whole serin and serout deal but I was just wondering if I can do that on any of the pic's pins? I will look at the datasheets of the pics I am doing but can you give me a label I should for if any. I am going to assume that any pin will work, trial and error will fix this for me.

Also, I know this is going to sound really dumb, but it is something I have been trying to fix for such a long time. I have been trying to use button debouncing with if then statements but they don't seem to work.

Let us say this is the beginning of my code:


gosub rightbuttoncheck ;high then check right side. If right not, then restart.

goto start

rightstart:
gosub nap54ms
if GPIO.3 = 0 then start

gosub checkRmode

rightstart2:
nap 6 ; low power mode for 1.152 of a sec.
if rightbutton = 0 then start



I don't know how to do a "if tact switch (momentary) is pressed, then goto [labe]" type of deal. I tried using the "button" command but that just gave me too many errors that I just dropped it. I was thinking of putting assembly in the and using btsfc or whatever :D I know some assembly...just to get me around and understand what a program is doing.

So, if I had a a chip, a wire connect to that chip's pin, that wire to a pin of a momentary tact switch, then the other end to the ground or ground pin of the pic chip. How would I do that in basic, will the above If then statements work...well...they have not worked with me even when I change it to "if rightbutton = 1 (or a 0) then [label]".

Regards and thanks for everything!

P.S. are there any cheaper alternatives to this...is there no example code I can follow?

Archangel
- 16th January 2009, 02:12
thanks tony, I figured the whole serin and serout deal but I was just wondering if I can do that on any of the pic's pins?SERIN, SEROUT, SERIN2, SEROUT2, . . . YES, HSERIN HSEROUT, NO on these you must use the hardware ports

Also, I know this is going to sound really dumb, but it is something I have been trying to fix for such a long time. I have been trying to use button debouncing with if then statements but they don't seem to work.

Let us say this is the beginning of my code:


gosub rightbuttoncheck ;high then check right side. If right not, then restart.

goto start

rightstart:
gosub nap54ms
if GPIO.3 = 0 then start

gosub checkRmode

rightstart2:
nap 6 ; low power mode for 1.152 of a sec.
if rightbutton = 0 then start



I don't know how to do a "if tact switch (momentary) is pressed, then goto [labe]" type of deal. I tried using the "button" command but that just gave me too many errors that I just dropped it. I was thinking of putting assembly in the and using btsfc or whatever :D I know some assembly...just to get me around and understand what a program is doing.

So, if I had a a chip, a wire connect to that chip's pin, that wire to a pin of a momentary tact switch, then the other end to the ground or ground pin of the pic chip. How would I do that in basic, will the above If then statements work...well...they have not worked with me even when I change it to "if rightbutton = 1 (or a 0) then [label]".

Regards and thanks for everything!

P.S. are there any cheaper alternatives to this...is there no example code I can follow?
Just use 2 if then loops with a short delay between them.


LOOP:
If portA.1 = 1 then
pause 5
if PortA.1 = 1 then
{ your code here}
ELSE
goto LOOP
ENDIF
ENDIF

GOTO LOOP

mackrackit
- 16th January 2009, 03:03
SERIN, SEROUT, SERIN2, SEROUT2, . . . YES, HSERIN HSEROUT, NO on these you must use the hardware ports
Some thing about that sounds...funny :)

.n0rig.
- 16th January 2009, 03:18
ok, I got the IF THEN statement to compile in one of my other codes. As for this remote controller car, how would I got about controlling two DC or three DC rumble motors from an xbox 360 controller? I really wanted one that you can control the speed on but dang...those cost a lot and for something like this, I don't want to blow my money on little 2 in x 2 in things that cost over $100. :D

Anyways, I'm guessing PWM is not an option on these? How about pulsout? I just want to make these things make the car go forward, reverse, stop (if possible), and have a 3rd small one controll the steering of the front tires. The motors would have separate power sources from the pic chip. I believe the guidelines said to not use over 5 or so volts in total...I can bring extra batteries and I only need the car to operate for a few minutes. I am guessing a tripple A for the front motor and 2-3 double A's for the pic and two back motors. Maybe add some other components to make the whole thing work. But this is the idea for now. Oh, I have a few 16F684 chips and 16F636, 16F616 and an 18F that I never used. I usually buy 100's of 12F683 though :P.

I like the 12F683 and the 16F684 because they both have the same modules and stuff. The datasheets are practically similar...except the 16F has 14 pins. So, this is the pic I want to use.

sooo, what are my options?

.n0rig.
- 16th January 2009, 03:30
sorry double posted

.n0rig.
- 16th January 2009, 03:56
triple...please erase these last two.

elec_mech
- 16th January 2009, 16:00
.n0rig.,

I'll try to get more detail to you this evening if you need it, but here's some info to get you started.

The button command will work on any I/O so long as the pin you select is set to a digital output. As I'm a little more familar with 16 and 18 series, let's stick with the 16F684. Now, most of the pins on this chip can be used as analog or comparator inputs, so you need to turn these off. Something like this (sorry, this is quick and dirty):



CMCON0 = %00000111 ' Turn off comparator bits and set pins to digital I/O
ADCON0.0 = 0 ' Disable ADC
TRISC = %00001111 ' Make port c pins 0-3 inputs and the rest as outputs
b0 VAR byte ' Byte variable for button
HIGH PORTC.4

Start:

BUTTON PORTC.0, 0, 255, 0, b0, 1, drive_forward ' If button is pressed, goto drive_forward routine

GOTO Start

drive_forward:
LOW PORTC.4
PAUSE 500
HIGH PORTC.4
PAUSE PORTC.4
goto Start


Now, as far as hookup, you should connect a 10k resistor to 5V (whatever is powering VDD) and to pin RC0. Connect one side of the momentary switch to RC0 and the other to ground. Connect the positive side of an LED to 5V and the other to, say, a 1k resistor and the other side of the resistor to RC4. Assuming I made no mistakes, you should see the LED blink once when you press the switch.

To control motors, it depends on what you want to do. If you're NOT trying to vary the speed and just want to turn the motor on and off (one speed), I'd look at an H-bridge IC or make one with transistors or MOSFETs. Another option is to use a DPDT and a simple SPST relay, which you'd have to interface to the PIC with transistors or an optoisolator. The DPDT will change the direction will the SPST will turn the motor on and off. If you do want to vary the speed keep in mind your controller must be able to vary the signal to the PIC as well. If you want to go this route, I'd search the forum on PWM and/or motors. The rumble packs are just simple brushed DC motors as far as I know, so if one speed is okay, you just feed them power and they go - they don't need PWM to function. You would use PWM to vary the speed, but my knowledge on this subject is limited at best.

As far as steering, I'd use a cheap servo and the PULSOUT command. Optionally, you could use continuous servos for the wheels too and get varying speed easy with the PULSOUT command, but it won't go very fast.

.n0rig.
- 16th January 2009, 17:06
Yea sounds like a good idea, I figured out how to do if then commands and I think I just figured out why my buttons were not working. I didn't signify a b0 register as a byte. Anyways, what I will need most help in will be the serout and serin to connect to the chip on the car to make the car move forward, back, etc.

And can I use rumble motors from an xbox 360 controller for my main forward and reverse motions? can these be controlled like a servo or not? see, there is a requirement that we have to make the vehicle stop when at a certain time. The faster it stops the better.

thanks for all your help guys!

elec_mech
- 16th January 2009, 18:26
.n0rig.,



Anyways, what I will need most help in will be the serout and serin to connect to the chip on the car to make the car move forward, back, etc.


By chip, do you mean the PIC or are you interfacing the PIC to some chip on the car? You only need serin and serout if you're interfacing to a computer or another IC. Or do you mean to talk from one PIC (on the remote) to the PIC on the car?

I doubt you can control the motors like a servo. Rumble packs are typically DC brushed motors with a counterweight on the end that act like pager motors or the vibration ringer in a cellphone. They'll be full on or off like a standard DC motor. You'd have to use PWM with some type of interface circuitry or buy a motor controller that can interface with the PIC.

If you'd like to dive further into motor control, a quick Google search turned this up:

http://www.newark.com/pdfs/techarticles/microchip/PICmicroMotorControlTipsnTricksBrochure.pdf

http://ww1.microchip.com/downloads/en/AppNotes/00893a.pdf

http://ww1.microchip.com/downloads/en/AppNotes/00905a.pdf

http://www.seattlerobotics.org/encoder/200001/simplemotor.htm

I haven't looked at this in detail, but you might get away building this and using pulsout:

http://www.aaroncake.net/CIRCUITS/motorcon.asp

However, I think this would do everything you want and pretty cheaply:

http://www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/CategoryID/35/List/0/Level/a/ProductID/491/Default.aspx?SortField=ProductName%2cProductName

.n0rig.
- 17th January 2009, 04:34
elec_mech, you are really helpful and thank you for finding those links for me.In regards to some of your questions, yes, I will be using serout to "wireless" interface like this:

me -> push buttons on remote -> remote has 16F684 in it -> which is connected to an RF transceiver (or transmitter "tx") -> sends the info about me pushing the button(s) -> transceiver (or receiver "rx") in car receives info -> transceiver forwards received info. to another 16F684 chip in the car that is connected to either 3 or 4 rumble motors (dc) without the weights on the spindles -> this controls forward and reverse motions. With some gears and just 3 motors (two on back and one of front between two front tires with spindle facing upward) I can make a steering system.

That right there sums up my plan for this. I don't need anything fancy for controlling the car, nothing that exceeds 30M probably (RF quality).

I am still lost on what actual supplies I can use that are not too expensive. If you have done something like this before I would greatly appreciate either a sample code, parts list, or guides for me. I really appreciate all of your help...this is going to be a really important event for me if I finish this as it will be one of the biggest completed codes I could possibly make. With the knowledge that I attain from this, I can put it to use in the future. Anyways, thanks...just keep all this information rolling guys.

Regards,

n0rig

elec_mech
- 17th January 2009, 17:57
.n0rig.,

Ahh, okay. It's been years since I worked on an IR project, so I did a quick search on the forum under 'infrared' and found some postings you might want to check out:

http://www.picbasic.co.uk/forum/showthread.php?t=10343&highlight=infrared

http://www.picbasic.co.uk/forum/showthread.php?t=8470&highlight=infrared

Now, by all accounts, everyone said Bruce was the man on IR and to check out the solutions on his website. These are both inexpensive and relatively easy to implement.

http://www.rentron.com/Infrared_Communication.htm

http://www.rentron.com/remote.htm

http://rentron.com/PicBasic/IR_Chips.htm

If you'd consider using a universal TV remote programmed with Sony signals, as a backup plan - I'm not encouraging you to abandon your plans for making your own remote - then: http://www.rentron.com/remote_control/IR-D15A.htm

Hope this helps and good luck!

.n0rig.
- 18th January 2009, 03:33
okay, after spending about an hour reading through rentron's articles...I have come to the conclusion that I will need to generate the signal, run that through my IR transceiver and then collect it again at the transceiver in the car. I have three transceiver here that have an in and out for RF communication. I am sure I will not need to encode the data stream, right?

Well, I have two of these:
http://www.mouser.com/search/ProductDetail.aspx?qs=X1mjqRbeMc7EXmCYV8QSMg%3D%3D

100+ 12F683 I/P
~6 16F683 I/P
~3 16F616
1 18F2550
~500 tact switches
~3000 ft kynar wire (30 awg)
no oscilloscope
1 voltimeter
and soldering iron and glue
other basics

Soo...I am not sure if this is what all I may need to make an IR link between two chips. I just need your guidance guys in all of this. I will post pictures of it if I finish it :D

.n0rig.
- 18th January 2009, 03:44
Found this at rentron and going to see if I can make my own encoder and decoder. Ok...I know I will need this to minimize "noise" that may be from cells and stuff like that at the competition. sooo, what exactly will me connecting my 16F to the encoder pic to the transceiver which will transmit to the tranceiver at the car, decoded by the decoder pic, and forwarded to the 16F in the car do to my remote controlling abilities. Is this required and what are the benefits. And...is my concept above wrong? Does the data go through the transceivers and get picked up by the other transceiver?

This is seriously the first ever pic basic code that I have done for wireless or "serin/serout" communication. I have some good knowledge of a pic but it is just novice to intermediate knowledge. But anyways, the link is here:

http://www.rentron.com/PicBasic/IR_Chips.htm

Also, I will be trying to test some serout/serin commands with my 16F684 tonight to see if I can get a pin on the receiving pic to go high and turn on an LED. If I can do this...maybe using the pulse command can control the DC motors? Then I can incorporate this to the IR transceivers.

Any tips and help is appreciated by all viewing...

.n0rig.
- 18th January 2009, 04:03
Also, for my two 16F pics (not decoder/encoder, Tx/rx) I was wondering if I could make subroutines in the code that simplify the wireless communication part. Maybe have it do something like this (in English not in basic :D) .

-------16F in remote controller-----
if porta.0 button is pressed (signifies forward) then goto send_forward
send_forward:
serout the letter "f"

------16F in car------
serin "letter (can be F, B, L, R, and combinations of letters)

if letter = F then goto foward
foward:
PWM on two back motors using hardware PWM
...or jsut make both pins connected to the + of the motors high?

-------------------------------------


Would something like that work? Also....I have some guides here (and the internet) on how to use the serin/out commands....I just need to learn the basics of what I can and cannot do. I cannot test anything right...I really don't want to mess anything up. For now...I want to collect as much info as i can and prepare myself with the knowledge that others have done this before me...that I should be able to as well.

Regards,

n0rig

elec_mech
- 19th January 2009, 02:51
.n0rig.,

As much as I love to help, I'm a bit short on time this week. It looks like you're heading in the right direction. My only advice to you at this point is to put something together and try it. The worse case is it won't work - you're not going to blow anything up. Just make darn sure there are no shorts between the positive and negative power leads and that you don't switch the two going into your ICs before you apply power - those have been my biggest problems (thumping head against wall). Once you've put something together and tried out some code, let us know what you've done, where you're stuck and we'll do our best to help. Good luck!

.n0rig.
- 23rd January 2009, 00:42
:( I can't get the chips to communicate...

mackrackit
- 23rd January 2009, 02:11
Try it without the transmitter, use a wired connection for trouble shooting.

Post the non-working code!

paulbergsman
- 24th January 2009, 00:31
I just found out about this website. So, this information may be too late to use.

On the other hand, your original post was on Jan 15, 2009.

Microchip has an application note, AN657, that shows you how to decode TV remote control signals. The application note includes source code.

You make a table of the decoded codes for the buttons you want to use.

Then write simple subroutines for each task you need to do.

.n0rig.
- 27th January 2009, 05:21
Can you please post the link :) ????

mister_e
- 27th January 2009, 15:53
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011039

.n0rig.
- 3rd February 2009, 07:27
Okay, deadlines are this saturday. I got the chips communicating with a wired connection. On a 16F684 I used the pin portc.1 to communicate. I got it to send a variable (but now I just changed it to two word sized variables (movement1 for forward and reverse motors, and movement2 for turns). When I did one veriable, it worked perfectly by using this:


TRAIN VAR BYTE
movement1 var word
movement2 var word

PORTc.1 = 1 'turn enable pin high
TRAIN=$55

SEROUT PORTc.1,T2400,[TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,9,movement1,movement 2]

goto get_actions
goto start

and this to receive:
*movement1 and 2 have been declared in the beginning of code

TRAIN VAR BYTE

Start:

PORTc.1 = 1 'turn communication pin high
TRAIN=$55
SERIN PORTC.1,T2400,[9],movement1,movement2
gosub get_actions

goto start

forward:
forwardleft:
forwardright:
backward:
backwardleft:
backwardright:
turnleft:
turnright:
nomov:

the last labels are where my actions to route power to the motors will go...that will be the simpler part I suppose.

Also, I want to add buttons to my remote control. It will simple momentary tact buttons but I still do not understand what will need to be hooked up to make this stuff work. Basically, I will need around 6 buttons or so...maybe all in the porta pins. That will be the basic way to do it...given each direction a button (e.g. L, R, FL, FR, Rl, RR). But now I am thinking of using the two movement word variables (movement1 & movement2) to do two things at once. So, when I press R and the forward button (almost like a dpad), it will send out those two variables to the chip in the car. But Idk how to make those two variables run at the same time :(. Like...if I am doing left and forward, then I want left and forward to be enabled at the same time.
*actually...wouldn't tris and port commands do this quicky?
:D

It's late and I am tired...

anyways, here is what I have for the buttons as described above...will this section of code work work with momemtary tact switches like I said? Or do I have to use the button command? If I am missing or doing something wrong in any part of this...please, please help me out. Also, if you have any tuts or previous codes your wrote and don't mind PMing me...then please do.


get_actions:
if leftbutton = 0 then
turns = 1 ;turns = 1 means a left turn
else
turns = 0 ;no turn at all
endif

if rightbutton = 0 then
turns = 2 ;turn = 2 means a right turn
else
turns = 0 ;no turn at all
endif

if backwards = 0 then
forwardsandback = 1
else
forwardsandback = 0
endif

if forward = 0 then
forwardsandback = 2
else
forwardsandback = 0
endif

goto start ;now we have all the buttons pressed at this small
;interval of time...we need to send it.
*the serout command is located after start

I have been working on this for a long time and have spent so much money that I decided to buy those rentron transmitter and receiver pair. I did next day shipping on it too as I need them fast.

If I were to use tho...will I have to encode anything or can I just connect the transmitter to the remote control pin and the receiver to the car?

Oh, I bought these:
1 - RXLC-315-LR High-Performance RF Receiver Module
http://www.rentron.com/remote_control/RXLC-434LR.htm
1 - TXLC-315-LR High-Performance RF Transmitter Module
http://www.rentron.com/remote_control/TXLC-XXX-LR.htm


I got the full code compiling but just a few things I am not sure about stilll...I have the chassis and also ordered some motors from...well...for now I forgot the place. But it was like 10 DC motors and stuff...


ONE MAJOR QUESTION!!!!
How do I make my car stop? I mean, using a DC motor...if u take the currect away from it, the car will still keep on rolling...how can I make it so that it locks up and stops? Is it possible by reading the adc or something and making it go postive, then negative then positive (pulse???) make it stop?

Please give me something to work on that above guys.

Regards,

n0rig

P.S. Pin diagram attached is not final...just something that I keep on erasing and stuff...then changing it again.

P.S.S. Help me because this is my first time using PicBasic :D

.n0rig.
- 3rd February 2009, 07:33
some funny thing that happened...I ordered some wireless transceiver RF chips from mouser.com (great place :D) but they were so tiny and I don't have the equipment to solder to them that they are just now sitting there. Also, can these work (I got like 10 of them while I ordered my regular stuff from them...)?

http://www.mouser.com/Search/ProductDetail.aspx?R=MCP201-E/Pvirtualkey57940000virtualkey579-MCP201-E/P

Archangel
- 3rd February 2009, 08:57
ONE MAJOR QUESTION!!!!
How do I make my car stop? I mean, using a DC motor...if u take the currect away from it, the car will still keep on rolling...how can I make it so that it locks up and stops? Is it possible by reading the adc or something and making it go postive, then negative then positive (pulse???) make it stop?

Please give me something to work on that above guys.


To make a PM motor brake, short the power leads together, so the current the motor is generating works to stop the rotation. Obviously you would disconnect power first :D

Bruce
- 3rd February 2009, 15:16
.nOrig.,

Unfortunately, the MCP201 ICs you ordered from Mouser aren't RF tranceivers. These are
bidirectional serial interface ICs. See section 1.0 device overview in the MCP201 data
sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21730d.pdf

P.S.
Thanks for the order. I'll have a free copy of our RF code examples CD included/shipped
with your order today.

.n0rig.
- 4th February 2009, 21:04
Wow bruce Thanks. I did receive it today and I am planning on working on it later tonight (the cd was in there and those files look very helpful). I am going to attach what I have as of now for both my receiving and transmitting chip (both 16F684). I would like you guys to correct me on some stuff because I had it working the day prior to yesterday (but it was just the serin and serout without the "get_direction" label and the forward, backwards, left, right labels as well), but now it has stopped working.

Here is the code for the 16F684 that will be connected to the transmitter:
*also, how can I make a circuit with about 4 buttons using my 7mm tact switches so that I can get the values and send them out over serout?
**what is needed...I am still unclear on this, is it a 10k resistor or something. A simple diagram would be helpful (maybe with an accompanying piece of code :D)
***keep in mind that this is my first project ever in PBP, I have pieced stuff together from other's posts and stuff I have read. I have managed to get the somewhat good amount of knowledge that I possess of assembly programming (and all the stuff that you may learn from it) to better understand my code.

Transmitter chip code (beta - malfunctioning?):
*I was playing with the data being sent out and making it my own numbers so it is just a loop between start and the serout command...so I can test the receiver pic...which isn't working for some reason :(



'************************************************* ***************
'* Name : Electric car (4 motors and remote controlled) for Science Olympiad*
'* Author : GiroTechs *
'* Notice : Copyright (c) 2009 GiroTechs *
'* : All Rights Reserved *
'* Date : 1/14/2009 *
'* Version : 1.0 *
'* Notes : this is a single attempt to make a remote controller electric *
'* : vehicle with both reverse and forward plus steering *
'* : capabilities as well as a stop button. *
'* major code piece that baffled me came from:
'*http://www.picbasic.co.uk/forum/showthread.php?p=50584#post50584
'* THANK YOU n qwerty!
'************************************************* ***************
'
' power ^ ground
' RA5 RA0
' RA4 RA1
' RA3 RA2
' RC5 RC0
' RC4 RC1
' RC3 RC2
'
Include "modedefs.bas"
'
' ——-[ Equates ]———————————————————————————-
'
FLbutton var porta.0 ;left side forward
FRbutton var porta.5 'right side forwad
BLbutton var porta.1 ;left side backwards
BRbutton var porta.4 ;right side backwards
rightbutton var portc.5 ;just turn right
leftbutton var porta.2 ;just turn left

act1 var word
act2 var word


;Create a changing pulsewidth signal from 10 usec wide to 655
;msec wide.
pulsewidth var word

;end equates

;Main start
start:
TRISA=%00000000
TRISC=%00000010

OPTION_REG.7=0 'Enable Pull-Up's on PORTB

ANSEL = 0 'turns off analogue inputs

OSCCON =$60 'sets internal osc to 4MHz

TRAIN VAR BYTE
movement1 VAR WORD
movement2 var word

direction var word
turns var word

PORTc.1 = 1 'turn enable pin high
TRAIN=$55
movement1 = 4
movement2 = 1
direction = movement1
turns = movement2
SEROUT PORTc.1,T2400,[TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,9,movement1,movement 2]


goto start


END



;
;subroutines
;

get_actions:
if leftbutton = 0 then
turns = 1 ;turns = 1 means a left turn
else
turns = 0 ;no turn at all
endif

if rightbutton = 0 then
turns = 2 ;turn = 2 means a right turn
else
turns = 0 ;no turn at all
endif

if FLbutton = 0 then
direction = 1
else
direction = 0
endif

if Frbutton = 0 then
direction = 2
else
direction = 0
endif

goto start ;now we have all the buttons pressed at this small
;interval of time...we need to send it.

;***RAN out of space on this post, you will need to get this part of code ;from the next one below.
;



My Receiving pic's code:
*in the previous code, I set it up to send fixed data so I can see if the pins are being enabled or not. As it turns out, my code isnt working for some reason. 2 days ago I had it working but idk what could be wrong because I know that "movement1" and "movement2" are being received (wired connection). Any help by looking over my if then statements and all that would be apreciated :D



'************************************************* ***************
'* Name : Electric car (4 motors and remote controlled) for Science Olympiad*
'* Author : GiroTechs *
'* Notice : Copyright (c) 2009 GiroTechs *
'* : All Rights Reserved *
'* Date : 1/14/2009 *
'* Version : 1.0 *
'* Notes : this is a single attempt to make a remote controller electric *
'* : vehicle with both reverse and forward plus steering *
'* : capabilities as well as a stop button. *
'* major code piece that baffled me came from:
'*http://www.picbasic.co.uk/forum/showthread.php?p=50584#post50584
'* THANK YOU n qwerty!
'************************************************* ***************
'
' power ^ ground
' RA5 RA0
' RA4 RA1
' RA3 RA2
' RC5 RC0
' RC4 RC1
' RC3 RC2
'
Include "modedefs.bas"
'
' ——-[ Equates ]———————————————————————————-
'
forwardL var porta.0 ;left side forward
forwardR var porta.5 'right side forwad
backwardL var porta.1 ;left side backwards
backwardR var porta.4 ;right side backwards
right var portc.5 ;just turn right
left var porta.2 ;just turn left
rec var portc.1 ;receiver pin

action var byte
B1 var byte
movement1 VAR WORD
movement2 var word

direction var word
turns var word

;Create a changing pulsewidth signal from 10 usec wide to 655
;msec wide.
pulsewidth var word

;end equates

;Main start

TRISA=%00000000
TRISC=%00000010

OPTION_REG.7=0 'Enable Pull-Up's on PORTB

ANSEL = 0 'turns off analogue inputs

OSCCON =$60 'sets internal osc to 4MHz

TRAIN VAR BYTE

Start:

PORTc.1 = 1 'turn communication pin high
TRAIN=$55
SERIN PORTC.1,T2400,[9],movement1,movement2
movement1 = direction
movement2 = turns
goto checkdirection

goto start

forward:
if turns = 0 then
goto forwardgo
if turns = 1 THEN
goto forwardleft
if turns = 2 then
goto forwardright
endif
endif
endif
forwardgo:
high forwardl
high forwardr
pause 500
low forwardl
low forwardr

goto start

forwardleft:
forwardright:

backward:
if turns = 1 then
goto backwardleft
if turns = 2 then
goto backwardright
endif
endif

high backwardl
high backwardr
pause 500
low backwardl
low backwardr

goto start

backwardleft:
backwardright:
turnleft:

high left
low right
pause 500
low right
low left
goto start

if turns = 0 then
goto start
if turns = 1 THEN
goto checkturns
if turns = 2 then
goto turnright
endif
endif
endif

goto turnright

turnright:

low left
high right
pause 500
low left
low right

if turns = 0 then
goto start
if turns = 1 THEN
goto turnleft
if turns = 2 then
goto checkturns
endif
endif
endif

goto turnright

nomov:


goto start


;
;subroutines
;
checkdirection:
;forward and backwards
if direction = 0 then
goto start
if direction = 1 THEN
goto forward
if direction = 2 then
goto backward
endif
endif
endif

checkturns:
;forward and backwards
if turns = 0 then
goto start

start_turn:
if turns = 1 THEN
goto turnleft
if turns = 2 then
goto turnright
endif
endif
endif
goto start

;left and right turns


return




end

;Subroutines
nap18ms:

clearwdt ;let us make these nap intervals accurate by resetting the
nap 0 ;the watch dog timer on the PIC itself.
return

nap54ms:
gosub nap18ms
gosub nap18ms
gosub nap18ms
return

nap108ms:
gosub nap54ms
gosub nap54ms
return

nap216ms:
gosub nap108ms
gosub nap108ms
return

nap540ms:
gosub nap108ms
gosub nap108ms
gosub nap108ms
gosub nap108ms
gosub nap108ms
return

nap1080ms:
gosub nap540ms
gosub nap540ms
return

nap1512ms:
gosub nap1080ms
gosub nap108ms
gosub nap108ms
return





Thanks guys for helping me out, and bruce...for some reason you taking the care to responding to this thread and knowing that it was me that ordered the other day really shows that ye top you guys are at the top of your game around here. I am wanting to talk to you about something I want to do...it involves selling chips and stuff.

Just get back to me at my email "GiroTechs [at] gmail".

Thanks for your help all!

Regards,

n0rig

P.S. If you can help me out with my code please, please do it quickly as I will need to have a working piece with a remote control (transmitter chip connected to tact switches to designate what the motors connected to the receiving chip will do).

mackrackit
- 4th February 2009, 22:22
I could be wrong, but this might work for you.
Receive:


MOVEMENT VAR BYTE[2] 'ARRAY VARIABLE
SERIN2 PORTC.1,396,[WAIT("9"),STR MOVEMENT\2]
MOVEMENT1 = MOVEMENT[0]
MOVEMENT2 = MOVEMENT[1]

.n0rig.
- 4th February 2009, 23:38
wtf...double post and I don't know why...READ BELOW :)

.n0rig.
- 5th February 2009, 00:09
That part I am good in, it is the if then and stuff that after I connect the chips to a power source....the transmitter is supposed to send the already set numbers to the receiver. When the receiver gets that info., it is supposed to use that information to control the in/out at the car so it can turn the motors on or off.

EDIT: WORKED PERFECTLY! NOW LET ME CENTER MY THING AROUND THAT...

This is what I did to test it with your code and it worked perfectly :D

Start:

PORTc.1 = 1 'turn communication pin high
TRAIN=$55
MOVEMENT VAR BYTE[2] 'ARRAY VARIABLE
SERIN2 PORTC.1,396,[WAIT("9"),STR MOVEMENT\2]
direction = MOVEMENT[0]
turns = MOVEMENT[1]
if turns = 1 then
high porta.1
if turns = 2 then
high porta.5
else
goto start
endif
endif
;goto checkdirection
goto start

BRILLIANT! I LOVE YOU! (just...I apreciate you :D)
Now to learn how to wire those buttons up so that they work when I press them down...I really don't know anything about that. Lets say I have porta.1 connected to a button that is also connected to ground pin (which is connect to ground...). In my code, will I be looking for a "0" or "1". *just thought of this: will I have to use the poke command to get the status of the pin (either low or high)*

Regards,

n0rig

mackrackit
- 5th February 2009, 00:27
Have one side of the button connected to 5 volts, the other to the PIC pin. Have a 10 k resistor connected to the same PIC pin and ground (zero).

When the button is pushed ( assuming it is NO ) the PIN pin will be forced HIGH, that is 1.


IF PORTA.1 = 1 THEN LABEL


Being this sounds like a school project, can you tell me why the below worked? :)

SERIN2 PORTC.1,396,[WAIT("9"),STR MOVEMENT\2]

.n0rig.
- 5th February 2009, 01:03
I am assuming that it "waited" to receive a digit of 9, then the array of 2 movement split the next 2 incoming bytes into the array.

That part worked if afterward I did a check on what digit was sent (in this case, a 1), and then if it was a 1, to turn the pin porta.1 high. This worked and turned an LED i had put there on. Buttttt, when I did the same thing with the following if then statements...it did not work:



;lets get moving!
checkdirection:
;forward and backwards
if direction = 0 then
goto checkturns
if direction = 1 THEN
goto forward
if direction = 2 then
goto backward
endif
endif
endif

checkturns:
;forward and backwards
if turns = 0 then
goto start

start_turn:
if turns = 1 THEN
goto turnleft
if turns = 2 then
goto turnright
endif
endif
endif
goto start

;left and right turns
forward:
if turns = 0 then
goto forwardgo
if turns = 1 THEN
goto forwardleft
if turns = 2 then
goto forwardright
endif
endif
endif

forwardgo:
high forwardl
high forwardr
pause 500
low forwardl
low forwardr

goto start


I am not sure why it would not work...

.n0rig.
- 9th February 2009, 03:44
Guys, I could not get the car working :(. I lost...but can take it to states :) :(

For some reason the data being sent, even when wired, would not work. I was using several if then statements but I think that some small discrepancy was what was making it not work.

I have posted my code above and would like someone to help me out with the trisa, porta things. I believe that is where i have messed up.

Please guys, support me on this and help me out.

Thanks...