The PC reference was just to show how the processor reacts to USB commands.
I am trying to replicate what works from a PC using an Adruino Uno + USB shield, with the USB Host Shield Library 2.0.
There is one cable from the Shield to the Processor.
During debugging phase, there is one cable from the PC to tje Arduino, but that's just to upload the program and debug it.
With the help of grok 2, I am trying now:
#include <Usb.h>
#include <cdcftdi.h>
USB Usb;
FTDI *Ftdi = NULL; // Use a pointer to handle dynamic allocation
void setup() {
Serial.begin(115200);
// Initialize USB
while (Usb.Init() == -1) {
Serial.println("OSC did not start.");
delay(200);
}
// Manually find and initialize FTDI device
Serial.println("Line 17");
Usb.Task();
Serial.println("Line 18");
uint8_t devCount = Usb.getUsbTaskState();
//if (devCount == 0)
Serial.println(devCount);
Serial.println("Line 23");
for (uint8_t i = 0; i < devCount; i++) {
USB_DEVICE_DESCRIPTOR devDescr;
if (Usb.getDevDescr(i, 0, 0x12, (uint8_t*)&devDescr) == 0) {
Serial.println("Line 27");
// Check if this device is an FTDI device by its VID/PID
if (Usb.getUsbTaskState() == USB_STATE_RUNNING) {
if (devDescr.idVendor == 0x0403 && devDescr.idProduct == 0x6001) { // Example VID and PID for FTDI FT232R
Ftdi = new FTDI(&Usb, i); // Assuming FTDI constructor takes USB instance and device index
if (Ftdi == NULL) { // Check if allocation failed
Serial.println("Failed to allocate FTDI instance.");
} else {
break; // Found FTDI device
}
}
}
}
}
if (Ftdi == NULL) {
Serial.println("No FTDI device found.");
while (1);
}
// Set baud rate to 115200
if (Ftdi->SetBaudRate(115200) != 0) {
Serial.println("Failed to set baud rate.");
while (1); // Halt if baud rate cannot be set
}
Serial.println("USB FTDI Initialized");
}
void loop() {
Usb.Task(); // Maintain USB functionality
if (Ftdi->isReady()) {
const char* cmd = "DE4212";
uint16_t len = strlen(cmd);
// Write the command string to the FTDI device
uint8_t rcode = Ftdi->SndData(len, (uint8_t*)cmd);
if (rcode) {
Serial.print("Send Data Error: ");
Serial.println(rcode, HEX);
} else {
Serial.println("Data sent successfully.");
delay(1000); // Wait a bit before sending again or looping
}
} else {
Serial.println("FTDI device not ready.");
}
}
I should have made a search of course!
I found it in several places, so I just used: include "C:\Users\m1\Documents\Arduino\libraries\USB_Host_Shield_2.0-master\examples\USB_desc\pgmstrings.h"
At first, I got "OSC did not start.", so I added this retry loop:
while(start)
{ if (Usb.Init() == -1)
{ Serial.println("OSC did not start.");
delay(200);
}
else
{ Serial.println("OSC started.");
start = 0;
}
}
Now it does start, but all I get is:
Port open
VS%�5E���5
OSC did not start.
OSC started.
and in the output window:
Millis is currently 28720.
13:58:50.827 [up:28s:971ms perf:247ms] GoldCont.ino, line 103 millis()=28971
Millis is currently 28971.
13:58:51.075 [up:29s:221ms perf:246ms] GoldCont.ino, line 103 millis()=29221
Millis is currently 29221.
@Bob8K How do you know it is an FTDI device? Run the USB_desc example to find the Vendor ID and Product ID. Search the web for "USB Vendor ID code" to determine the manufacturer.
This could be due to mismatch of Vendor ID and/or Product ID.
The following might help.
I would debug the USB host shield without all those wires connected. One misplaced wire can prevent this from working. Also if there are any other shields in the stack, remove them.
Can you get the same control functions via the Audio Processor's RS232 interface as are available via USB? I imagine using RS232 would be considerably simpler.
Goldmund doc does not say that the USB socket can be used the same way as the RS232 one, it's usually used to set up the processor with a specific software.
But I tried with exactly the same C program with Visual Studio, and it does work.
I can from the PC control the volume, input and balance exactly the same it was working before using the RS232 socket. For the PC, it's just a different COM port once I set up the driver mentioned above,