PDA

View Full Version : Serial problem between BasicStamp code and PBP code



AllanZilkowsky
- 3rd April 2014, 06:32
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.

Demon
- 3rd April 2014, 12:39
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

tasmod
- 3rd April 2014, 16:04
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.

mark_s
- 3rd April 2014, 16:05
Hi
Not sure about your code. But when using Basic Stamp syntax for serial. You should place at the top of your 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.

AllanZilkowsky
- 3rd April 2014, 21:31
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.

Demon
- 3rd April 2014, 22:08
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

AllanZilkowsky
- 4th April 2014, 02:00
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.

Archangel
- 4th April 2014, 07:42
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.

AllanZilkowsky
- 4th April 2014, 16:01
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.

tasmod
- 4th April 2014, 18:09
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.

AllanZilkowsky
- 4th April 2014, 18:37
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.

tasmod
- 4th April 2014, 20:11
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.

tasmod
- 4th April 2014, 20:56
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 :D

tasmod
- 4th April 2014, 21:05
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.

AllanZilkowsky
- 4th April 2014, 23:00
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.

AllanZilkowsky
- 4th April 2014, 23:04
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

AllanZilkowsky
- 4th April 2014, 23:21
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.

richard
- 5th April 2014, 00:59
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]

AllanZilkowsky
- 5th April 2014, 16:04
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.

AllanZilkowsky
- 6th April 2014, 00:34
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.

AllanZilkowsky
- 6th April 2014, 00:44
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.

richard
- 6th April 2014, 00:53
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

AllanZilkowsky
- 6th April 2014, 02:15
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.