Xbee visual basic

hi,

i need visual basic 2010 express code to control xbee io pins.

i have two xbees one connected via usb cable to my computer and the other one is supply via a 3.3V battry and has an led connected through the pin 20.

i need a code that sends data to switch the led on and off

i tried this code but its not working.

SerialPort1.Write (“20, 4”) ’ suppose to switch on the led
SerialPort1.Write (“20, 5”) ’ suppose to switch off the led

if the code i wrote is good then maybe its the config of the xbee which is wrong.

what shoud the D0 (pin 20 ) be ; high, low, enable…?

thanks for helping me out

maybe i have wrongly configure the xbee through x-ctu.

does DO0 should be High for the receiver and low for the transmitter??

If I understand correctly you’re trying to control a LED on a remote XBee by sending commands to the local XBee that’s directly connected to your computer.

As a suggestion, start with a simpler case. Connect a LED to an output pin of the local XBee and check that you can control that. The AT commands will be “ATD0=4” and “ATD0=5” if you have the LED connected to DIO line 0.

I’ve never used visual basic so I don’t know what SerialPort1.Write does, but if it does what it looks like then you’re sending the 5-character string ‘20, 5’. The XBee will have no idea what to do with that.

To control a LED on a remote XBee you’ll need to learn about API packets.

The Digi product manual has all the details you need. Optionally, you might also want to look at my cookbook (see pinned posts at the top of the forum).

hi john,

i tried what you told me but still it’s not working.

am wondering maybe the xbees are wrongly configured in the x-ctu.

can you please tell me the correct configuration for the I/O setting?

thanks

First, I assume your LED has 1 pin tied to 3.3vdc, and the other tied to pin 20? Plus some form of step-down resister?

The XBee can only ‘power’ the LED by pulling low (the ATD0=5) command.

By default writing ‘ATD0=5’ will cause that string to be sent to the remote, who will dump it out the serial port. If you use the ‘+++’ first, then you can toggle the pin 20/D0 on the local XBee, but not the remote.

As John mentioned, API frames will be required with the Remote AT Command Request (frame type 0x17).

hi lynnl,

even i thought the same but it’s actually working. i dont know how but its working while using the ‘+++’ and wont if i dont.

well i have to enter in command by typing the ‘+++’, wait for the ‘OK’, then type ‘ATD04’ and ATCN to exit the command for the LED to light up.
to switch off the LED i need to re-enter the command ‘+++’ , ’ ATD05’ and ‘ATCN’
here’s the code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim data(2) As Byte
    'System.Threading.Thread.Sleep(1900)
    SerialPort1.Write("+++")
    System.Threading.Thread.Sleep(2000)
    SerialPort1.Write(vbCrLf)
    SerialPort1.Write("ATD04" & vbCrLf)
    System.Threading.Thread.Sleep(900)
    SerialPort1.Write("ATCN" & vbCrLf)


End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim data(2) As Byte

    'System.Threading.Thread.Sleep(1900)
    SerialPort1.Write("+++")
    System.Threading.Thread.Sleep(2000)
    SerialPort1.Write(vbCrLf)
    SerialPort1.Write("ATD05" & vbCrLf)
    System.Threading.Thread.Sleep(900)
    SerialPort1.Write("ATCN" & vbCrLf)

End Sub

End Class

by the way i need to monitor voltages across a pin of the xbee which will be sent to the coordinator.

i believe that i should use the DI05 pins for ADC, what’s the maximun input voltage should i use. what the command i should type in the coordinator xbee to read those voltages?

thanks

hi,

thats exactly what am thinking.

can you please help me with the configuration?