I have two XBees hooked to my Pi now, one to control the network I've been building for a long time hooked to the serial port, and the other acting as a controller for my Iris Smart Switch hooked into a USB port. I like the Smart Switch, so I'll be using more of them and that meant I had to figure out a better way to hook two XBees to the Pi and make it work.
I really didn't want to get into the mess of trying to get another standard serial port working because I eventually want LEDs for indicators of things that are important and maybe even a display that I can put words on. Heck, I could decide to put voice on it at some point. So, since the Pi comes with two USB ports, I decided to move both of the XBees to USB. I started out with the USB explorer that I have to program the XBees:
I've had this board a long time and it just works. Never had a problem with it, so I just plugged it into one of the USB ports on the Pi and changed my code to point to it. It worked after a tiny bit of messing around. Now I could control my own stuff and read the Smart Switch as well. That proved that it could be done so I got two of these:
I chose this board so I could use a short USB cable to connect it, avoiding the problem of the bigger board above not fitting. With these plugged into the Pi, I could still control the house and have all my GPIO pins available for whatever else I decide to do someday. But, as usual, there was a problem. See, USB is designed to be plugged and unplugged so you can change devices on the Pi, that unfortunately means that the address of the XBee will change each time you unplug it from the USB port. So, one time I would have the smart switch on /dev/ttyUSB0 and the next time it would show up on /dev/ttyUSB1. Makes coding for it more complex, and I really don't want complex right now.
It turns out that there is another way to connect to it. Under the directory /dev is another directory 'serial'; looking in /dev/serial, I found two other directories by-id and by-path. The by-id directory holds the device ids of the USB to serial chip and that doesn't change as you plug and unplug it. So, I changed my code to define the serial port to this:
XBEEPORT = '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A901QLG3-if00-port0'
Yes, it's long and obscure, but that's what variables and comments are for. It's also hard to type in, but that's what copy and paste are good for. All in all, not a bad way to go as long as I don't reverse which little board I have the XBee plugged into. Remember this little trick when your USB device seems to disappear.
So, now I have all the GPIO pins available; wonder what I'm going to plug into them.
I really didn't want to get into the mess of trying to get another standard serial port working because I eventually want LEDs for indicators of things that are important and maybe even a display that I can put words on. Heck, I could decide to put voice on it at some point. So, since the Pi comes with two USB ports, I decided to move both of the XBees to USB. I started out with the USB explorer that I have to program the XBees:
I've had this board a long time and it just works. Never had a problem with it, so I just plugged it into one of the USB ports on the Pi and changed my code to point to it. It worked after a tiny bit of messing around. Now I could control my own stuff and read the Smart Switch as well. That proved that it could be done so I got two of these:
I chose this board so I could use a short USB cable to connect it, avoiding the problem of the bigger board above not fitting. With these plugged into the Pi, I could still control the house and have all my GPIO pins available for whatever else I decide to do someday. But, as usual, there was a problem. See, USB is designed to be plugged and unplugged so you can change devices on the Pi, that unfortunately means that the address of the XBee will change each time you unplug it from the USB port. So, one time I would have the smart switch on /dev/ttyUSB0 and the next time it would show up on /dev/ttyUSB1. Makes coding for it more complex, and I really don't want complex right now.
It turns out that there is another way to connect to it. Under the directory /dev is another directory 'serial'; looking in /dev/serial, I found two other directories by-id and by-path. The by-id directory holds the device ids of the USB to serial chip and that doesn't change as you plug and unplug it. So, I changed my code to define the serial port to this:
XBEEPORT = '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A901QLG3-if00-port0'
Yes, it's long and obscure, but that's what variables and comments are for. It's also hard to type in, but that's what copy and paste are good for. All in all, not a bad way to go as long as I don't reverse which little board I have the XBee plugged into. Remember this little trick when your USB device seems to disappear.
So, now I have all the GPIO pins available; wonder what I'm going to plug into them.