Beginner's Cerbuino Bee questions about XBee integration among other things

Hi,

I’m new to the microprocessor world, so forgive me if these are dumb questions. I am running a brand new Cerbuino Bee and I have updated the firmware and I am running version 4.2 of the SDK and micro framework.

  1. I have a XBee module plugged directly into the XBee port of my Cerbuino Bee. What socket number do I need to pass into the constructor of the Gadgeteer.Modules.GHIElectronics.XBee class? And where could I have gone to find this information myself?

  2. I have a couple of button modules attached and I am using the Gadgeteer.Modules.GHIElectronics.Button class, but the ButtonPressed events are not firing. I assume there needs to be a watcher process in another thread that fires these events? If so, where is the code to start such a thread? BTW, the LEDs on the buttons work fine.

  3. Can I also send and receive data via the USB cable? If so, where can I find a code example for the Cerbuino-side code as well as the code for the Windows client app that would talk to it?

Thanks,
Scott

The class you are using was designed to work with Gadgeteer sockets. It only exposes the serial line to you. If all you want is to use the transparent mode in XBee (all data you send to module is broadcasted to other modules and the other way around) i suggest you just use a serial port class and initialize it with ‘COM1’ value. The default baudrate for XBee is 9600. If however you are looking for using full potential of XBee monitor this site: http://xbee.codeplex.com. I have just updated the driver to work with .NET MF 4.2 and tested in on all available 4.2 boards. I will push my weekend changes to repo on monday. In case of CerbuinoBee the XBee socket is not a Gadgeteer socket so you have to initialize the module from code (not thru designer). Regular Gadgeteer modules have one constructor that take the Socket object as argument. Since you can’t inherit from Socket I have added an extra constructor that accepts the serial port name and neccessery pin numbers.

@ Gralin
Hello
I try to use the GBee library with MF4.2,Cerbuino Bee and an XBee serie2 module directly plugged on the Cerbuino board.

First test : My XBee is configured in « Zigbee End Device AT », I try to initialise the communication like this :

XBeeApi.XBee xBee = new XBeeApi.XBee(“COM1”, 9600);
xBee.DataReceived += new XBeeApi.XBee.XBeeDataReceivedEventHandler(xBee_DataReceived);
xBee.Open();

I have this exception :
AT command timed-out while attempt to read configuration. The XBee radio must be in API mode (AP=2) to use with this library

Second test : My XBee is configured in « Zigbee End Device API » with AP=2, I try to initialize the communication like this :
XBeeApi.XBee xBee = new XBeeApi.XBee(“COM1”, 9600);
xBee.DataReceived += new XBeeApi.XBee.XBeeDataReceivedEventHandler(xBee_DataReceived);
xBee.Open();

I have the same exception.

The Gralin answer indicate that it is possible to use the XBee module with transparent mode (AT mode) or with the GBee library.
My question: How to use the XBee module directly plugged on the Cerbuino board in each mode ? How to initialize the communication and how to communicate in each mode ?
Thanks
Christian

There are no dumb questions, only dumb/stupid answers my friend :wink:

@ christian - As Gralin mentioned in his post, the Cerbuino XBee socket is NOT a gadgeteer socket, so if you wnat to use transparent mode, do not use the GBee library, and instead just use COM1 directly.

From Gralin’s post:

If you want to use the GBee library (API mode), Gralin recently added a constructor that accepts a serial port object directly. This means you have to manually add the GBee library reference to your project, and not use the Gadgeteer designer.

We are working on adding code examples to the codeplex site. Also, in the future, please use code tags. It makes reading code on the forum much easier.

@ christian - this works for me on com3 wiring up the xbee to the arduino pins but not when it is in the xbee socket itself…



 static SerialPort xBeePort = new SerialPort("COM3",57600,Parity.None,8,StopBits.One);
        private static Timer _sendTimer;

        public static void Main()
        {
           xBeePort.Open();
           _sendTimer = new Timer(new TimerCallback(SendMessage), null, 1000, 100);
            Thread.Sleep(-1);
        }
        static void SendMessage(object o)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(DateTime.Now.ToString() + "\r\n");
            xBeePort.Write(buffer, 0, buffer.Length);
            xBeePort.Flush();
        }


Cheers
Justin

@ ransomhal and justin - Thanks for yor answers.

@ justin - If I understand the XBee do not run on the socket on the Cerbuino and it is necessary to add a XBee Gadgetter module. It is exact ?

I have only a Cerbuino card and I do not want to buy other Gadgeteer module.
I want to use only this card and add eventualy personal hardware but not Gadgeteer modules.

I have modify my code

[title]Transparent mode[/title]
My XBee is configured in « Zigbee End Device AT »

private GT.Timer m_timer = new GT.Timer(5000);
private SerialPort m_serial;

     void ProgramStarted()
     {
         m_serial = new SerialPort("COM1", 9600);
         m_serial.DataReceived += new SerialDataReceivedEventHandler(On_Serial_DataReceived);
         m_serial.Open();

         m_timer.Tick += new GT.Timer.TickEventHandler(Timer_Tick);
         m_timer.Start();
     }

     void On_Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
     {
         byte[] buffer =  new byte[100];

         int nb = m_serial.Read(buffer, 0, 100);

         Debug.Print("Received Count = "+ nb.ToString() + " - Data =  " + new string(Encoding.UTF8.GetChars(buffer)));
     }

     void Timer_Tick(GT.Timer timer)
     {
         string msg = Hello AT";
         byte[] buffer = Encoding.UTF8.GetBytes(msg);
         m_serial.Write(buffer, 0, buffer.Length);

         Debug.Print("Send Hello AT") 
     }

I send and receive nothing !! I have try “COM3” it is same.

[title]API mode[/title]
My XBee is configured in « Zigbee End Device API » with AP=2

private GT.Timer m_timer = new GT.Timer(5000);
private XBeeApi.XBee m_xBee;

     void ProgramStarted()
     {
         m_xBee = new XBeeApi.XBee("COM1", 9600);
         m_xBee.DataReceived += new XBeeApi.XBee.XBeeDataReceivedEventHandler(On_XBee_DataReceived);
         m_xBee.Open();

         m_timer.Tick += new GT.Timer.TickEventHandler(Timer_Tick);
         m_timer.Start();
     }

     void xBee_DataReceived(XBeeApi.XBee receiver, byte[] data, XBeeApi.XBeeAddress sender)
     {
         m_receivedData = new string(Encoding.UTF8.GetChars(data));

         Debug.Print("Data =" + m_receivedData);
     }

     void Timer_Tick(GT.Timer timer)
     {
         m_xBee.Send("Hello API").ToAll();

         Debug.Print("Send Hello API") 
     }

I have this exception :
AT command timed-out while attempt to read configuration. The XBee radio must be in API mode (AP=2) to use with this library

@ User_8197 - Yes my xbee doesnt work in the socket ( i have asked the lads at GHI about that)…
As a temp workaround i have just wired it up with header pins to the sockets - slight pain due to the smaller pins…
Try m_serial.Flush(); on the send to see if that makes a difference.

@ Christian - are both Xbees on Cerbuinos? If not, what is the second XBee wired to?

No, the XBee should run directly on the Cerbuino Bee on COM1. You should not need a Gadgeteer XBee module. Justin has another thread (http://www.tinyclr.com/forum/topic?id=7507) open with an issue using COM1, so there may be another issue masking your problem. Let’s wait and see how the other thread gets resolved.

In the meantime try using a plain NETMF project and manually adding references to the Cerbuino. Try it in AT mode without the GBee drivers. I will make some time to test this scenario myself in the near future.

@ ransomhall - I use Centruino card and a Digi XBIB-U-DEV3 card on PC side.

Today I have make test in AT mode and I have looked the XBee pins RX and TX with an oscilloscope.

[title]Test1: XBee plugged on Cerbuino slot[/title]
It is not good when the XBee is plugged on the Xbee slot on the Cerbuino card. COM1 used.

Rx is at 0,8v and down to 0v when I send data from my XBIB card.
TX is always at 0v.

[title]Test2: XBee plugged on a Sparfun XBee breakout[/title]
I have make a test with my XBee plugged on a Sparkfun XBee Breakout and only this connection.
Pin1 : 3,3v
Pin2 : RX connected to D1 - PB10 (UART3 RX)
Pin3 : TX connected to D0 - PB11 (UART3 TX)
Pin10 : 0v

COM3 used. It is correct.
RX is at 3.3v and down at 0v when data is received.
TX is at 3.v and down at 0v when data is send.
I send and receive data . It is OK in AT mode.

There is a problem with the XBee plugged in the Cerbuino Xbee slot.
RX and TX pins inverted on the board? Problem with COM1 configuration or initialization?
Signals are not correct.

I have a Cerbuino card revision 1.2

After a few more tests there is defo something wrong with Com1 xbee socket.

Loop back test on Com1 doesn’t work but ok on Com3.

Wiring up the xbee to Com3 works fine but not to Com1 and it’s not a juice supply issue.

As per Aron’s reply on the other xbee thread it will be sorted in the next firmware update.

Has anyone gotten GBeeto work with a Gadgeteer board? I have one plugged into the Cerbuino board (I’ve tried sockets 1 and 2, ex: xbee = new XBee(2))
but still get the timeout. I can plug my XBee into X-ctu and talk to it fine.

@ scoleman2272 - best to start a new thread and give us a link to what a GBeeto might be.

Sorry, I’m referring to the XBee client at http://xbee.codeplex.com/

Ah, it needed some space :slight_smile:

How do you have your XBee(s) configured? The GBee library only supports API mode.

1 Like

switching to API mode fixed the problem. Thanks