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.
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?
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?
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?
sterretje:
You should have asked Rigol if the USB gives all data
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?
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
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?