rampage128 / niscan

nissan canbus interface for arduino uno
18 stars 8 forks source link

*Question* USB OTG #3

Open radensb opened 5 years ago

radensb commented 5 years ago

@rampage128 In the INO file, there is code that defines pin 3 as an output and sets it high in the setup(). // pin3 set to high for USB-OTG pinMode(3, OUTPUT); digitalWrite(3, HIGH);

The comment above it states that this is for USB OTG. This is the only mention of USB OTG I have seen in this project. Can you elaborate on what this signal is for? All of the USB OTG wiring diagrams show that the OTG adapters ground the sense pin (which I initially thought this was for), so setting it high adds more confusion with regards as to what it is for. Couldn't one just use an OTG adapter or is there special wiring going on using pin 3? Thanks!

rampage128 commented 5 years ago

In my setup, I use an opto-coupler to close the OTG loop. The issue is that devices are all very unique in how they handle the OTG detection. Besides the various voltages used, some devices require to connect the ID-Pin to the own ground pin in order for it to work properly.

The board I am using currently is this one: https://easyeda.com/rampage-128/carduino-v2 There you can see the component U5 (EL817C-F) to get some more insight into how that works.

Please note, that this board is designed for a newer version of the arduino firmware: https://github.com/rampage128/carduino/tree/library-preparation

That project is currently a working sketch, but will soon be a library used by this sketch. The pin layout and functionality of the sketch is quite different there.

radensb commented 5 years ago

Thanks for the quick reply. I now understand what you are doing with the opto-coupler which clears up the question of what D3 was doing. However, it appears that you are not isolating the ground from the "tablet" and the car, so the opto is actually just completing a ground loop to the same ground as the board? Also, the code is currently enabling it as part of the startup. Is there any difference in this compared to a hard wired OTG adapter in this case? Or is this just in place should it be needed to control OTG enable timing should a specific device need it?

rampage128 commented 5 years ago

The tablet I use is a bit special. It has a separate charging port. I did not connect the +5V and GND of the micro USB port to the PCB. Also for my tablet connecting the ID pin to common ground did not work for some reason.

There was also another issue with that specific tablet: When a generic OTG-adapter is connected to this tablet, it drains about 2-5% of battery per hour. Even when only the adapter is connected without any usb device. This resulted in draining the tablet battery over night, when the car was turned off.

I ended up using a micro usb extension cord instead of an OTG-adapter, so I could wire up the ID pin to the opto-coupler. That way the battery isn't drained over night. A nice side effect is that these extension cords are cheaper too.

Also important is the resistor between ID and GND. I tested 4 different tablets. All of them needed different values for the resistor to allow simultaneous OTG and charging.