PICAXE Radio Project

Discussion in 'The Projects Forum' started by DRock, Sep 25, 2011.

  1. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    I am trying to tackle my first PICAXE project and I want to eventually move it to transmit over RF. My code is as follows:

    Code ( (Unknown Language)):
    1.  
    2.  
    3. main:
    4.  
    5. if pinC.3 = 1 then flash
    6. goto main
    7.  
    8.  
    9. flash:
    10.  
    11. high B.2
    12. pause 100
    13. low B.2
    14. pause 100
    15. goto main
    16.  
    17.  
    Basically I am trying to sense when pinC.3 is pulled high and when it is I want to flash the LED to alert. I can get it running when I have the loop run with "if pinC.3 = 0 then flash" and when I click the button it stops the flash. But when I change it to "if pinC.3 = 1 then flash" it will not start flashing when I click the button.

    What gives?

    Thanks!
     
  2. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    Why does this program keep randomly flashing the LED and sometimes it stays on solid?

    Code ( (Unknown Language)):
    1. main:
    2.  
    3. if pinC.3 = 1 then flash
    4. goto main
    5.  
    6.  
    7. flash:
    8.  
    9. high B.2
    10. pause 100
    11. low B.2
    12. pause 100
    13. goto main
    I only have the V+ and V0 connected and the LED is connected to ground and pinB.2 while leaving all other pins floating. If I tap the breadboard it will sometimes stop flashing and sometimes stay solid...what gives?
     
  3. pilko

    Active Member

    Dec 8, 2008
    213
    20
    The people on this forum are very helpfull, but since you are device specific, you should post to the Picaxe forum, where you will find hundreds of experienced people.

    pilko
     
  4. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You didn't say what PICAXE you are using, but if you are using the 08M2, there are no B port pins. The following code will run on the 08M2; it will flash the LED as long as C.3 is high.

    Code ( (Unknown Language)):
    1. main:
    2.  
    3.     if pinC.3 = 1 then flash
    4.    
    5. goto main
    6.  
    7.  
    8. flash:
    9.  
    10.     high C.2
    11.     pause 100
    12.     low C.2
    13.     pause 100
    14.  
    15. goto main
    The following code will flash the LED as long as C.3 is low.

    Code ( (Unknown Language)):
    1. main:
    2.  
    3.     if pinC.3 = 0 then flash
    4.    
    5. goto main
    6.  
    7.  
    8. flash:
    9.  
    10.     high C.2
    11.     pause 100
    12.     low C.2
    13.     pause 100
    14.  
    15. goto main
     
  5. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    I programmed it with your new code that will flash if C.3 is high and the LED will still randomly flash. I only have V+ and V0 connected to the 08M2 and I have the LED connected to C.2 and ground, there is nothing else connected to the circuit so pinC.3 is getting no input. My question is this...why is it flashing? Also, if I tap a breadboard wire on the pinC.3 leg it will sometimes stop, and sometimes it will just stay on solid.

    I just went out and bought a new breadboard from Radioshack too because my old one was junk.

    I am very confused haha.

    Thanks again.
     
  6. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You can't leave pinC.3 floating.

    You need to connect a 4.7k resistor from pinC.3 to Vcc. That is called a pull-up resistor and will hold pinC.3 high until you connect it to ground through your switch.

    Or, you can connect the 4.7k resistor from pinC.3 to ground. That is called a pull-down resistor and will hold pinC.3 low until you connect it to Vcc through your switch.

    You really need to get in the habit of drawing schematics of your setups. It will help you to visualize the circuit better, and therefore learn what works and what doesn't, and it will help others know how you have things connected. Hand drawn is better than nothing, but there are some free software packages on the net that you can download.

    P.S. You do have a current limiting resistor from your LED to ground, right? (Like the two that I sent you.)

    ETA: The pull-up/pull-down resistors don't have to be 4.7k; as close as you can get between 3k and 12k.
     
    Last edited: Sep 27, 2011
  7. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    I was messing around with pull-up and pull-down resistors but I guess not in the correct way. And yes as a matter of fact I am using the green LED you sent me, it makes everything much simpler! Everything works correctly now, time to attempt the RF part.

    Thanks again!

    EDIT:

    This is my Basic Stamp 2 code:

    Code ( (Unknown Language)):
    1. ' {$STAMP BS2}
    2. ' {$PBASIC 2.5}
    3.  
    4. main:
    5.  
    6. IF (IN15 = 1) THEN flash
    7. GOTO main
    8.  
    9. flash:
    10.  
    11. HIGH 0
    12. PAUSE 100
    13. LOW 0
    14. PAUSE 100
    15. GOTO main
    This is my PICAXE code:

    Code ( (Unknown Language)):
    1. main:
    2.  
    3.     if pinC.3 = 1 then alarm
    4.        
    5.         if pinC.3 = 0 then
    6.        
    7.             low C.2
    8.        
    9.         endif
    10.  
    11.     goto main
    12.  
    13.  
    14. alarm:
    15.  
    16.     high C.2
    17.  
    18.     goto main
    I am trying to get the PICAXE to detect when pinC.3 goes high and then to send a constant high signal to my BS2 which will flash an LED in alarm. When the pinC.3 goes low then it sends a constant low signal and the BS2 does nothing.

    Right now it does the opposite, the LED flashes until I connect it to Vcc then it stops. I have tried searching a bunch to see exactly how to send a simple radio signal like this, hell I even bought a premium membership to Instructables, but I am still not sure if I am doing it right. I will try to find a schematic drawing program such as PSpice but the reason I haven't drawn any out so far is because I don't 100% trust myself to do them correctly haha. Time to think some more...
     
    Last edited: Sep 28, 2011
  8. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Here is a schematic of your basic PICAXE circuit. You can't be "100%" certain until you try. Note that I have shown the use of a 4.7k "pull-up" resistor; it's a pull-up because it pulls the input pin "up" to Vcc. Then, when the normally open switch is closed it puts a hard ground on pinC.3, which brings it low. A schematic is absolutely essential to understanding how a circuit works.

    Good luck.

    BTW, you do have a .01uF ceramic capacitor across legs 1 and 8 of the PICAXE, don't you?
     
  9. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    Yes that is what my circuit looks like except I do not have a 0.1uF cap from leg 1 to leg 8. What purpose does this serve? I am just guessing but if I continue to run the PICAXE without one I will severely diminish the life of the IC correct?

    The PICAXE side of my project is wired correctly now with your help, still a little hiccup somewhere but I am troubleshooting.
     
    Last edited: Sep 27, 2011
  10. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    The .01uF cap is just to suppress noise that can find its way onto power leads. It's good practice to put one across the power and ground pins of the PICAXE, but leaving it off doesn't hurt the PICAXE, however, it can sometimes cause erratic operation. Because you are using battery power, it's not as important, but still would be good practice.
     
  11. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    Ah ok I see, I just redid the circuit on the TX side and cleaned it up a lot since I know it's working correctly, I will make sure I include that when I design and etch my PCB.

    I am not sure I understand completely how to send the radio signal to the RX though because when I simulate the HIGH by plugging the pin15 on my BS2 into Vcc it flashes the LED correctly. I of course added the pull-down resistor in the correct location and everything works fine like this.

    However, when I run both of the above code with the BS2 pin15 plugged into the signal it flashes the LED constantly until I send the 08M2 TX circuit HIGH and then it stops, but it should be the other way around. This doesn't make sense because the pin15 should be pulled down by the 10k resistor unless it is getting the HIGH signal sent from the 08M2 which I know it is not sending.

    This leads me to believe there is something missing in my code and it is incorrect. I am working on an accurate schematic that I will post up tomorrow. I am looking for any tips or maybe some reading material that can explain this stuff better.

    Thanks!
     
  12. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    If you are planning to lay out PCB's, it's all the more important to learn to use a schematic drawing software that will translate to PCB layouts. Take a look at DipTrace; there's a free version you can down load and try. It seems complicated at first, but it gets easier as you learn.

    http://www.diptrace.com/download.php
     
    Last edited: Sep 28, 2011
  13. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    Ok so I drew up these two schematics which I believe represent my circuit accurately.

    The problem is that the LED on the receiver side blinks constantly until I press the switch on the transmitter side which stops it. I want it to be the opposite so it does not blink until I press the switch.

    I have tried using a resistor to pull the signal input low (on the RX side) until it gets the high signal from the transmitter but it does not work. I wrote the code like I did on the transmitter end to send a low signal constantly until the switch is pressed then send a high signal as kind of a "virtual pull-down" but it has not worked for me thus far.

    Also, the Diptrace program did not put the half circle when I place one wire over another to show that they are not connected so I hope it is not too confusing.

    Let me know what you think!

    Thanks.
     
  14. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    Good start on the schematics. You need a better representation of the 08M2; the symbol you are using is for the 08M. It's not wrong, but it's not completely representative of the 08M2. I'll try to attach a library file for the 08M2.

    You need to post your code for both the transmitter and the receiver side for me to see what you are trying to get the μC's to do. However, I think one problem with the transmitter is that you are trying to use pin C.3 (leg 4) as an output. It can only be an input; move the function to pin C.2 and see if that helps.

    Not confusing at all to me, but I know that DipTrace does not use the "loopover" method for indicating that wires are not connected. Instead, it shows a solid dot to indicate that crossing wires are connected.

    I think you are making progress and will succeed.

    You are welcome; I am far from an expert, but I am glad to help when I can. At some point, we will probably want to move these discussions to the PICAXE forum where there are some real experts.

    ETA: PM me your e-mail address, and I will send you a DipTrace library file with the 08M2, 14M2, and 20M2 components. I don't seem to be able to attach it here.
     
    Last edited: Oct 3, 2011
  15. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    I sent you a PM with my email, as soon as I get those libraries I will make the changes. Right now I am using a BS2 for the receiver side because my second breadboard is junk so I need to buy a third one. I am not sure how familiar you are with those devices but I am going to go out tomorrow probably and pick up another breadboard so I can use the 08M2 instead. I wrote the following code for each:

    EDIT: Its not working so I am just going to re-quote my earlier post with the code in it.

    EDIT2: Ok good that worked! I believe I can use the pin15 in the manner I wrote it as there is a tutorial in the educational book I have and when I hookup a push button switch to simulate the HIGH signal it will flash the LED correctly. I will definitely have to switch it when I use the 08M2 though as you pointed out, thanks again!
     
    Last edited: Oct 3, 2011
  16. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    This is my Basic Stamp 2 Receiver code:

    Code ( (Unknown Language)):
    1. ' {$STAMP BS2}
    2. ' {$PBASIC 2.5}
    3.  
    4. main:
    5.  
    6. IF (IN15 = 1) THEN flash
    7. GOTO main
    8.  
    9. flash:
    10.  
    11. HIGH 0
    12. PAUSE 100
    13. LOW 0
    14. PAUSE 100
    15. GOTO main
    This is my PICAXE Transmitter code:

    Code ( (Unknown Language)):
    1. main:
    2.  
    3.     if pinC.3 = 1 then alarm
    4.        
    5.         if pinC.3 = 0 then
    6.        
    7.             low C.2
    8.        
    9.         endif
    10.  
    11.     goto main
    12.  
    13.  
    14. alarm:
    15.  
    16.     high C.2
    17.  
    18.     goto main
     
  17. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    I just wired it up with the new breadboard and another 08M2 and it does the same thing it did when I was using the BS2. I switched the input to pin C.3 like you said and I have pin C.2 outputting to flash the LED and to send the signal through the receiver.

    Here is the new picaxe receiver code I just wrote:

    Code ( (Unknown Language)):
    1.  
    2.  
    3. main:
    4.  
    5.     if pinC.3 = 1 then flash
    6.    
    7.         if pinC.3 = 0 then
    8.        
    9.             low C.2
    10.    
    11.         endif
    12.    
    13.     goto main
    14.    
    15.  
    16. flash:
    17.  
    18.     high C.2
    19.    
    20.     pause 100
    21.    
    22.     low C.2
    23.  
    24.     pause 100
    25.    
    26.     goto main
    27.  
     
    Last edited: Oct 4, 2011
  18. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    OK, the transmitter code as you have it only flashes C.2 as long as the button is held down, and each flash is only 100ms (1/10 of a second.) Change the 100ms to 2000ms both (high and low) so that the flash lasts long enough to check with your DMM. You should be able to see the high (about 4.5VDC) pulse on and off (while the button is pressed.) If that is happening, then we can check the receiver end. Post your code for the receiver 08M2.

    BTW, are you powering both the transmitter and the receiver with the same power supply?
     
  19. DRock

    Thread Starter Member

    May 7, 2011
    68
    0
    Yes same power supply, and the code I posted last is my receiver code. I am going to use a mercury switch to trigger the pulse but for right now I am using a push button which I just hold down.

    The code I wrote in the post before that contains the transmitter code.
     
  20. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    OK, I was confused, but I understand now. I loaded the transmitter code in my 08M2 and it did just what you want. Then I loaded the receiver code in my 08M2 and it also did what you want. You obviously have a wiring error or a loose connection somewhere. Use your DMM to find out where you are losing your signal; start at C.2 on the transmitter, then check C.3 on the receiver, etc. It should be easy to find where the signal is being lost.

    Your receiver schematic doesn't show a pull-down resistor on C.3, but you should have one: 4.7k is optimum.
     
    Last edited: Oct 4, 2011
Loading...