Please help

tmack

Member
I am running this code in a 08m:

Do: if pin1= 1 then SEROUT 4,N2400,("1")
else SEROUT 4,N2400,(0) endif
if pin2= 1 then SEROUT 4,N2400,("2")
else SEROUT 4,N2400,(0) endif
if pin3= 1 then serout 4,n2400, ("3")
else serout 4,n2400, (0) endif

LOOP


I am running this code in a 18A:

my_loop:
serin 4, N2400, b0
if b0 = "1" then
high 0
elseif b0= "2" then
high 1
elseif b0= "3" then
high 2


else ' b0 = 0
low 0,1,2,4
endif
goto my_loop


Both picaxes are mounted on prototype boards. Both are able to have the program loaded into them. I have a wire going from pin 4 of the 08m to pin 4 on the 18a. There is another wire going from ground on the 08m to ground on the 18a. The wire going to the input on the 18a protoype board is going to the inside hole immediately to the right of the small #4. The ground is coming in to immediately right of the little G. Any Ideas why this would not be working at all? Im not sure what it means but When I got my picaxe at a little class we cut R1 off of the board and put a 1K resistor where it says R7.If that has any bearing on the situation. Thanks for any help.
 

hippy

Technical Support
Staff member
I cannot comment on the hardware, but there are a number of problems with your code -

SEROUT 4,N2400,(0) should probably be SEROUT 4,N2400,("0")

Even so, you probably do not want to send "0" whenever a pin isn't high, only when none are high.

You are also sending bytes incredibly quickly, far quicker than your receiver can handle them while it is processing the last byte received. You should add a PAUSE between sending every byte from your transmitter.

You probably want to have something like this -
Code:
Do
  If pin1 = 1 Then
    SerOut 4, N2400, ("1")
    Pause 100
  Else
    If pin2 = 1 Then
      SerOut 4, N2400, ("2")
      Pause 100
   Else
      If pin3 = 1 Then
        SerOut 4, N2400, ("3")
        Pause 100
      Else
        SerOut 4, N2400, ("0")
        Pause 100
      End If
    End If
  End If
Loop
A more compact version would be -
Code:
Do
  b0 = "0"
  If pin3 = 1 Then : b0 = "3" : End If
  If pin2 = 1 Then : b0 = "2" : End If
  If pin1 = 1 Then : b0 = "1" : End If
  SerOut 4, N2400, (b0)
  Pause 100
Loop
If you wanted to get really clever ....
Code:
Do
  LookDown 1,(0,pin1,pin2,pin3,1),b0
  b0 = b0 & 3
  SerOut 4, N2400, (#b0)
  Pause 100
Loop
You can also improve your receive loop by using a SELECT-CASE statement -
Code:
Do
  SerIn 4, N2400, b0
  Select case b0
    Case "0" : Low  0, 1, 2, 4
    Case "1" : High 0
    Case "2" : High 1
    Case "3" : High 2
  End Select
Loop
 
Last edited:

tmack

Member
Thanks

Hippy, Thanks ALOT! I got it up! Part of my issue was hardware. I think the resistor set up on my prototype board was not right to use with serial communication.When I switched over to (2) 08M boards it seemed to be kinda working but the leds would just flash quickly and apparently randomly. So I looked back on the board found your answer and loaded that into my set up. Wah lah It worked like a charm. You were right ,It sure was sending the data too fast for the reciever to process. Thank you so much. I am excited to see that I can FINALLY Make this work.Now I am just going to change this over to 18x's and pa ir them up to give me several input/outputs.Thanks again.
 

pcfixit

New Member
Tmack, small point as far as serial comms between PICAXES, if you cant get the data to transfer properly,try adding a 10K resistor between your serial line and 0V. Worked a charm when I was having problems with serial comms.
Good luck with any future projects
Alex :)
 
Top