Reading serial data using USB host shield

Hi, I have been searching a way to read serial data using USB host shield connected to Arduino Uno, but did not have much luck.

Here is the setup:

Rigol 3068 multimeter ----> USB host shield / Arduino Uno

I know that my multimeter sends 14 byte ASCII serial data, and would like to read that using the USB host shield.

How should I code this? I have looked through the USB host shield library 2.0, but the library provides high level examples (XBOX controller, bluetooth, etc), but not this kind of simple task.

Any help would be appreciated.

Thanks,
Jaewoo

You might start by looking for something like the acm_terminal example. Is your shield Max3421E based? I have used this with similar devices. GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

Using an Arduino with extra hardware UART ports such as the Mega is much easier than adding a UART via the USB Host shield.

gdsports:
Using an Arduino with extra hardware UART ports such as the Mega is much easier than adding a UART via the USB Host shield.

Or a Pro Micro if you want something smaller.

gdsports:
Using an Arduino with extra hardware UART ports such as the Mega is much easier than adding a UART via the USB Host shield.

I tried doing that with Teensy 3.5, reading data from RS232. However, reading data from RS232 worked but it had its flaws. So now I'm trying to read data from the USB channel.

Is there any way I could connect the USB channel to hardware UART port?

Thanks,
Jaewoo

wzaggle:
You might start by looking for something like the acm_terminal example. Is your shield Max3421E based? I have used this with similar devices. GitHub - felis/USB_Host_Shield_2.0: Revision 2.0 of USB Host Library for Arduino.

Thanks for your reply. I could not find the acm_terminal example. Is it supposed to be in the USB host shield 2.0 library?

and yes, the shield is Max3421E based.

Thanks,
Jaewoo

po03087:
I tried doing that with Teensy 3.5, reading data from RS232. However, reading data from RS232 worked but it had its flaws. So now I'm trying to read data from the USB channel.

Is there any way I could connect the USB channel to hardware UART port?

Thanks,
Jaewoo

What unspecified flaws are those?

Thanks for your reply. I could not find the acm_terminal example. Is it supposed to be in the USB host shield 2.0 library?

Yes, look in the examples folder of the library.

aarg:
What unspecified flaws are those?

I am using RIGOL 3068 for the multimeter, and the RS232 channel doesn't output every data measured. For example, if I do a capacitance measurement in a frequency of 25Hz, the RS232 channel outputs data only in 2.5 Hz, meaning that it is outputing 1 data set out of 10. I emailed Rigol about it, and they said there is nothing I can do to fix that.

Therefore I am trying to see if the USB channel outputs every data set.

One question: is data communication over USB channel serial just like RS232 communicates?

Thanks,
Jaewoo

You should have asked Rigol if the USB gives all data :wink:

And no, USB is nothing like serial.

sterretje:
You should have asked Rigol if the USB gives all data :wink:

And no, USB is nothing like serial.

I contacted Rigol several times but no answer.. so I'm giving a shot on USB output channel.

If USB is not like serial, is the setup I am trying to build (acquiring measurement data from the USB channel via usb host shield on arduino) possible?

Thanks,
Jaewoo

I use keyes usb host shiled
the code is the acm_terminal

#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

class ACMAsyncOper : public CDCAsyncOper
{
public:
    uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
    uint8_t rcode;
    // Set DTR = 1 RTS=1
    rcode = pacm->SetControlLineState(3);

    if (rcode)
    {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING lc;
    lc.dwDTERate = 115200;
    lc.bCharFormat = 0;
    lc.bParityType = 0;
    lc.bDataBits = 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode)
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

    return rcode;
}

USB     Usb;
//USBHub     Hub(&Usb);
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

void setup()
{
  Serial.begin( 115200 );
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");

  if (Usb.Init() == -1)
      Serial.println("OSCOKIRQ failed to assert");

  delay( 200 );
}

void loop()
{
    Usb.Task();

    if( Acm.isReady()) {
       uint8_t rcode;

       /* reading the keyboard */
       if(Serial.available()) {
         uint8_t data= Serial.read();
         /* sending to the phone */
         rcode = Acm.SndData(1, &data);
         if (rcode)
            ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
       }//if(Serial.available()...

       delay(50);

        /* reading the phone */
        /* buffer size must be greater or equal to max.packet size */
        /* it it set to 64 (largest possible max.packet size) here, can be tuned down
        for particular endpoint */
        uint8_t  buf[64];
        uint16_t rcvd = 64;
        rcode = Acm.RcvData(&rcvd, buf);
         if (rcode && rcode != hrNAK)
            ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

            if( rcvd ) { //more than zero bytes received
              for(uint16_t i=0; i < rcvd; i++ ) {
                Serial.print((char)buf[i]); //printing on the screen
              }
            }
        delay(10);
    }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}

I want add the log in the sd, but if not start the serial monitor, the code is freeze

1 Like

I know it's kinda late, but I'm working with my UT71C Batronix multimeter, doing the same thing as you. I'm trying to connect it with usb shield with uno. Is there any answer for this topic?