Xbee (802.15.4) with Sharp GP2D12 Analog Sensor and BS2
kvvanbure
Posts: 7
My goal is to use the Sharp GP2D12 Analog Sensor connected to the Xbee (802.15.4) to transmit the analog signal to another Xbee (802.15.4). From there the signal will be passed through an ADC0831 and then to the stamp to output the distance as measured from the sensor. So far I've been able to get the ADC and Sharp sensor working together using the following code supplied in the data sheet. Was also able to loop back info using the following code for the Xbee:
My question is. Is it possible to transmit the signal as analog, receive it, pass it though the ADC, and then read it on the stamp? Is there any extra coding that needs to be done in order to get the analog signal transmitted? So far the attempt to get this to work is it use the analog output of the sensor connected to pin 20 of the transmitting Xbee with Vref connected to 3.3V. The receiving Xbee is on the breadboard on the Basic Stamp board of education. Pin 20 of the receiving Xbee is then connected to the V+ pin of the ADC and the output of the ADC is then connected to pin 13 of the stamp and then read by the program linked above.
Any help on this would be greatly appreciated.
Thanks in advance.
' {$STAMP BS2} ' {$PBASIC 2.5} ' Requires remote XBee in loopback mode (DIN connected to DOUT) Baud CON 84 ' 9600 baud non-inverted Rx PIN 15 ' XBee DOUT Tx PIN 14 ' XBee DIN temp VAR Byte ' Temporary variable PAUSE 500 ' 1/2 second pause to stabilize DO DEBUG CLS, "Type a character: " ' Prompt for character DEBUGIN temp ' Catch user response SEROUT Tx, Baud, [temp] ' Send to transmitting XBee SERIN Rx, Baud, [temp] ' Get echo from receiving XBee SEROUT 16, Baud, [CR, "You entered: " , temp] ' Display result PAUSE 1500 ' Wait 1-1/2 seconds LOOP
My question is. Is it possible to transmit the signal as analog, receive it, pass it though the ADC, and then read it on the stamp? Is there any extra coding that needs to be done in order to get the analog signal transmitted? So far the attempt to get this to work is it use the analog output of the sensor connected to pin 20 of the transmitting Xbee with Vref connected to 3.3V. The receiving Xbee is on the breadboard on the Basic Stamp board of education. Pin 20 of the receiving Xbee is then connected to the V+ pin of the ADC and the output of the ADC is then connected to pin 13 of the stamp and then read by the program linked above.
Any help on this would be greatly appreciated.
Thanks in advance.
Comments
I guess if that's not possible I'd like to pass the signal through the ADC before inputting it into the Xbee and then transmitting it to the receiver on the basic stamp. The real problem I'm having is that I can't get a signal transmitted to the receiver to output to the basic stamp.
I'm pretty sure that's a no.
I think it's possible to use the XBee as your ADC and have it transmit the readings directly.
I haven't ever used the XBee's ADC pins myself, but it looks like the manual covers how to do it. IIRC, only the "Pro" versions of the XBees can to this ADC themselves (at least that's what I thought the manual said).
I'm pretty sure some of the other forum members have used the XBee's ADC feature. Hopefully they'll chime in to help you out.
On the analog input side, need AT commands:
MY 1 ' my network address
DL 2 ' destination XB network address
D0 2 ' configures pin 20 as an analog input
IL 3E8 ' sample at one second intervals
On the PWM output side, the AT commands:
MY 2 ' my network address
DL 1 ' destination XB network address, if necessary
P0 2 ' configure pin 20 as PWM output, will update once per second.
IA 1 ' to enable line passing from MY=1
There are other settings that could affect that. For example, if the analog input side is using a sleep mode, the XBee can be configured to transmit an update whenever it wakes.
But, why do you want to convert back to analog, then to an ADC, and then to the Stamp? Why not just have the XBee send the data in digital form directly to the Stamp?
My attempt at sending and receiving the digital signal is to input the digital signal from the ADC to the DIN input of the transmitting Xbee. Then connect the DOUT pin on the receiving Xbee to pin 13 on the stamp to read the distance from the sensor. So far this doesn't work and I'm a little stumped on what to try from here.
Din (pin2) and Dout (pin3) are for transmission of RS232 data (3 volt levels). One scenario is:
Sharp---ADC---Basic.Stamp---Din.XBee- - - - - -XBee.Dout---BASIC.Stamp---Display
You see, that requires two BASIC Stamps, because the ADC can't talk directly to the XBee. On the other hand, if your assignment allows you to use the ADC that is built into the XBee, then it becomes simpler:
Sharp---ADC.XBee- - - - - -XBee.Dout---BASIC.Stamp---Display
The transmitting XBee is set up with the command
ATD0 2
to enable the XBee ADC on pin 20. The data in digital form comes out on pin3 of the other XBee, and the Stamp reads the data and formats it for display.
Please diagram what is expected for your assignment.
Requirements – The system must meet the following requirements:
- use two or more external devices (e.g., sensors, actuators, or interfaces)
- use the Basic Stamp board
- use one AD0831, 8-bit analog-to-digital converter (A/D converter or ADC)
Our original block diagram is shown below and we planned on driving the clock of the ADC with a 555 timer (page 11).It would be ideal if we could incorporate the ADC in some way. At this point just getting the stamp to output the distance as measured from the sensor would be nice. Also listed below are the parts we currently have.
(2) Xbee 802.15.4
(1) BS2 and USB board of education
(1) Sharp IR Sensor
ADC0831
(1) Xbee breakout adapter board (to convert pin alignment to fit on breadboard)
(1) Xbee 5/3.3V breakout adapter board (provides 3.3V power for Xbee from 5V source and converts pin alignment to fit on breadboard)
However, you would need a level inverter to go from the XBee directly into the PC.
That's the other problem we've run into. We don't have the adapter to interface the Xbee with the pc. I'm assuming this is the level inverter you are referring to?
It looks like the best option for us then is going to be to use the on-board ADC on the Xbee. I think we can work around having to use the external ADC.
Since you have the parts, and this is all about learning, you might as well also get the ADC0831 ADC working directly with the Stamp--PC, to read the Sharp sensor without the XBee link. Good to know!
Transmitter side:
Xbee on sparkfun breakout board
Sharp analog IR sensor -> AD0 (pin 20) on transmitter.
Vcc (pin 1) connected to 3.3V power
Vref (pin 14) connected to 2.3 V power (through voltage divider from pin 1)
Gnd (pin 10) connected to gnd
Receiver side:
Xbee on 5V/3.3V adapter board from Parallax
Pins 1 and 10 connected to gnd
Dout (pin 3) connected to pin P12 on BS2
Pin 11 connected to 5V power
My attempt at modifying the code for the ADC to work with the built in ADC of the Xbee is shown below. I know this isn't right because it still uses P13 in the code which won't be connected in the working product (P13 is the analog input connected to the stamp for testing).