Controlling an individual USB PIN (on nano board) via code alone.

I am relatively new to Arduino programming, but am capable of learning most anything quickly when there is a willing teacher. I have SOME level of knowledge where circuits are concerned, but essentially no idea how a serial-to-USB chip operates, how to access its internal structure or "firmware", potential for modification thereof, etc. I know what I am attempting is possible, because frankly anything is possible, so respectfully, I do not need to know any of the reasons that it "can't be done", I have experienced plenty of those. However, if someone would please work with me in determining how it can be done, it would be much appreciated.

Here's a brief explanation, then the question. Thank you.

I have recently undertaken a project that is for me somewhat of an entry into an serious level of programming/electronics, an assistive device geared toward aiding visually challenged individuals in object-detection. The beef of the design itself is nothing new. HC-SR04 ultrasonic range-detector, coupled with an Arduino Nano, as well as a 3.7 Lithium battery (secondary concern, for which I also need to determine the most basic charging circuit - perhaps I have, as now simply soldered to VIN and GND pins, and hoping it charges thoroughly when plugged in to wall charger [thanks]). This will in turn drive a vibrator motor for tactile input, duty cycle for the motor being derived from the HC-SR04 distance data (either some scale of pulses or RMS voltage manipulation through PWM, thus (hopefully) helping someone to construct (mentally) some sort of spatial model of the three-dimensional space around them, though I'm open to suggestions on that one, and THAT is where I have managed to become stumped. My intention is to mount this vibration unit inside a wall-charger, so that the charger can be unplugged from the wall socket, folded up and attached to the ankle or wrist of the device user while remaining plugged in to the arduino's USB port from which I need a usable signal, all without disrupting the devices ability to remain programmable through said port.

Having made it through my verbosity, (and thanks for doing so)... the beef:

How can one idle or unused USB-connector pin be used (without modification to the nano board) to transmit pulsed voltage to a motor (or anything else) housed within a wall-charger's plastic housing via an unused USB pin and cord conductor.

I am hoping to address this from a CODING, rather than hardware approach, and would greatly appreciate any help in achieving the desired result. I realize the programming involved is likely to be over my head, at least for right now, but if I am given some good direction and help, I'm sure I can solve this. For the record, I do plan to open-source this particular project upon it's completion, so maybe it'll help someone else too. Thanks again!

Bill Hawes.

So you want to charge through the usb cable when the wall-wart is plugged in to AC, and manipulate a motor that is also in the wall-wart through the same cable when the wall-wart is being worn?

It can't be done. The USB/Serial controller won't do anything unless it is connected to a USB host. (ok, so you could do it by putting a USB Host (generally a Raspberry Pi class computer) in the wall wart as well, but I don't think that's what you had in mind...)

It would be pretty easy if you had the cable between the wall wart and the Nano use pins OTHER than the USB pins...

That cannot be done on a nano, nor any other AVR-based microcontroller.

The firmware on the dedicated serial adapter ICs (CH340G, FT232, CP2102) cannot be changed. The firmware on the boards with native USB and ones that use a 16u2 as serial adapter, those can be reprogrammed - BUT the chip provides no facility to made the USB pins do anything other than USB functions, so you can't reprogram them to do that.

I couldn't comment on the other ARM-based boards that do native USB - I think some of them will let you do weird things to the USB pins if you turn off the USB functionality? Would have to really study the documentation though.

That's a weird (and likely wrong too, as it violates the USB standard, and could trash the USB host if it tried to do that while it was plugged into something other than your specific thing) thing you're asking to do, and you should not be surprised that it isn't supported on most parts.

westfw:
So you want to charge through the usb cable when the wall-wart is plugged in to AC, and manipulate a motor that is also in the wall-wart through the same cable when the wall-wart is being worn?

It would be pretty easy if you had the cable between the wall wart and the Nano use pins OTHER than the USB pins...

Entirely accurate summation of my intended use. Regarding the suggestion, it's a very good one, and I appreciate it. I may utilize that idea.

But more likely, it seems to have led me to this. There is an inherent benefit in separating the power and programming connectors (and circuits), at least in my mind it is basically a safety feature to NOT have an exposed programming port. So, while this is still an issue I would like to learn to overcome, as anything is in fact possible, my consideration is this... UL, IEEE, ISO, etc would be unlikely to approve of a device that uses USB-type connectors but does not follow established standards. I'm never opposed to bucking convention, but why do so when there's a workaround? Why detach the wall-charger from the unit at all, when I could hard-wire a cord between the two, use as many pins for any reason that is suitable, not worry about losing one of several pieces to a device, using an incorrect or different charger, etc...

However, that restricts addition of alternate feedback periphery. Whereas one user might prefer tactile input, another may wish to interface via aural tones, data-to-speech, etc. Then again, I do plan to open-source my final revision of this device, so those features could be addressed if and when a need arises, and of course I'd be willing to help.

That said, thanks a bunch to DrAzzy and westfw.

I mentioned a secondary concern in the original post, that of a charging circuit. I am at present using an 1800 mAh Lithium cell, soldered directly to VIN and GND. My device has been running for about two days on battery power, though mostly with RST switched to GND, thus pulling (from what I've read) only about 2.5 mA. I feel like I am missing something in that I am sort of just "hoping" the battery will charge in its current position, and I can say that doesn't seem to be the case. The nano, is of course, hooked up to a wall-charger, and I have taken several voltage measurements, none of which have been higher than the previous, so none of this data indicates that any battery-charging is taking place. Have I done something silly such as left out a diode or resistor or something?

Thanks so very much.

  • Bill Hawes

Please post schematic of what you've done.

That description alarms me.

|------ NANO PINS-------|

Intended Vibrator Motor Pin -----> [TX1] [VIN]<-----(CHGR^V+)------------ [B+]

[RX0] [GND]<--------(CHGR^V-)--------- [B-]

|-------- [RST] [RST]

[Reset Switch] |||||| |-------- [GND] [+5V]

|-------- [D02] [0A7]

|------------------> [GND] |----------- [D03] [0A6]
|
| |---------------> [ECH] |------------ [D04] [0A5]
| |
| | |------------> [TRG] |------------ [D05] [0A4]
| | |
| | | |----------> [Vcc] |----------- [D06] [0A3]
| | | |
[HC-SR04 PINS] [D07] [0A2]

[D08] [0A1]

[D09] [0A0]

[D10] [REF]

[D11] [3V3]

[D12] [D13]

This is essentially the setup that I am working on. The GND and Vcc for the HC-SR04 are handled by setting D3 and D6 as OUTPUT pins, writing D6 HIGH, and D3 LOW (to tie it to ground). The nano seems to be able to provide sufficient current to the ranging unit while allowing direct (90° headers) attachment to the nano board.

But I'm still convinced there is SOME way, to handle all this (charging, programming, as well as manipulation of one pin of USB connector) VIA the on-board USB connector. And I think this would be one way of doing so... the CH340G USB-to-UART chip apparently does not support parallel interface via USB bus, as do a few of it's variants. *(intra-statement question: what makes the CH340G different in function from the CH340R, and/or the C340T, which apparently have parallel-output options, which to me signifies the ability to "write" the USB D+ "HIGH" (or "LOW") via/as per programming, for parallel communication? Is there a hardware difference that precludes this possibility in the CH340G? I will investigate further, but I'm sure there's a solution).

Here is, for me, one potential solution to the issue of driving the USB D+ (or D-) pin via Arduino Nano. Let's do a little integral math, from a verbal/pictorial standpoint, and see if a more acceptable solution can be derived. A simple jumper wire from TX1 to the USB connector's D+ contact would allow for signal (and/or power) transmission via this conductor, "up" a USB cord, into the modified wall-charger, as described previously. If I have explained the goal here sufficiently, I think we can agree on that much. For clarity (an example): A jumper-wire from Nano Pin TX1 to USB connector pin D+ (as the D+ conductor is already intended for low-current ~ +5V logic carriage) would allow us to write to D+, by writing to TX1 (also D1, in terms of IDE nomenclature), provided a common ground between wall-charger and nano board (which we have). So...

Our CH340G serial chip has pins (UD+, and UD-) that connect directly to the USB signal lines, according to a translated CH340G datasheet. Also present on the CH340G are pins TXD (UART Data Transmit) and RXD (UART Data Receive). It appears to me, to the best of my understanding, that these pins are for direct coupling to a UART device, in this case the AtMega328p (or in my case, derivative thereof).

Here's the reduction... Now, a jumper between CH340G pins UD+ and TXD, the latter of which is tied to Nano board pin TX1, would solve our problem. This is where my understanding needs to deepen regarding the internal structure of the CH340G, and how an internal bridge can be fabricated, implemented, manufactured, or emulated in such a way as to electrically, if not mechanically, connect Nano TX1 to USB D+ via CH340G pins UD+ and TXD, both of which bear a terminus exactly where we already need them, and with that I need some help. There IS an answer here, and in my opinion, this could lead to some pretty cool projects, so any assistance is certainly appreciated. Thanks a bunch!