Need pin with analog input and output

Hello. I am planning a little handheld device that reads and acts like LEGO NXT sensors. I think that I have everything worked out, except for the analog I/O. I need to have the input and output pins be the same to maintain i2c support, but then the analog pins wouldn't be able to use PWM to output analog. So here's my question. Is there any way to have PWM and Analog I/O on the same pin? If not, is there a way to digitally switch the wire to go to a different pin without changing the currency? (So like a transistor but not merging the voltages) I would then send the extra power to ground. Any help solving this puzzling problem would be greatly appreciated! :slight_smile:

Oops. My post didn't make much sense, after all. Okay. The nxt sensor has a power supply, a set of i2c cables and a set of analog wires. Now, I want a way to be able to either act as a slave i2c device, act as a master i2c device, supply poer and read analog, or ground power and give analog, based on user input. I've got use input down, but I need a way of switching between those functions. Note that only one of these functions will be utilized at any given time and I am fine with a bit of delay between them. Obviously being an i2c master and switching to a slave is easy. Reading analog is easy, and outputting with PWM is easy, but being able to switch between analog input and PWM output is where I'm stuck. Software based PWM is out of the wuestion because I need to read user input when not switching between modes, so I need a way to redirect the analog wire to either an analog in pin or a PWM pin. Also, I need to do this without modifying the voltage that is running through the wire, because I need to accurately read the voltage. Hope this clarifies things a bit. :slight_smile:

P.S. I'm stuck on Internet Explorer right now, so please excuse my spelling. I'm used to Firefox. :-[

Ok. I'll try to explain this again. There is another robot called an nxt. It connects to sensors using 6-wire cables. To connect to these sensors, it supplies 4.5 volts, and a ground. Now, there are two ways of communication. One way it reads some sensors is by analog feedback over 2 wires. The other way is through the i2c bus on another 2 wires, for a total of 6 wires.

Now, I am trying to make a device that can either read these sensors OR act like them, depending on user input. This has to use the same port for the sensor to connect to, because there is only one set of i2c ports. Now, siwtching between 4.5 volts and grounding the 4.5 volts is an easy task, and the reverse is true as well, so I know how to handle the i2c, and the power.

Now, all I am stuck on is the 2 analog I/O wires. I need my device to EITHER read those signals OR emit analog signals, depending on user input. The problem arises with switching between them. I need some way to read analog from the two wires, and then switch to outputting analog signals to the two wires. I am rather sure that this will require something similar to a transistor, but the transistor merges the voltages, and for accurate analog signal, I must keep the voltages on the lines the same during this operation.

Schematics and documentation of the nxt hardware is available here: under hardware development kit. This should clarify what some of this means.

Maybe, depends on what you mean. If you mean, can you switch some node between analog input and analog output, then yes. But, of course it can be only input or only output, never both at the same time. And you must have some way to tell it when to switch.

This is exactly what I need. How would I do this? :slight_smile:

I guess it baisically means switching between using an analog pin and a PWM pin for the node?

Perfect! That is exactly what I need. Of course, since I want to switch between two wires, I think that a SPDT relay is what I'm looking for. That is my main problem that I'm looking to solve. Now, I still have a second problem. Sensors for the nxt are usually an integrated circuit, and draw power from the nxt microprocessor. Of course, Mine must have its own power source to support the sensors when it is in a read mode. So here is my second question. If the nxt supplies 4.5 volts of power, and expects some power to come back to its ground wire, could I just ground the 4.5 volts and send back 5v from the arduino board?

So when I am the master device, I will supply a ground (EASY) and 5v. (EASY) These will be through digital pins 2 and 4. Now, when I am the slave, I basically want to ignore these, because I have my own power, but just leaving them loose would make the master device angry at me. Would it work to just gorund the incoming voltage and supply 5v to the ground? (With a few resistors, of course)

Here's the schematic of my design so far, without any safety resistors.

The hardware documentation is a bit sparse. Maybe the best thing to do would be to just test it with all three wires connected to ground through a 10k. If that doesn't work, then we can start blowing stuff up?

See if you can read what the device is doing or look up the NXT part number or name online and see if anyone else has reverse engineered it.

You can set an arduino analog pin to be analog, or it can be a digital input or output.

The PWM pins are separate and they can be a PWM output or a digital input or obviously they can be a ordinary digital output.

If you have to have pwm out, analog in, digital out, digital in on the same wire then you will need some sort of relay as richard said. The relay can be driven by a different I/O pin that drives a transistor as is documented in the playground.

Your arduino code would tell what pin to do what and when whether it's just responding to an I2C command, responding to an I2C slave, external digital or analog I/O, serial port communication, or other condition.

Yeah. The hardware docs explain just about everything, but they don't say exactly what has to happen with the power. I do know the part numbers and such, and the i2c will come in time. Now, I haven't gotten my arduino board yet, so I can't do much more until I get it, besides speculating on how it will work. Thanks for all of the help!