lofty00

I'm having trouble printing out numerical data from a packet sent over a couple of xbee radios. I have a coordinator which is sending out regular heartbeat broadcast packets, and a receiver which receives these packets and sends back a log packet to show what it's doing. I'm trying to work out why I can't get the log packets to print out correctly over software serial. I've reduced the problem to sending a character string "1234567890ABCDEF" from the receiver, and printing it out either as characters, or as decimal character codes, from the coordinator.

In other words, it's waiting to receive the log packet, and if it doesn't time out waiting, it puts a copy of the pointer to the received packet payload into rxPayload, then goes through storing successive characters in 'test' and printing them out.

Another thing to add to my perplexity is that when I define the character string in the coordinator's code, and print it directly, it works fine both ways...

If anyone has any idea what is going on here, I'd really appreciate it, as I've been stuck on what looked at first sight like a simple problem (sending log packets) for several days now. The only thing I can guess is that it might be due to some compiler optimisation that I don't know about, but I may be wrong.

lofty00

Next time I'll post the whole code - I just wanted to avoid doing that because it's a fairly long program, and the problem was just in printing out the received log packets.

rx is an instance of ZBRxResponse. I know that it's meant to be uint8_t. The first thing I tried was to do the cast at the end, in the usb.print function (I.e. usb.print((char)test); ), but I was trying casting the pointer to see if it worked any better.

The other thing I tried since I posted this was to print 'test' in both formats at once. I.e. using this code:

If I do that, neither the characters nor the numerical values come out right, apart from the first character in the packet.

I have managed to find a workaround for this problem, which is to copy the bytes from the xbee receive buffer into another buffer before printing them. If I do it this way, they will print as characters or decimal ascii codes perfectly well.

lofty00

usb is an instance of SoftwareSerial (from arduino 1.0.1 - i.e. based on NewSoftSerial). The code I have working now is attached to this post. This is different from what I was posting before because I've done some more work this afternoon. xbee_beacon_transmitter.pde is on the coordinator, which is sending out regular (4 second) ticks to the device running xbee_beacon_receiver.pde. The receiver sends back log packets, which is the bit I was stuck on.

The idea of the code is for the receiver to sync its own clock as closely as possible to the clock on the transmitter, in period and phase. This part isn't working fully yet, but at least I can now debug it. The code which sends the heartbeat and log packets is now working fine as far as I can see.

lofty00

I didn't realise that was the way it worked. I've been using a makefile from http://ed.am/dev/make/arduino-mk to build my sketches, so I hadn't noticed that .pde isn't recognised by the new IDE (if that's the case). (Before I switched to this makefile, I was using the one that came with earlier releases of arduino).

I switched to arduino 1.0.1 (from the earlier version that came with ubuntu) because I was wondering if there was a bug in NewSoftSerial that had been fixed in the latest release.