RS-232 to RS-485 converter
Posted: 16 Oct 2010, 20:34
First, I know that 5V communication levels really don't count as RS-232, sorry .
Second, a bit of an idea of what I'm trying to do. I'm wanting to create something that is somewhat similar to the Mindsensors PSP-NX but using Picaxe microcontrollers on both ends, on the hacked game controller and one on the robot, acting as a go-between. My idea is to have a Picaxe 20X2 (my favorite Picaxe by the way) reading the joysticks (potentiometers) and buttons in the game controller and then sending them wirelessly over the SparkFun 315 Mhz 4800 baud RX/TX pair (woah, long mouthfull) to a receiving 20X2 (or 18M2) on the robot that will interpret values, toss out bad bytes and then send them on over to the NXT. The second 20X2 would also be able to control servos, motors and maybe do some basic navigation/triangulation using IR and a compass.
Third, my problem. Originally I was planning to communicate between the Picaxe and the NXT using the Picaxe as a I2C slave. The Picaxe would write some values to its scratchpad and then the NXT would read those values as it would read a I2C EEPROM. However, after a bit of research I found out the the scratchpad's memory would wear out after about 100,000+ writes (or about 170+ hours at 10 updates a second). I thought, for a little bit more $$ why not stick a I2C RAM or a serial to RS-485 converter in there and making it something that'd last for a good deal longer? I figured that the 485 converter route would be the simpler way to go, even if I had to learn another language (I'm thinking about NXC) to do so.
Fourth, the question (Finally!!! I hear you say). Now, it comes down to finding the right converter to plop in-between the Picaxe and my precious NXT. I first found the SparkFun SP3485 breakout. However, $10 US is too much to spend, I think. I could get two MAX485s for that price. Which brings me to my next option. After a bit of searching (yes, I did do the mandatory Google search ) I found this blog post about connecting a NXT and an Arduino over 485 using a MAX485 chip. I'm pretty sure that I could just substitute a Picaxe (or a FTDI chip so I could talk to the computer!) for the Arduino, write some code and begin talking. However, I'm cheap. I'd rather spend $1 dollar than $5 most times, even if it means a bit of extra work.
Ok, another option. I found a link on the SparkFun converter page to a tutorial that pointed out that the SN75176 chip is pretty much the same as the MAX485 but a lot cheaper (~$1 VS ~$4 dollars). Disadvantages are that it has a higher power consumption; advantages are that it that it can handle higher communication speeds. I don't think I'm worried about too much about a extra couple mA of power being used and even though the 20X2 can handle serial speeds up to 115,200 baud (with overclocking) I don't think I need to get up that high. 4800/9600 would work to begin with, might bump it up later if I'm desperate for more speed.
Last option that I've considered. The DS485 was mentioned as NI's substitute for the MAX485. If the SN75176 just doesn't cut it I could get it instead as it runs at about ~$3 dollars. It actually seems to be superior to the MAX485; long distance industrial designs seem to prefer them as they (supposedly) have more built in protection against over-voltage and ESD.
Fifth, software. RS-485 only defines the voltage levels and such, no protocol is defined like when using RS-232 or I2C. According to all the tutorials ect. that I have read, I would need to create my own protocol. Now, I wouldn't mind doing that as it might be rather fun and all but I'm wondering what I have to work with on the NXT end. Is there any kind of protocol defined? If not, how hard would it be to write my own? Something like a 2-10 byte message containing power levels for both drive motors, information coming from the IR beacons so that I could do some triangulation/location calculations, amount of dropped messages coming from the controller (IE, coded safety tether) and maybe some other info (ideas anyone?). Another limitation I have to work with is memory space. The 20X2 has 2048 bytes of program space, along with the ability to load programs from an external I2C EEPROM. I would want to reserve at least half that for general use, the other half (or preferably less) I could use for the protocol. I have been thinking it might be easier to just create a 232 like protocol on the NXT, enabling me to use existing commands on the 20X2, opening up a lot more space for other things. I'm not sure if this would work, although, I don't know anything about existing protocols on the NXT.
To sum it all up. What chip do you recommend I use? What kind of protocol does the NXT use for the 485 port? Would it be possible to work with existing 232 protocols so that I don't have to bother with software quite as much on the Picaxe end? Is there any existing work out there that I might find interesting? Thanks for actually reading all of this very long post, I hope it didn't end up too long. I'm very open to suggestions right now, suggestions about pretty much anything that this project involves. Thanks!
Second, a bit of an idea of what I'm trying to do. I'm wanting to create something that is somewhat similar to the Mindsensors PSP-NX but using Picaxe microcontrollers on both ends, on the hacked game controller and one on the robot, acting as a go-between. My idea is to have a Picaxe 20X2 (my favorite Picaxe by the way) reading the joysticks (potentiometers) and buttons in the game controller and then sending them wirelessly over the SparkFun 315 Mhz 4800 baud RX/TX pair (woah, long mouthfull) to a receiving 20X2 (or 18M2) on the robot that will interpret values, toss out bad bytes and then send them on over to the NXT. The second 20X2 would also be able to control servos, motors and maybe do some basic navigation/triangulation using IR and a compass.
Third, my problem. Originally I was planning to communicate between the Picaxe and the NXT using the Picaxe as a I2C slave. The Picaxe would write some values to its scratchpad and then the NXT would read those values as it would read a I2C EEPROM. However, after a bit of research I found out the the scratchpad's memory would wear out after about 100,000+ writes (or about 170+ hours at 10 updates a second). I thought, for a little bit more $$ why not stick a I2C RAM or a serial to RS-485 converter in there and making it something that'd last for a good deal longer? I figured that the 485 converter route would be the simpler way to go, even if I had to learn another language (I'm thinking about NXC) to do so.
Fourth, the question (Finally!!! I hear you say). Now, it comes down to finding the right converter to plop in-between the Picaxe and my precious NXT. I first found the SparkFun SP3485 breakout. However, $10 US is too much to spend, I think. I could get two MAX485s for that price. Which brings me to my next option. After a bit of searching (yes, I did do the mandatory Google search ) I found this blog post about connecting a NXT and an Arduino over 485 using a MAX485 chip. I'm pretty sure that I could just substitute a Picaxe (or a FTDI chip so I could talk to the computer!) for the Arduino, write some code and begin talking. However, I'm cheap. I'd rather spend $1 dollar than $5 most times, even if it means a bit of extra work.
Ok, another option. I found a link on the SparkFun converter page to a tutorial that pointed out that the SN75176 chip is pretty much the same as the MAX485 but a lot cheaper (~$1 VS ~$4 dollars). Disadvantages are that it has a higher power consumption; advantages are that it that it can handle higher communication speeds. I don't think I'm worried about too much about a extra couple mA of power being used and even though the 20X2 can handle serial speeds up to 115,200 baud (with overclocking) I don't think I need to get up that high. 4800/9600 would work to begin with, might bump it up later if I'm desperate for more speed.
Last option that I've considered. The DS485 was mentioned as NI's substitute for the MAX485. If the SN75176 just doesn't cut it I could get it instead as it runs at about ~$3 dollars. It actually seems to be superior to the MAX485; long distance industrial designs seem to prefer them as they (supposedly) have more built in protection against over-voltage and ESD.
Fifth, software. RS-485 only defines the voltage levels and such, no protocol is defined like when using RS-232 or I2C. According to all the tutorials ect. that I have read, I would need to create my own protocol. Now, I wouldn't mind doing that as it might be rather fun and all but I'm wondering what I have to work with on the NXT end. Is there any kind of protocol defined? If not, how hard would it be to write my own? Something like a 2-10 byte message containing power levels for both drive motors, information coming from the IR beacons so that I could do some triangulation/location calculations, amount of dropped messages coming from the controller (IE, coded safety tether) and maybe some other info (ideas anyone?). Another limitation I have to work with is memory space. The 20X2 has 2048 bytes of program space, along with the ability to load programs from an external I2C EEPROM. I would want to reserve at least half that for general use, the other half (or preferably less) I could use for the protocol. I have been thinking it might be easier to just create a 232 like protocol on the NXT, enabling me to use existing commands on the 20X2, opening up a lot more space for other things. I'm not sure if this would work, although, I don't know anything about existing protocols on the NXT.
To sum it all up. What chip do you recommend I use? What kind of protocol does the NXT use for the 485 port? Would it be possible to work with existing 232 protocols so that I don't have to bother with software quite as much on the Picaxe end? Is there any existing work out there that I might find interesting? Thanks for actually reading all of this very long post, I hope it didn't end up too long. I'm very open to suggestions right now, suggestions about pretty much anything that this project involves. Thanks!