This is not a "Gotcha" question or anything like that. I want to know how I missed the issue the first time around and check my diagnostic skills. I wondered if this is a well known issue which I've not encountered so far. (Note: It is difficult to formulate the question without giving away my answer.)
I encountered this issue after going through the process of assembling the LK Cokoino 4DOF Robot arm. The final step in the process is to upload the robot control sketch. That's when I encountered the issue.
Here's the question:
Given the circuit
Question: Should the external power supply be ON or OFF when the USB cable is connected? Does it matter?
There is a note in the "Lesson 6 - Assembly the Robot" instructions (emphasis mine)
2.Adjust the angle of 4 servos to 90 degrees
2.1 Please connect the 4 servos, the nano board, nano shield, and battery case with two 18650 batteries together, as shown in the figure below, and then connect them to the PC via a mini USB cable.
NOTE:
Servo 1, 2, 3, 4 are connected to Pin4, 5, 6, 7 of shield respectively Make sure your two 18650 batteries have enough power.
Turn on the power switch of the shield since the current provided by the usb is not enough to drive the servos
I adjusted the servos angles using a servo tester rather than connect them to the Nano. Thus, I didn't encounter the issue until I uploaded the control sketch. But I noted the order as unremarkable: USB then power supply ON.
When I did upload the control sketch to the Nano from the USB, both the HAT power switch and the power supply are OFF.
The result was unexpected behavior: the buzzer sounded and wouldn't stop.
It took a considerable amount of time to diagnose and verify the cause of the symptom and the actual problem. I verified it's not a wiring problem and that the code is fragile but has no error, i.e., the code behavior is a symptom of, but not the problem.
SPOILER AHEAD
Diagnostics
When I examined the buzzer code I found
void buzzer(int H,int L){ while(yR<420){ digitalWrite(buzzerPin,HIGH); delayMicroseconds(H); digitalWrite(buzzerPin,LOW); delayMicroseconds(L); yR = arm.JoyStickR.read_y(); } while(yR>600){ digitalWrite(buzzerPin,HIGH); delayMicroseconds(H); digitalWrite(buzzerPin,LOW); delayMicroseconds(L); yR = arm.JoyStickR.read_y(); } }
Since I wasn't touching the joysticks, it was the state of the joysticks at boot time that was causing the buzzer to sound. The joystick was tested (and passed) in a previous step, so I went back and re-examined the results and that's when I discovered that the joystick positions never reached their maximum value and their "centered" values were lower than the midpoint. The wiring diagram for the joystick test was
Of course, I followed this exactly, so the circuit was powered by the USB. At the time of the test, I noted the changing values but not the range of the values. Mea culpa.
Thus the code was reading the center position as a recording movement and repeatedly sounding the buzzer.
When I did notice the range error, I changed the power source to the bench power supply and the full range came through.
From that it became apparent that the Nano needed to be powered from the external power supply instead of the USB; thus, the power should be ON before the USB is connected.
When I did this the buzzer stopped and the arm operated as intended (but unsatisfactorily.)
I'm honestly not sure if I should have known this or not but I certainly do now.
The one who has the most fun, wins!
@tfmccarthy Normally it doesn't make any difference, but I always turn on the auxiliary power first anyway, however in this case it was mandatory. Lesson learned and your diagnostic skills are functioning well.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.