Goals
This page will describe how to create Phy2Phy projects with two major goals in mind:
- Cheap - as inexpensive as possible
- Easy - as easy and fast to create as possible
So here we go!
Basic Concept
One problem with connecting remote embedded Ethernet devices is how to get them to meet up on the network. At one time, almost all Internet devices had fixed, static IP addresses, but this is no longer the case. Network Address Translation (NAT), dynamic IPs from DHCP, and firewalls that restrict initiation of incoming connections is the norm.
The best solution I've found it to have a "server-in-the-middle". You rent a dedicated Internet server with a fixed IP address, and have your two DHCP/Firewalled devices connect to that server.
One good server host to look at is All My Data, they have a shared hosting account for $3.95 per month that allows you to run "background processes". For Phy2Phy, this would be a simple script (I like using Python) that accepts connections on a specific port or ports from the two Phy2Phy embedded devices, and then sends them back data to drive the physical actuators.
Here is simple Python code to receive a UDP packet from a Phy2Phy device on port 2078, it prints out the address and the value of the first byte of the packet, then echos the first byte back to the Phy2Phy device using UDP. You can use this basic structure to build out the server to do the communications and computations you need to link the Phy2Phy devices.
from socket import * s=socket(AF_INET,SOCK_DGRAM) s.bind(('',2078)) while 1: [msg,addr]=s.recvfrom(256) p=ord(msg[0]) print addr,p s.sendto(chr(p),addr)
Microcontroller
There are two good solutions for microcontrollers:
Arduino
The Arduino is an open-source electronics prototyping platform that uses flexible, easy-to-use hardware and software. It is based on the Atmel ATmega168 chip.
The Arduino has 6 A/D inputs, and 14 general purpose digital I/O pins (of which 6 can be PWM outputs and two can be a TTL level serial port).
The Arduino is programmed in a very high-level C-like language. It isn't the fastest system, but it should suffice for most Phy2Phy style projects. You have to download a program onto your computer to develop and load the code onto the Arduino.
The standard board is available for $34.95 from Spark Fun. There are other distributors for non-US as well. This board can take power from the USB port, which is nice when you are first programming and testing the system.
Because the Arduino is open source, there are many variants. For example, you can purchase a "Bare Bones Board" kit for $15 that has everything except a USB-to-TTL serial cable ($20 from Mouser) which you need to program the Arduino.
The Arduino has the concept of a "shield". These are PC boards you stack on top of the Arduino "PC/104 style". Here is a list of some shields.
Comfile CUBLOC CB220
The Comfile CUBLOC CB220 is programmed in a BASIC much like the BASIC Stamp, and it runs very fast (36,000 instructions per second). Like the Arduino, you have to run a special program onto your computer to develop and load the code onto the CUBLOC.
Since it is based on the same chip as the Arduino (the Atmel ATmega168), the pinout capability is very similar. The CB220 has 16 digital I/O lines, 8 10-bit A/Ds, 3 PWMs, and 2 serial ports (one RS-232, one TTL). If you need more digital I/O lines, you can move up to the CB280 (49 I/Os, 6 PWMs), the CB290 (91 I/Os, 6 PWMs), or the CB405 (64 I/O and 12 PWMs).
The CUBLOC CB220 is $34 from Comfile. You may also want the nice Proto Board for $5.
IP Connectivity
Lantronix Xport Direct
The Xports are devices with a serial port and an Ethernet port. You can configure them to take bytes in over the serial port, and send them over IP using Ethernet. Also incoming IP packets over Ethernet are turned into bytes sent out the serial port.
You can flash an Xport to communicate serial data to a single fixed external IP address (the easy way to do it), or you can use "Hayes like" commands over serial to "dial up" connections to different IP addresses (for more flexibility). Communication can either be TCP or UDP. The IP address of the Xport itself can be dynamic using DHCP or you can set it to a static IP.
The Xport Direct is the cheapest Xport. It takes up more room than the "classic" Xport, and also its pins are a troublesome 2mm pitch (not the standard protoboard/breadboard 0.1 in = 2.54mm pitch). It works up to 231 kbps.
The Xport Direct can be found for $28 at GridConnect or $29.95 at Mouser.
You can purchase a Arduino Xport Shield for $15 from Adafruit. And NKC sells Xport Direct breadboard adapters. This is useful since the Xport Direct uses 2mm pitch pins.
The Xport Direct has 2 digital I/Os pins available directly on-board. A very simple Phy2Phy project may just need an Xport and not even need a microcontroller.
Lantronix Xport
The "classic" Xport has a very small form factor, and has a standard RJ-45 connector pin footprint. It works up to 921.6 kbps.
The Xport can be found for $49.95 at Gridconnect or $52 at Mouser.
A useful board is the Comfile Xport Dongle ($8) which allows you to hook the Xport right up to RS-232 level serial over a DB-9 connector (the Dongle has a MAX232 to convert the RS-232 level to TTL level so you don't burn out your Xport). You have to provide 5V on pin 9 of the DB-9 to power the Dongle and the Xport.
The Xport has 3 digital I/O pins.
Lantronix also has other devices such as the MatchPort that convert between serial and 802.11 b/g wireless networking, but they cost much more than the wired Ethernet Xports.
Note on TCP/IP Stacks for Microcontrollers
I used to be a big believer in developing assembly language on PIC microcontrollers. As a result, I purchased some PIC-based systems that came with a TCP/IP stack. I had two major problems with them. First of all, the stacks didn't always properly DHCP both an IP address and a gateway router. Second, yes you might have the code available to you in C, but C on a PIC is practially assembly language with braces. It is a pain to follow. Frankly, I'm over assembly and C development on microcontrollers, because I don't need the speed for art projects right now.
If you really want to try a TCP/IP stack on a PIC or Atmel chip, go ahead, but I'm convinced that the amount of time you spend effort on that will cost you more than the price of a Lantronix Xport, which has served me well 100% of the time.
On the other hand, you could go with a full Linux system on an AVR like the ATNGW100 Network Gateway Kit that has two Ethernet NICs (~$89 from DigiKey). But then you'd have to work out how to do general digi I/O and A/D etc.
Servos
Servos are generally priced by torque, speed, and size. You can get a feeling for the range here. Torque runs from 12 ounce/inches for the smallest, weakest servos to 200 ounce-inches or more.
Probably the cheapest servo you can purchase is the Futaba S3003 ($9.89 from Tower Hobbies). It provides around 50 ounce-inches of torque.
Servo Power Gearboxes can ramp a servo up to 2,000 ounce-inches of torque (at the expense of speed though). Meanwhile, this Dynam servo is only $6.34 and has just 20 ounce-inches of torque.
Budget Example
Here is a budget example for the microcontroller and IP interface for two sides of a typical Phy2Phy project:
Item | Number | Unit Price | Extended Price |
Arduino "Bare Bones Board" Kit | 2 | $15 | $30 |
USB-to-TTL serial cable | 1 | $20 | $20 |
Lantronix Xport Direct | 2 | $28 | $56 |
AdaFruit Xport Shield | 2 | $15 | $30 |
Total: | $136 |
Servos and other actuators extra, of course.