Help with setting up serial communication on FEZCerbuinoBee

I am just starting development on the FEZCerbuioBee hardware board. I have a XBee radio that i want to act as a coordinator for two Xbee router radios.I’ve updated with the latest Firmware on the deviceFEZCerbuionBee I’ve installed VS2012 Professional, .NET Micro Framework 4.2 and 4.3 and I’ve installed .NET Gadgeteer which also has these frameworks in it’s subdirectories. I have some experience in C# but I can’t seem to get the serial communication between the board and my computer to work.

I’ve attached a screen shot i’m having trouble understanding what to do with the GT.sockets class and it is also confusing to which serialPort class to call as there seem to be several. Can someone help explain how to set up a basic serial connection with these libraries and how they interact with each other?

I also want to add that I’m connecting via the mini-usb port on this board to my PC which is running windows 8.

More specifically, I’m trying to use the USB Client mode on the FEZ CerbuinoBee

Hi,
you can use the usbSerial Module to communicate with your PC.
https://www.ghielectronics.com/catalog/product/287
with this module you can initilize the Serial port:


 try
                {
                    usbSerial.Configure(115200, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8);
                    
                }
                catch (Exception e)
                {
                    Debug.Print(e.ToString());
                }
                if(!usbSerial.SerialLine.IsOpen)
                {
                    usbSerial.SerialLine.Open(); 
                ]

May be that it is possible to use the mini-usb on the board, but I don’t know how.

To use a Serial port on an U socket you can add a reference to Gadgeteer.Serial
then


public GTI.Serial serialPort;
...
...
Socket socket = Socket.GetSocket(socketNumber, true, this, null);

                                            
                this.serialPort = new GTI.Serial(socket, (int)baud, GTI.Serial.SerialParity.None, GTI.Serial.SerialStopBits.One, 8, GTI.Serial.HardwareFlowControl.NotRequired, this);
                
                //this.statusInt.Interrupt += new GTI.InterruptInput.InterruptEventHandler(statusInt_Interrupt);
                this.serialPort.ReadTimeout = Timeout.Infinite;
                this.serialPort.Open();

1 Like

Thanks for this info. Is there a way to interface with the microcontroller (the the goal of communication with an Xbee module) on this FEZCerbuioBee using a serial link on the PC without buying more hardware? It seems there would be enough functionality on this board to communicate with a PC without getting more hardware.

I need to be able to stream serial data from the Xbee to my PC through this board.

The second code looks like it may work. I have a few more questions before I can compile it.

  1. Am I correct in thinking this is instructing the micro-controller to open it’s serial port on board the FEZCerbuinoBee? I guess I’ll also need to know how to tell this framework to open the serial port on my PC as well. Do you have any examples of this? System.IO.Ports.SerialPort DOES NOT WORK for some reason. nor does Microsoft.SPOT.hardware.serialport or anything else…

  2. in the second code snippet you say that this will open socket ‘U’. Does this mean I still need to buy the second piece of hardware and plug it in before I can get this code to work?

  3. how do you call the ‘Module’ (how do you know what name it has?) which you have in this code generally referenced to as ‘this’



I've attached an image to give a more clear understanding of the libraries i'm referencing as well as where in the code i'm using your example. (this is just a proof of concept, not where the code will live when it is actually being used).

The Code snippet is from the bluetooth Module driver bluetooth.cs for example have a look in my codeshare projects e.g y.a. Bluetooth driver

My code compiles but i’m having trouble actually establishing communication over the USB port on my PC. I currently do not have an XBee connected to the COM1 port. But I don’t think this should matter because i’m just trying to talk to the uC for now. Is this correct?

I’m wondering if there is a conflict with the GHI USB Driver on my PC? When I download this code and open a terminal on my PC nothing happens but I think this is because the GHI driver has already taken the hardware assignment. Do I need to uninstall the GHI driver to communicate with the FEZ Cerbuino Bee (over a serial connection) on my PC? If not how do I tell the GHI Driver not to engage?

Here is my (shamelessly copied) code. It ‘makes it’ to the 7th step in the debug sequenece…:

        // This method is run when the mainboard is powered up or reset.   
        bool state = true;         
        SerialPort xbee = new SerialPort("COM1",9600, Parity.None, 8, StopBits.One);         
           
        void ProgramStarted()
        {
            xbee.Open();
            Debug.Print("Made it here 0");
            xbee.DataReceived += new SerialDataReceivedEventHandler(xbee_DataReceived);
            Debug.Print("Made it here 1");
            GT.Timer timer = new GT.Timer(500);
            Debug.Print("Made it here 2");
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            Debug.Print("Made it here 3");
            timer.Start();         
        }         
        
        void xbee_DataReceived(object sender, SerialDataReceivedEventArgs e)         
        {
            Debug.Print("Made it here 1a");
            Debug.Print(e.ToString());
        }         
        
        void timer_Tick(GT.Timer timer)
        {

            Debug.Print("Made it here 4");    
            state = !state;
            Mainboard.SetDebugLED(state);
            Debug.Print("Made it here 5");    
            
            byte[] openingStatement = Encoding.UTF8.GetBytes("\n\rI am open from COM 1\n\r");
            int read_count = 0;             
            byte[] rx_byte = new byte[1];
            Debug.Print("Made it here 6");
            xbee.Write(openingStatement, 0, openingStatement.Length);
            Debug.Print("Made it here 7");
            
            // read one byte               
            read_count = xbee.Read(rx_byte, 0, 1);
            Debug.Print("Made it here 8");
            if (read_count > 0)// do we have data?                 
            {                     
                // create a string                     
                string counter_string = "I am being Transmitted from the Cerbuino Net over COM 1 \n\n\rYou typed: " + (char)rx_byte[0] + "\r\n";                     // convert the string to bytes                     byte[] buffer = Encoding.UTF8.GetBytes(counter_string);                     // send the bytes on the serial port                     UART.Write(buffer, 0, buffer.Length);                     //wait...                     
                Thread.Sleep(10);
            }

            Debug.Print("Made it here 9");
            byte[] buffer = Encoding.UTF8.GetBytes(DateTime.Now.ToString() + "\r\n");
            Debug.Print("Made it here 10");
            xbee.Write(buffer, 0, buffer.Length);
            Debug.Print(string.Concat("Made it here 11 ", buffer.ToString()));
            xbee.Flush();         
                        
        }

So I’m not quite sure what you expect to achieve if you don’t have an xbee connected, or how you will know it should work. There is no “conflict” of drivers, but I don’t think your expectations of what will happen if you don’t have an XBee connected are meaningful either. To properly use a serial connection between the Cerb and the PC, you need a second connection, as the first USB connection is used as a debug connection - it can’t be both a serial connection and debugging connection at the same time. Read up on USB Client https://www.ghielectronics.com/docs/20/usb-client for more info - although I can’t easily find a “switch USB debugging to COM1” document.

One thing with serial ports is that they can (not always) require data to be transmitted out of the hardware queue before letting you proceed. So perhaps that’s why your app reaches a point and proceeds no further - I personally would just abandon this as a test, it’s not simple for anyone to accurately determine what should occur here, so there’s no need to be worried with the results.

Honestly, the best way to “test” your Fez to PC communication is to get some cheap CP2102 USB to TTL UART connections from ebay like http://www.ebay.com.au/itm/USB-2-0-To-RS232-UART-TTL-COM-Module-Serial-Converter-6Pin-Buildin-in-CP2102-New-/270920605812 and test using that. This allows you to confirm your programming logic works without the wireless headaches. If you have two USB to XBee connectors and two PCs, you can run the XBee connection between the two PCs to prove you have the XBee setup working, and then you can simply migrate one end of the connection to the Fez.

1 Like

Hi Brett,
Thanks for the pointer. I followed the instructions (they were not very clear about what to do with the CDC driver file so I saved it under my windows32\driver directory as well as my C:\Program Files\GHI Electronics\GHI NETMF USB Driver Set\GHI_NETMF_Interface Directory.

Again,the code throws exceptions:‘System.NotSupportedException’ occurred in GHI.Premium.USBClient.dll

I have a feeling that the CDC Is not supported with the FEZ Cerbuino Bee. I think this because of the post below, however it was over a year ago: https://www.ghielectronics.com/community/forum/topic?id=8333&page=1
Can anyone confirm this?

For completeness what I’m trying to do is shown in the image below. You guessed it I would like to configure the XBee over the serial interface. I already can communicate between XBees but the FEZCerbuino is intended to be the central coordinator in the mesh. I’m fairly comfortable with the wireless communications and protocols but it is this serial communication protocol that is really confusing because is it so different for the FEZ Cerbuino Bee.

Sorry, I may have led you astray - Premium is not for Open Source devices like Cerbuino. But the part I wanted you to look at was the part about moving debug to COM1 (the bit I couldn’t clearly find - if @ Jeff@ GHI is reading this, can we have a documentation page for this, or make it a mandatory section for each device’s developer page ?) Actually, can someone confirm the firmware status of USB Client, I’ve seen conflicting info from a few months ago that go against what the cerb family table https://www.ghielectronics.com/docs/46/cerb-family says.

From a driver perspective, you need to install the driver (not copy it anywhere). The install process would normally be - connect device that is in CDC mode, it’ll either find the driver, prompt you to install one, or leave the device without a driver (then you install it through the Device Manager)

1 Like

Hi Brett,

So if I buy this guy: https://www.ghielectronics.com/catalog/product/437 will I be able to interface with the XBee over a serial link? When I plug it into a U or K module on my FEZ Cerbuino Bee, that is… and then send the XBee (attached to socket 1) commands from Putty and get a response (with the assumption that the XBee module is configured correctly to do so.)?

Also is there a list that shows the Premium and Open Source devices?

Thanks,
~Shane

Hi,
no, you should buy this guy: https://www.ghielectronics.com/catalog/product/287
if you do not want to use the usb-serial-device suggested by Brett.
The other one is a red power supply module (all power supply modules are red). It is not allowed, I think, to have more than one power supply modules connected to a board. For the Cerbuino bee power is already supplied over the mini-USB-Port. Open source devices have the OSH –logo (Cerb-family and Hydra) the other actual boards have GHI-premium software:

1 Like

Hi Ro,
That is what I was at first thinking but I eventually want to get this guy: https://www.ghielectronics.com/catalog/product/322
and probably this guy:
https://www.ghielectronics.com/catalog/product/444

and it recommends the red board for the power requirements…Will these other modules still function within the power budget of the mini-USB-port on board?

So lets ask another question - do you have an XBee programming module (XBee Explorer or something I think they’re called). I am trying to grapple with what you’re trying to prove and what you do/don’t have working… In your example you have the Cerbuino Bee and the PC as a single device - which they aren’t, they’re separate. If you can send serial data from your sensor to the PC directly over XBee, then it’s a simple enough step to take the same data on the Cerbuino Bee, and would be a sensible first step. Then, we need to establish how you intend to get data from Cerbuino to PC… that could be something as simple as a USB-to-TTL-UART adapter like I showed, any of the GHI serial modules, a Bluetooth module sending serial data, or even just debug.print statements that you read when debugging (which is what you can do today!)

Hi Brett,

(thanks for all your help here! ;D) Basically I’m just trying to see if all of these electronics talk to each other. I’ve attached a few more block diagrams to help clarify what i’m trying to do. When my second XBee module comes I’m going to want the Cerbuino Bee to coordinate the nodes and the sensor data, format this data into a specific structure then I want it to take that data and send it somewhere else. I also want to program or access any given node from the FEZ Cerbuino. Right now that “somewhere else” is a serial port. When my SIM900 board gets here the “somewhere else” will be to my server. It will need to do even more formatting then formatting and I may add a camera for some image processing as well.

I get get the tutorial on this website working:
Geekswithblogs.net, the End of an Era – Julian Farms (with a few small tweeks)

If I were just messing around with the hardware this would be fine because I can read my sensor data to my PC and be done. Eventually I’d like to have multiple XBees or some variant of zigbee protocol chip-set sending data to one coordinator. The Cerbuino has the horsepower to control and manage all this data (in theory). But the Explorer boards don’t really have what I need to make this happen. I could make any combination of boards manage the data but I also need to look at the overall bandwidth, the end cost and and the expand-ability of the end product. It wouldn’t be very economical to make each user buy a Cerbuino like chip-set for each sensor she wanted to use.

OK, cool, you have a grand idea and a plan to somewhat handle the interactions… no more questions there from me (I’m not an XBee guy, so you’re talking above my pay grade :slight_smile: )

There’s lots of “com” ports in use in all this - perhaps we need to be explicit about what they all are. COM1 on the PC and COM1 on the Cerb are totally different ports, and it’s more random chance than design if you were talking from COM1 on one to COM1 on the other - so lets call them cerb-com1 and pc-com1 for clarity.

So in your first diagram, the “working” scenario is what you have right now, correct? Talking over debug.print you can see the data you want on your device. Your cerbuino works, the xbee on the cerbuino works, and your code that talks to the xbee on the cerb works too. All good so far?

Assuming this is the current state, you open cerb-com1 to talk to the xbee. That then happens to open the channel from the sensor data. So cerb-com1 is only relevant to the xbee, not to anything to talk to the PC - so whatever you tried in the second scenario in that picture will only be changing the cerb–>xbee comms.

I guess there are two other parts of the puzzle you need to sort out. First, you need to move from using the coordinator on the sensor node to using the coordinator on the cerb. That should be a simple change, and it seems to me that you should have enough to work with on that (caveat: I am not an xbee guy :slight_smile: ). The second change is to then move to using API mode not AT mode. I am not an xbee guy, someone else will have to weigh in to help more there ! Out of interest though, have you searched codeplex, I believe there’s a netmf project there that has xbee capability and IIRC it handles API mode.

Then the final part of “getting this working” is to turn the connection between the cerb and the PC from a debugging connection to a truly serial connection. To do that we either need to a) resolve the CDC/USB Client serial capability in the Cerb family firmware, or b) move to an additional module or connection that uses a UART and fronts up a serial port over USB. My personal suggestion is still to use a CP2102 module, but a “more formed” device could be the USB-serial module from GHI https://www.ghielectronics.com/catalog/product/287

Do you intend to turn this into a “solution” that needs to be simple for other people to use, as that might lead you to different pieces that are more “consumer” friendly rather than things that are tinker-er friendly like we’ve talked about so far.

Also I’d investigate the SIM900 module capabilities before you buy it, if you explain what you want to achieve there, people can suggest whether that will or will not be suitable.

Hi,
besides power over the mini-USP you can use at the same time additionally the other power plug of the cerbuino-board. This should be enough I think but you should check the specifications. Anyway the USB-Serial SP Module is no alternative. If you think of a wireless connection to the PC you should also think about using the Bluetooth-Module.
https://www.ghielectronics.com/catalog/product/312
From my codeshare project
https://www.ghielectronics.com/community/codeshare/entry/823
you can extract everthing you need for the wireless serial communication between PC and Cerbuino. The application is tested to run on the Cerbuino (little modifications) as well. I do not know if there are stable applications for serial communication over WiFi or the Cellular Radio Module

@ Brett:

yes to both of your questions here.

Yes, this is really easy to do in XTCU

I ordered one of these guys: https://www.ghielectronics.com/catalog/product/287 to speed up development. It would be good to know if the Cerb family can provide a USB client…… :slight_smile:

What i’m working on now is a prototype to so functionality it will need to be a solution; it doesn’t have to be very user friendly at this point. It just needs to provide the sensor data along the right communication path. I am planning on spinning my own board for the final product to reduce cost, part count ect…but when I do that it will require minimal user interaction.

I’ll start another thread on the SIM900 chip.

So here’s what I am thinking.

If you can use debug.print to get the values you need, in all the xbee scenarios/configurations you need, then you only need a different “channel” to get the data to the PC. Your USB-Serial module will do that for you, for sure, and still allows you to do debugging over the serial line so it’s perfect.

Hi Brett,
It is a workable solution and I can supplement the Serial.Write() function with the debug.print() function until the module gets here. …thanks again for your help.
~Shane