Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting to a Goldmund audio processor #830

Open
BobHD opened this issue Jan 7, 2025 · 6 comments
Open

Connecting to a Goldmund audio processor #830

BobHD opened this issue Jan 7, 2025 · 6 comments

Comments

@BobHD
Copy link

BobHD commented Jan 7, 2025

Hi,

I am trying to use an Aduino Uno + ARCELI USB Host Shield to send serial commands to a Goldmund audio processor.

These commands when I use a C++ program on Windows 10 with code like:

WriteFile(hSerial, dataToSend.data(), dataToSend.size(), &bytesWritten, nullptr)

work well.

I had to use a driver from:

https://ftdichip.com/drivers/

My Arduino program uses:


#define ENABLE_UHS_DEBUGGING 1
#include <cdcacm.h>
#include <usbhub.h>                                                                                                            
// Global objects for USB communication
USB Usb;
CDCAsyncOper AsyncOper;
ACM Acm(&Usb, &AsyncOper);

void setup()
{

  Serial.begin(115200);

  while(Usb.Init() == -1)
   { Serial.println("OSC did not start.");
     delay(250);
   }
}
void loop()
{
  Usb.Task(); // Required to maintain USB functionality
  USB_DEVICE_DESCRIPTOR desc_buf;
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
   { uint8_t rcode = Usb.getDevDescr(1, 0, 0x12, (uint8_t *)&desc_buf);
     if (rcode)
      { Serial.print(F("\r\nError reading device descriptor: "));
        Serial.println(rcode, HEX);
      }
     else
        Serial.print(F("\r\nDevice descriptor: "));
     delay(10000);
   }
  else
     Serial.println(Usb.getUsbTaskState());
..............
 
Usb.Task();
if (Acm.isReady())
   Acm.SndData(len_serial, buff_serial);
else
   Serial.println("Acm is not ready);
..............
}

With this:

  1. Usb.Init() works.

  2. Usb.getUsbTaskState() return 18.

  3. Acm is not ready.

What can I do to debug this?

@BobHD
Copy link
Author

BobHD commented Jan 9, 2025

My error was that FTDI is not CDC ACM.

Si I rewrote my program using FTDi:
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.");
  }
}

that goes straight to:

Serial.println("No FTDI device found.");

Any idea?

@xxxajk
Copy link
Contributor

xxxajk commented Jan 19, 2025

UHS30 treats all serial (including FTDI) as if they are CDCACM by providing the equivalent responses via a small abstraction layer. Have you tried to see if that will work for you?

@BobHD
Copy link
Author

BobHD commented Jan 20, 2025

I did not know about the USB Host Shield 3.0 (just looked it up), I got the first one I found, a DollaTek ESP-12E ESP8266 UART.

I found the library here:

https://github.com/felis/UHS30

I'm not sure about the hardware compatible with the UNO REV3 though, is this the one?

https://www.sparkfun.com/sparkfun-usb-c-host-shield.html

Would you have a link in Europe?

Thanks.

@xxxajk
Copy link
Contributor

xxxajk commented Jan 20, 2025

The sparkfun board is wired wrong, and only old UNO will work with it without modifications, and it doesn't have enough RAM to operate with UHS30 because it uses the actual USB specifications instead of shortcut hacks.
I have to look into it, but I should be able to get a PJRC Teensy 4.1 running with it, and does not require any additional boards. Last time I used it the 4.1 worked fine.

@BobHD
Copy link
Author

BobHD commented Jan 20, 2025

Let me know please.

Also, what might be a problem is that I also run the IRLib library.

I know for example that it does not compile with the Arduino UNO WIFI, that I just tested needing to add Ethernet capability. I'm going to try an Ethernet shield on the UNO, but I'm close to max memory with it.

Any suggestion to replace the UNO with another board that will have more memory and work with IRLIB?

Edit: I see now that the Teensy has also Ethernet, great. That would be ideal if IRLIB works with it.

It will be fun to try, I just ordered it.

@xxxajk
Copy link
Contributor

xxxajk commented Jan 20, 2025

Excellent. Don't forget the usb cable (if you got one from an old motherboard for front panel, these work fine) and the ethernet leadout that contains the magnetics/jack.
Teensy4.1 is a 600MHz beast, and you won't be disappointed, especially if you need a lot of RAM for something. You can add on an extra 16MB of PSRAM (same 8MB on the ESP32) for some fantastic possibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants