Simultaneous or alternating use of USB and TWI bus

I have a little hobby project in which I will use some µC to realize some “house management” functions, as triggering house light and eventually open a door :smiley:
The µC should collect some statistical data which can be read from a PC.

I imagine that I have some devices (sensors and triggers, maybe an EEPROM for data acquisition) connected via the TWI bus which is controlled by the Arduino. If I want to retrieve the statistics data from the Arduino I just plug in the PC via USB and load it down – but w/o reprogramming the Arduino all the time.

As I read in the documentation it is not possible to use USB and TWI at the same time. So I have a scenario in mind:

When the PC connects to the Arduino via USB the Arduino is resetted, so I have a good point to start. Is it possible to detect a USB connection? If I can detect it, I can switch between a “house management” path and a “PC interface” path in the program.
To not interfere with the TWI bus in the “PC interface” path I could use a signal on some I/O pin to disconnect the TWI bus from the Arduino with a little “hardware solution”.
Is it possible to reset the Arduino using software? So it would be possible to reset the board and switch back to the “house management” path. Or even simpler … Is it possible to disable the USB port?

So I’m curious if the Arduino can handle this.

Bewalticus

As I read in the documentation it is not possible to use USB and TWI at the same time.

eh?

I think you’ve misunderstood something, as I use SPI and I2C and rs232 simultaneously in my most recent project. (RS232 is attached to the FTDI USB/rs232 adapter on the USB Arduinos.)

TWI = I2C. Atmel uses the name TWI because the name I2C is trademarked by someone else.

Now, you may have a problem with the most recent generation of the Arduino USB, becasue it has some automatic reset functions that could cause an undesirable reset when you fire up RS232 communications, but if I read things corrctly removing a cap or a resistor will disable that functionality.

-j

Thanks quick response!

I think you’ve misunderstood something, as I use SPI and I2C and rs232 simultaneously in my most recent project.

So it isn’t right that both, the Serial functions and the TWI functions, are using the TX and RX lines? If so, how do you circumvent possible signal collissions?

So it isn’t right that both, the Serial functions and the TWI functions, are using the TX and RX lines?

Nope. rs232 uses Arduino pins 0 and 1. TWI / I2C uses a couple of the analog pins, but I don’t recall which off the top of my head.

-j

TWI / I2C uses a couple of the analog pins, but I don’t recall which off the top of my head.

You’re sooo right. I found an article at http://www.windmeadow.com/node/42 about working with I²C. The analogue pins 4 and 5 are used.

Thanks!