#### DRock

Joined May 7, 2011
68
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:

Rich (BB code):
main:

if pinC.3 = 1 then flash
goto main

flash:

high B.2
pause 100
low B.2
pause 100
goto main
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!

#### DRock

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

Rich (BB code):
main:

if pinC.3 = 1 then flash
goto main

flash:

high B.2
pause 100
low B.2
pause 100
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?

#### pilko

Joined Dec 8, 2008
213
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

#### tracecom

Joined Apr 16, 2010
3,944
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.

Rich (BB code):
main:

if pinC.3 = 1 then flash

goto main

flash:

high C.2
pause 100
low C.2
pause 100

goto main
The following code will flash the LED as long as C.3 is low.

Rich (BB code):
main:

if pinC.3 = 0 then flash

goto main

flash:

high C.2
pause 100
low C.2
pause 100

goto main

#### DRock

Joined May 7, 2011
68
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.

#### tracecom

Joined Apr 16, 2010
3,944
nothing else connected to the circuit so pinC.3 is getting no input.
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:

#### DRock

Joined May 7, 2011
68
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:

Rich (BB code):
' {$STAMP BS2} ' {$PBASIC 2.5}

main:

IF (IN15 = 1) THEN flash
GOTO main

flash:

HIGH 0
PAUSE 100
LOW 0
PAUSE 100
GOTO main
This is my PICAXE code:

Rich (BB code):
main:

if pinC.3 = 1 then alarm

if pinC.3 = 0 then

low C.2

endif

goto main

alarm:

high C.2

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:

#### tracecom

Joined Apr 16, 2010
3,944
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?

#### Attachments

• 95.9 KB Views: 86

#### DRock

Joined May 7, 2011
68
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:

#### tracecom

Joined Apr 16, 2010
3,944
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.

#### DRock

Joined May 7, 2011
68
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!

#### tracecom

Joined Apr 16, 2010
3,944
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.
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.

Last edited:

#### DRock

Joined May 7, 2011
68
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.

#### Attachments

• 16.5 KB Views: 53
• 14.3 KB Views: 45

#### tracecom

Joined Apr 16, 2010
3,944
Ok so I drew up these two schematics which I believe represent my circuit accurately.
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.

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.
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.

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.
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.

Let me know what you think!
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:

#### DRock

Joined May 7, 2011
68
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:

#### DRock

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

Rich (BB code):
' {$STAMP BS2} ' {$PBASIC 2.5}

main:

IF (IN15 = 1) THEN flash
GOTO main

flash:

HIGH 0
PAUSE 100
LOW 0
PAUSE 100
GOTO main
This is my PICAXE Transmitter code:

Rich (BB code):
main:

if pinC.3 = 1 then alarm

if pinC.3 = 0 then

low C.2

endif

goto main

alarm:

high C.2

goto main

#### DRock

Joined May 7, 2011
68
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:

Rich (BB code):
main:

if pinC.3 = 1 then flash

if pinC.3 = 0 then

low C.2

endif

goto main

flash:

high C.2

pause 100

low C.2

pause 100

goto main

Last edited:

#### tracecom

Joined Apr 16, 2010
3,944
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.
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?

#### DRock

Joined May 7, 2011
68
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.

#### tracecom

Joined Apr 16, 2010
3,944
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.
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: