Serial problem between BasicStamp code and PBP code


Closed Thread
Results 1 to 23 of 23
  1. #1

    Unhappy Serial problem between BasicStamp code and PBP code

    I wrote a program for a BasicStamp2p and it works perfect. I then copied the code to PBP and made the necessary changes. When I take the two serial lines from the Stamp and connect them to the PIC16F84, the program will not function. The first thing it should do is center the 2 servos. I have attached the 2 files. Any help will be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    If it is serial communication, I would start by sending a simple text to a PC in Stamp, then do the same in PBP.

    Don't use your entire logic, just "HELLO". It will be much easier to show code here and debug.

    (I can't see your files from my phone)

    Robert

  3. #3
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Two questions.

    Is there a serial ground connection between communicating modules (Not mentioned in pin assignments notes)

    Is the Bluetooth module receiving commands and outputting serial. Scope checked etc.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Hi
    Not sure about your code. But when using Basic Stamp syntax for serial. You should place at the top of your code.

    Code:
    Include "modedefs.bas"
    In the back of the Picbasic Pro manual there is a section on the differences between PBP and Basic Stamp.

    Hopefully you can make it work.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    I have tried it with Include "modedefs.bas" and without. The code is not very long. What I need is for someone to look at the 2 files and see if they can tell why it won't work on the PIC. I have both the PIC and the Stamp and FT639 and Bluetooth module on breadboard. When I hook the 2 serial lines to the Stamp I can control the servos. When I remove the two serial lins and connect them to the PIC. it won't work. All the pin configuration is documented in the 2 files. lt appears to be a serial problem. When I power up the circuit it should automatically center both servos. It does with the Stamp but not with the PIC. Hope this helps.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,596


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    You might get more help if you post your code directly. Some may not be able to open those files on mobiles.

    Click GO ADVANCED at bottom right of a new post and use the code tags like this (CODE)...(/CODE) but using [ ].

    My money is on a config.

    What version of PIC BASIC PRO?

    Robert

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    I am new to this. Have never posted before. Am 67 and trying to learn. I am using PBP ver 2.50C. The code files can be opened with notepad they are not very complicated or big. I don't know how to add my code files to a post. When I tried it the first time, it put them at the bottom of the post. The commands go over the air via Bluetooth then serially to BasicStamp then serially to servo controller. Works great. When I try it with the PIC nothing happens. I assume it is a serial problem from PIC to servo controller because it does not need the bluetooth at the start . It first sends centering command serially to servo controller to center servos. That does not happen. I have tried changing serial config from true to inverted the manual also says bit 15 can be for open or driven. Whatever that means.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    No "NIBs" in pbp only bits, bytes, words & longs. Are you using "Default" configs ? have you gotten an LED to blink? I see NO "DEFINE OSC 4" in your code to tell PBP the pic is operating at 4 mhz
    Are you using a crystal, a resonator or internal RC oscillator? Does you config statement reflect what you actually have ?
    I have tried changing serial config from true to inverted the manual also says bit 15 can be for open or driven. Whatever that means.
    open is an open collector where a pullup resistor pulls the output high whereas driven means an output transistor drives the output high or low.
    Last edited by Archangel; - 4th April 2014 at 07:49.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Thank you for the reply. I had to rewrite the send routines because of the no "NIBS". Yes I am using default configs. I tried DEFINE OSC 4, INCLUDE "bs2defs.bas" and INCLUDE "modedefs.bas. I even tried their new program "meCONFIG" which gave me nothing but errors. I am using a 4 Mhz resonator on a PICBIT-18 board. I have used this board and PIC to blink an LED to make sure my PIC and board were working. The PIC I am using is a PIC16f84 /10 but I assume you can run a 10 Mhz at 4 Mhz with no problems. Thank you for the info on bit 15, good to no. I thought of disabling all interrupts, but don't know if the serial commands use interupts.

  10. #10
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Whats the control protocol? Is it numeric or ASCII ?

    i.e. what are the units expecting between themselves. At the moment 122 is "z" sent serially.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    From the android app I receive ASCII over the air to the Bluetooth module. From the Blutooth out serial numeric to FT639 which requires 2 bytes as per the send1 or send 2 depending whether or not to move pan servo or tilt servo. The protocol for the 2 bytes is Lower Byte = 0sssxxxx Upper Byte 1sssxxxx sss = servo number xxxx = lower nibble of position byte yyyy = upper nibble of position byte position byte is from 0 - 255.

  12. #12
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    OK lets get this straight. Is it like this :-


    Android --over air ---ASCII ---- BTooth BTooth ----- Z ------PIC16F84 PIC16F84 ----2bytes------FT639

    What is Z protocol? You have that as expecting ASCII in the code.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  13. #13
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Ah following it a bit better now.

    I'm near your age and still learning PBP, usually by trial and error.

    Try this and see if it works, SEROUT2 according to manual is same as BS2 serout

    I'm probably completely wrong
    Attached Files Attached Files
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  14. #14
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Allan,

    Search the net for MicroCode Studio Editor (MCS) it is free and will help tremendously.

    Any code posted on forum will likely be raw. i.e. no code formatting unless it is written that way
    so usually people copy the code into MCS which displays in formatted code.


    The code tag is the # button on the posting panel.
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  15. #15


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    The Android APP has U D L R arrows plus a button in the center. When I press one of the arrow keys or the center button, it sends a Capital U D L R or C via Bluetooth to the HC-06 bluetooth module which sends it to the PIC. I then check what was sent and select which way to move the servos using the appropriate servo controller command bytes. The ASCII values are only used to tell which button was pressed. The values 122(z) 117(u) 85(U) 90(Z) and 103(g) are numeric values needed to send to the FT639 to intialize it. Once it it initialized then the protocol explained previously is used to position the servos.

  16. #16


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    I am using MicroCode Studio Editor. That's where the example code was written in. I had to change the extensions on the 2 files. otherwise it would not let me upload them. The BasicStamp extension shoul be .bsp and the PIC code ext should be .pbp

  17. #17


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    I tried your code. Still not working. What I am having a hard time with is the code for the BasicStamp works 100%. The only changes I needed to make according to the PBP manual was the baud rate. The BasicStamp2p is faster than the BasicStamp2 and the baud rates in the PBP manual Appendix A are the same as the BasicStamp2 which is what I need for the PIC16F84 at 4Mhz. The other change was the move1 and move2 routines. PBP does not support nibble so I had to modify the code to send the apporpriate low and high bytes.

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    position1 and position2 are declared as byte vars . there is no position1.highbyte
    the position1 high nibble is Hbyte = ( position1 & %11110000 )>>4 , low nibble Lbyte = position1 & %00001111.
    SEROUT2 2,16780,[BIN Lbyte,BIN Hbyte] would send 16 ascii 0 or 1's ( 0x30/0x31) is that what you really want ?
    I suspect you should try SEROUT2 2,16780,[position1]

  19. #19


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    The code you are referring to is wrong. I uploaded 2 files Pan_andTilt.bas is for the BasicStamp2p and Pan_andTilt2.bas was for the PIC. I had to change the move1 and move2 subs because PBP does not support the .LOWNIB .HIGHNIB commands. If you look at Pan_and_Tilt2.bas you will see the changes in move1 and move2. They accomplish the same thing. I am adding the PDF for the FT639.
    Attached Images Attached Images
    Attached Files Attached Files

  20. #20


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    I have added an LCD to see what is going on. I have verified that the bluetooh module is receiving correctly, also the Lbyte and Hbyte I'm sending to the FT639 are correct. For some reason the data is not going to the FT639 correctly. I have tried all four possible 2400 baud rates, 396, 16780, 33164, and 49548. The serial_in works perfect, The serial_out command is the problem.

  21. #21


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    Problem solved. Added PAUSE 5 after each command sent in intialize subs setup: setpulse: setheader: and setactive: and works like a charm. Going to have a glass of wine. My guess is that in the BasicStamp code the interpreter takes a while but the PIC code needs no interpretation and therefore executes faster which was to fast for the FT639. By giving the chip time before the next instruction works. Thanks to all who tried to help. Much appreciated.

  22. #22
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    glad you got it to work .
    the pan_and_tilt2 as posted still looks wrong to me the moves should look like this

    move1:
    Lbyte = (position1 & %00001111) 'servo 0 + lownib
    Hbyte = %10000000 |( (position1 & %11110000)>>4) 'servo 0 + highnib
    SEROUT2 serial_out,baud1,[Lbyte,Hbyte] 'send command to FT639
    PAUSE 100
    RETURN

  23. #23


    Did you find this post helpful? Yes | No

    Default Re: Serial problem between BasicStamp code and PBP code

    You are correct. I modified the code to the following a few days ago.
    Move1:
    interim = position1 & %00001111
    Lbyte = interim | %00000000
    interim = position1 & %11110000
    Hbyte = (interim >> 4) | %10000000

    Your's look more compact I think I will change mine. Thanks. I'm learning.

Similar Threads

  1. Zero-error 1 second Timer code for PBP?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th June 2013, 14:31
  2. pbp code
    By samixta in forum PBP Wish List
    Replies: 2
    Last Post: - 2nd July 2011, 20:53
  3. pbp code for DS3234
    By itsssyam in forum General
    Replies: 2
    Last Post: - 23rd December 2009, 10:31
  4. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  5. Changing Swordfish code to PBP
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th April 2008, 01:28

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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