Xbee P2 FlexBASIC
Rsadeika
Posts: 3,837
I have just started to look into using Xbee in my P2 FlexBASIC robot project. Anybody have something working already?
I found some Xbee modules, that I had purchased back some time ago. Two are S1 modules and two are S2 modules, I think I will try to use the S2 modules, because they have mesh capability.
I also downloaded the Xctu User Guide; I viewed the Jon youtube session on Xbee, but I think I will be more comfortable with a paper manual in front of me.
So, my intent is to be able to communicate with the robot via the Xbee, instead of a wire.
Ray
Comments
Parallax has an XBee book. The code is in PBASIC (?) and Spin, but the information is useful.
Jon Titus (a member of the Parallax community) wrote a book on using XBee some time ago. The XCTU screens don't match, but the information is still very useful. It has lots of examples in C which you have comfort with, so you should be able to modify them easily.
-- https://www.amazon.com/Hands-XBEE-Lab-Manual-Communications/dp/0123914043/
This is another from the Parallax site:
https://www1.parallax.com/downloads/getting-started-xbee-rf-modules-text
This is my first try at using xbee with FlexBASIC. The program compiles, but it looks like the two xbee's are not understanding each other.
I tested out the xbee's using an Activity Board, and the xbee USB breakout, that setup, the xbee's, was working as expected.
I also, on the FlexBASIC side, tried out both SmartSerial and SimpleSerial, neither one was doing the job. Not sure if that is where the problem is. Since FlexBASIC does not have access to a P2 FullDuplexSerial, I could not test out a third program. Not sure what to try next to get this xbee setup too work.
Ray
Here is what I have going so far, it is sort of working.
The problem that I am having is, for some reason, the 'if inBuffx = "a"' is not working as expected. When I press the 'a' key on the remote keyboard, the program is getting 97, and not the ascci 'a'. When I change to 'if inBuffx5 = 97', then it recognizes that the 'a' key was pressed, and it does what it is supposed to do.
I switched over to jm_FullDuplexSerial.spin2 for this exersise, to get more control, but it seems that I cannot get FlexBASIC to cooperate correctly. I need help.
Ray
97 is the ASCII code for the letter 'a'. If you want to convert the result of xbee.rx into a character string, you need to do:
which is not the same as what you wrote.
My setup, at the moment is an xbee S1, in a SIP module with the P2 Edge setup. The other xbee S1, in the USB module, is acting as the base, and can be connected to whichever PC that I want.
I have the xbee's talking to each other, so that has been a good sign. All that I did was connect each xbee to xctu, set everything to default, write it, and everything seems to be working as expected, in transparent mode. I guess this was the easy part.
I have been using the GTK serial port terminal program on the xbee base side, but it looks like I might have to write a special terminal program, for that side of things.
Now the hard part, I want to replace the S1 with the S2, and try to get the mesh capability thing to work. More reading and making mistakes.
Ray
I believe you have to switch to an API mode for that to work -- it's no longer a simple matter of serial passthrough.
Below is a working FlexBASIC program for testing the xbee that is connected to the P2 Edge setup.
I am using jm_FullDuplexSerial.spin2 for this program, I kind of wish it had a strrx() function so I could use a string on input instead of just a character. I did try to get SmartSerial.spin or SimpleSerial.spin2 for the using a string on input, but I could not get it to work. Hopefully something will show up to fix the problem.
Next, I will change out the S1 xbee with an S2 xbee and start looking into having more than two xbee's online, and see what I can do with that.
I did do a search on ebay for xbee related stuff, not that much is available. I do have some TP-link Kasa WiFi plug mini modules implemented, it could be nice if I could replace them with an xbee equivalent.
Ray
I am making some headway, but not there just yet.
I am trying to setup a star topology, using an S2, S1, and S1. The S2, i have setup as a coordinator-AT, and the S1 I have setup as end device-AT. The part that I am having trouble with is the addressing of the units.
The S2 coordinator-AT, CH-14, PAN ID-234, SC-1ffe, DH-0, DL-2, MY ADDRESS-1.
The S1 end device-AT, CH-14, PAN ID-234, SC-1ffe, DH-0, DL-1, MY ADDRESS-2.
The S1 end device-AT, CH-14, PAN ID-234, SC-1ffe, DH-0, DL-0, MY ADDRESS-3.
Their is communication between the coordinator and the end device, but I cannot talk to the individual end device, both respond at the same time. I cannot figure this addressing scheme.
Ray
This is the new code for the xbee modules, I added a third end device to the mix.
The S2 coordinator-AT, CH-17, PAN ID-234, SC-1ffe, DH-0, DL-ffff, MY ADDRESS-0.
The S1 end device-AT, CH-17, PAN ID-234, SC-1ffe, DH-ffff, DL-0, MY ADDRESS-1.
The S1 end device-AT, CH-17, PAN ID-234, SC-1ffe, DH-ffff, DL-0, MY ADDRESS-2.
The S1 end device-AT, CH-17, PAN ID-234, SC-1ffe, DH-ffff, DL-0, MY ADDRESS-3.
I tried using dh and Dl for addressing, put I never got it work, so I decided, for the time being, to use a different method. So far it seems to be working, as expected. The FlexBASIC example shows how the individual module ID would work, in this case, in a very simplistic manner.
The coordinator component can get very complicated, not sure if Python would be the language to use. So far every thing seems to working as expected, in this very simplistic form.
Ray
FlexBASIC example
Python example