Main Site Documentation

Serial Write() from Cerberus to Arduino via Xbee


#1

I have a simple scenario here, mostly working. I can send data from Arduino to Cerberus no problem, but I can’t seem to get xBee.SerialLine.Write() or even SerialPort.Write() to send any data to the Arduino.

Please take a look, and let me know if you see what I am doing wrong.

Hardware setup:

  • Arduino + Xbee Series 1 as Coordinator wired to TX/RX, hooked to PC with SerialMonitor open
  • Cerberus + Xbee Series 1 as End Device wired to socket 6 hooked to PC for VS debug

The Xbee’s have been properly configured with XCTU as mentioned above, both at 9600 buad. They chat great between two Arduinos, or between Arduino and PC (USB adapter).

The Code:

Super simple hello-world using xBee module (Gadgeteer)


void ProgramStarted()
{
    button.ButtonReleased += button_ButtonReleased;

    xBee.Configure(9600, 
        GT.Interfaces.Serial.SerialParity.None, 
        GT.Interfaces.Serial.SerialStopBits.One, 
        8);
    xBee.SerialLine.Open();
    xBee.SerialLine.DataReceived += SerialLine_DataReceived;
}

void SerialLine_DataReceived(GT.Interfaces.Serial sender, SerialData data)
{
    int recievedData = sender.ReadByte();
    Debug.Print(recievedData.ToString());
}

void button_ButtonReleased(Button sender, Button.ButtonState state)
{
    xBee.SerialLine.Write("booyah");
}

Also tried a super simple hello world using Iggmoe’s SimpleSerial code mentioned here:
https://www.ghielectronics.com/community/forum/topic?id=11336
https://www.ghielectronics.com/community/codeshare/entry/644

Result:
In Arduino’s serial monitor, whatever I type and send will successfully be recieved by Cerberus! If I try to Write from Cerberus, NOTHING makes its way to Arduino.

What the heck? I tried both code paths as mentioned above with exactly the same results. Is there something about netmf Write() that I am just not getting? BTW, I tried writing UTF8 encoded strings as well as a raw byte via WriteByte() just to rule out encoding issues - to no avail.

Ideas are much appreciated!


#2

@ dapug - I assume you have wired a ground between the devices?


#3

Are you talking about the way Xbee is wired to the Arduino? Yes, they are grounded together, and are also using a level shifting adapter (Arduino Uno 5v, to adapter for Xbee 3.3v). As mentioned, RX and TX both work great on this Arduino/Xbee setup - known good. Just that Cerb specifically can’t send to it.


#4
void button_ButtonReleased(Button sender, Button.ButtonState state)
{
    xBee.SerialLine.Write("booyah");
}

void button_ButtonReleased(Button sender, Button.ButtonState state)
{
    xBee.Write("booyah");
}

#5

whelp, GTM.XBee doesn’t have a Write() method there. The only thing available is SerialLine.


#6

Dunno then :slight_smile:

Would only take 2 mins to write it from scratch…


#7

Looking at the xBee driver source i cant see how it would work…


#8

the prob is, how much more “scratch” can I get than System.IO.Ports.SerialPort directly? even that doesn’t work.


        private System.IO.Ports.SerialPort serial;
  
        void ProgramStarted()
        {
            button.ButtonReleased += button_ButtonReleased;

            GT.Socket socket = GT.Socket.GetSocket(6, false, null, "");
            serial = new SerialPort(socket.SerialPortName);
            serial.BaudRate = 9600;
            serial.Parity = Parity.None;
            serial.DataBits = 8;
            serial.StopBits = StopBits.One;
            serial.Open();
            serial.DataReceived += serial_DataReceived;
        }

        void button_ButtonReleased(Button sender, Button.ButtonState state)
        {
            var message = "booyah";
            serial.Write(Encoding.UTF8.GetBytes(message), 0, message.Length);
        }

FWIW, I can see the ASSOC LED on the GT Xbee module flash when it does a write, so it seems something is making it’s way to the module.


#9

if you add a “\r\n” ?


#10

no diff :frowning:


#11

How can you tell from the Arduino’s monitor that the data has been received at the Cerberus?


#12

I can set breakpoints or Debug.Print() on the Cerberus and see the data is received from the Arduino. But Cerberus Send/Write - no love (Arduino sees nothing).

Here is my test:

[ol]Arduino + Xbee Coordinator connected to USB PC, SerialMonitor open
USB Explorer + Xbee End Device connected to USB, XCTU open
Data entered in the XCTU console is received successfully in the Arduino monitor
Data entered in the Arduino monitor is received successfully in the XCTU console
Remove the Xbee End Device from PC and XCTU
Now take the SAME, known-good Xbee End Device, plug into GHI Xbee Module v1.2 and Cerberus v1.2 (note - [em]not[/em] a Cerbuino)
In VS with Cerb connected, run the code as mentioned in this post (SimpleSerial, or GHI xbee driver, whatever)
Data entered in the Arduino monitor (Coodinator) is received successfully by the DataReceived event on the Cerberus (debug breakpoint, or Debug.Print)
Data sent from Cerberus is NOT received by the Arduino Coordinator[/ol]

Given that data IS received by the Arduino coordinator just fine from other devices, my suspect issue is with Cerberus inability to send. I have tried 3 separate code paths: System.IO.Ports.SerialPort, SimpleSerial, and the GHI xbee driver. I have tried Write() and WriteLine() (with \r\n appended).

Is it perhaps my device config? Is Parity.None correct, 8 databits, stopbit One? (<- this is the part where I admit noobness to serial comms :slight_smile: )


#13

Have you tried to put the Cerberus serial port into a loopback, and verify that it is can receive the data that it is sending? You need to make sure that there is not a problem in the Cerberus.

Parity.None , 8 databits, stopbit One is fine as long as both sides are configured the same.


#14

RESOLVED.

Mike, I didn’t actually do a loopback test (not sure how off the top anyway) but I did think to myself, there has to be something totally obvious here…

Resolution: Use Cerb SOCKET 2!

Xbee module v 1.2 lists K and U as compatible sockets. So I had this plugged into socket 6 on the Cerb, which is a U, and thought nothing of it from there out. DANG! Cerberus Socket 2 supports both K and U, so I figured what the heck, and of course, that worked.

So why didn’t socket 6 work? Does xbee require UART H/S as opposed to just UART?


#15

In order for the cobra II board to use xbee module as gadgeteer you needed the extender.