Newbie to pic but not electronics


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Jul 2007
    Posts
    67

    Default Newbie to pic but not electronics

    Hi I have stepped into the world of the pics

    basicly I have a knowledge of electronics but I just started out using pic micro controllers.

    I wanted to use a pic 16f84a to control leds and servos wirelessly

    now I know I need a transmitter and a receiver but for the programing what codes would be used to press a button or turn a potentiometer and have a servo move or leds turn on or do a sequence I programed for the leds or the servo.

    Would this have to be done through serial and if so is there any other ways?

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Check out Bruce's Website

    http://www.rentron.com

    or more specifically, pages like this

    http://www.rentron.com/ruf-bot.htm
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Thank you for replying but I did try that website already the ruf bot source code was not functional. I tryed entering it in microcode studio and it gave me a list of things that were wrong.

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    I'm sure you will hear this eventually from someone, so I might was well be the one to say it:

    Have you got just a simple LED blinking? Did you get it responding to your button? Have you got the PIC to read the POT and output the value in some way (like a LCD)? Have you been able to TX/RX serial over normal lines, like with a PC?

    Here is the point. As most of us have discovered, there is a bit of a learning curve, both with the hardware portion of PICs as well as the firmware. So start small. Take it a one part at a time. Once all the individual parts are functioning, start assembling the parts into a whole application to meet your needs.

    In this process you will get a lot of help from the folks on this forum.

    SteveB
    Last edited by SteveB; - 6th July 2007 at 20:54. Reason: Typo

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Techbuilder View Post
    Thank you for replying but I did try that website already the ruf bot source code was not functional. I tryed entering it in microcode studio and it gave me a list of things that were wrong.
    That 'ruf bot' code has been posted at that site for quite some time, and I don't think the author would intentionally leave it posted if it didn't work.
    So, since you are just beginning in PICs...
    Do you have a PIC programmer? Which one?
    Do you have PicBasic or PicBasicPro from MeLabs or one of their distributors? Which version?
    Which errors did Microcode Studio give you? Which version of MCS are you using?
    Have you built a plain ol' 'Blinky LED' type thing yet?
    Have you tried to build anything more complicated than that? More than one LED? Pushbuttons lighting LEDs? Pushbuttons controlling servo's?

    Don't try and tackle the whole thing at once from the get-go...you'll get discouraged and quit before you even get started... You didn't learn how to drive in a high-performance sports car...

    Break it down, simple stuff first, combine the simple stuff into not-so-simple stuff, then put it all together...

    EDIT: In other words, just what SteveB said (which I would've had notice had I bothered reading...)
    Last edited by skimask; - 6th July 2007 at 20:24. Reason: DOH!

  6. #6
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    I have done the blinking led and I own picbasic pro that I got from microengineering labs. My programmer I bought from ebay and I do not remember what errors I got since it has been months since I tried it.

    How do you know rentron didn't just put it on with out trying the firmware out?

    Who knows

    But anyway I don't get how reading the inputs work yet.


    Let's start simple say I wanted two leds to chase eachother

    I connect led 1 to RB0and led 2 to RB1

    and I guess I would connect the switch to RB2

    but would I have to read RB2 Input
    then send and output to RB0 and RB1 when RB2 makes contact?

    The PIC I am using is a 16F84A
    Last edited by Techbuilder; - 6th July 2007 at 21:06.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Techbuilder View Post
    How do you know rentron didn't just put it on with out trying the firmware out?
    And throw ANY credibility out the window? I don't think so... Besides, I've seen their work, I've used their products and software. Good stuff...

    But anyway I don't get how reading the inputs work yet.
    Let's start simple say I wanted two leds to chase eachother
    I connect led 1 to RB0and led 2 to RB1
    and I guess I would connect the switch to RB2
    but would I have to read RB2 Input
    then send and output to RB0 and RB1 when RB2 makes contact?
    The PIC I am using is a 16F84A
    Good example of how to use a button and the BUTTON command in Section 5.2 of the PBP manual. But that's probably too much for your example...
    To read a pin, you have to set it to an input (as the datasheet states), you may also need a variable to store the state of that pin so you can work with it elsewhere.

    input_pin var portb.2
    input input_pin
    temp var byte
    temp = input_pin

    Now "temp" has the state of PortB.2.
    Again, break it down to the simplest possible level...
    Write a program that reads the portb.2, and have the LED on portb.0 light up if the button on portb.2 is pressed, and the LED on portb.1 light if the button is released.

  8. #8
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Ohh I get it that makes perfect sense

    So all I would have to do is read the input

    but say when I pressed the button I want the RB0 led to flash 4 times and RB1 led to flash 8 times when I press the button once.

    How would that work?

  9. #9
    Join Date
    Feb 2006
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Do you mean how would you have the different LEDs flash a different number of times depending on how many times you push the button? This could be accomplished by waiting for the input pin to go high then adding 1 to a pre-defined variable. You would then wait for the input pin to go low before monitoring the input for a high signal. After a pre-defined amount of time waiting for the high signal, the number of button pushes would be stored in the variable that holds the count.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Techbuilder View Post
    Ohh I get it that makes perfect sense

    So all I would have to do is read the input

    but say when I pressed the button I want the RB0 led to flash 4 times and RB1 led to flash 8 times when I press the button once.

    How would that work?
    For/Next.....If/Then.....counters in a loop....thousand different ways of doing it.
    Write some code, we'll dig thru it all...

  11. #11
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Try this

    Hi,

    While PicBasic makes your life real easy I still recommend to study the internals of the PIC micro to get the most out of PBP. To get started try the link here http://techtrain.microchip.com/x14/ and view or download the flash based presentation. IMO it accelerates learning the PIC....
    Regards

    Sougata

  12. #12
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Thank you very much everyone has been helpful

    Although I was reading on the button command wouldn't that be the easiest way to go?

  13. #13
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Techbuilder View Post
    Although I was reading on the button command wouldn't that be the easiest way to go?
    Not if you're just reading a single switch on a single port performing a single function...
    Now if you're looking for functionality like auto-repeat, debouncing, sure, button may be the way to go.

  14. #14
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Gotcha I guess I will just go with IF, THEN , GO Statements
    How exactly would that work

    I know I would have to set LED to HIGH

    but is this kind of how it would look

    IF port.0=1 THEN
    port.1 = high

    Something like that?

  15. #15
    Join Date
    Jul 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Here's a better constructed code I made then the one up

    Button var PORTB.0 ' Push button
    LED1 var PORTB.1 ' Led 1
    LED2 var PORB.2 ' Led 2
    Pushed var byte ' Variable will contain the byte
    If PUSHED =1 Then ' If button is push
    High LED1 ' Turn on the LED
    IF PUSHED=0 Then
    High LED2

    Endif
    Last edited by Techbuilder; - 12th July 2007 at 23:44.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Just so nobody gets the wrong idea...I'm not being a royal a$$ here....

    In your program...(and again, not being an a$$, just trying to get you to understand what's what here)
    Code:
    Button var PORTB.0		' Push button
    LED1 var PORTB.1                           ' Led 1
    LED2 var PORB.2                             ' Led 2 
    
    Pushed	var	byte		' Variable will contain the byte
    
    	If PUSHED =1 Then	             ' If button is push
    		High LED1	' Turn on the LED
    IF PUSHED=0 Then
               High LED2	
    endif
    You have 'If Pushed = 1'...Pushed is a variable...Where is 'Pushed' being set to anything, at least anything that is going to be useful to you?

  17. #17
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Instead of taunting people, Jeremy, it would be better to directly point out the error. You'll find that most people don't come to forums asking for help as a first resort.

  18. #18
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    shouldnt it be something like this?

    Code:
    Button var PORTB.0		' Push button
    LED1 var PORTB.1                           ' Led 1
    LED2 var PORB.2                             ' Led 2 
    
    
    	If Button=1 Then	             ' If button is push
    		High LED1	' Turn on the LED
    IF Button=0 Then
               High LED2	
    endif

  19. #19
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You have two IF's but only one ENDIF, so that would error...

    Try this... which includes a few additional things to think about....

    Code:
    	ButtonA var PORTB.0
    	LED1 var PORTB.1
    	LED2 var PORTB.2
    
    	TRISB=%00000001
    
    Loop:
    	If ButtonA=1 then
    		High LED1
    		LOW LED2
    		else
    		LOW LED1
    		HIGH LED2
    		endif
    	Goto Loop
    
    	End
    Finally, check your PBP manual - BUTTON is a reserved word, you can't use it as a variable.

Similar Threads

  1. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. PIC to PC newbie
    By Michael in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 19th June 2007, 01:07
  4. PIC Newbie
    By azmax100 in forum Schematics
    Replies: 7
    Last Post: - 23rd February 2007, 04:52
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts