Всем доброго времени суток! Помогите плиз или направьте в верное русло. Имеется данный датчик CO2, с которого нужно получить показания на Arduino через USB Host Shield. Для получения данных нужно отправить запрос. К датчику прилагается специальный софт, в котором при чтении с датчика выводятся следующие команды: Код (Text): **** K-33 ICB 'sensor' Connected on COM7 **** [Host]>>> 0xFE 0x44 0x0 0x8 0x2 0x9F 0x25 [sensor(K-33 ICB)]>>> 0xFE 0x44 0x2 0x0 0xFB 0xF9 0x67 CO2 = 2510 Поискал в интернете, многие советуют брать за основу скетч из примеров pl2303_terminal. Код (C++): /* Arduino terminal for PL2303 USB to serial converter and DealeXtreme GPRS modem. */ /* USB support */ #include <usbhub.h> /* CDC support */ #include <cdcacm.h> #include <cdcprolific.h> // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include <spi4teensy3.h> #endif #include <SPI.h> byte cmd1[] = {0xFE,0x44,0x0,0x8,0x2,0x9F,0x25}; //данные для запроса class PLAsyncOper : public CDCAsyncOper { public: uint8_t OnInit(ACM *pacm); }; uint8_t PLAsyncOper::OnInit(ACM *pacm) { uint8_t rcode; // Set DTR = 1 rcode = pacm->SetControlLineState(1); if (rcode) { ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode); return rcode; } LINE_CODING lc; //lc.dwDTERate = 9600; 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); PLAsyncOper AsyncOper; PL2303 Pl(&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( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { uint8_t rcode; /* reading the keyboard */ if(Serial.available()) { uint8_t data= Serial.read(); /* sending to the phone */ rcode = Pl.SndData(1, &data); //rcode = Pl.SndData(7, cmd1); if (rcode) ErrorMessage<uint8_t>(PSTR("SndData"), rcode); }//if(Serial.available()... /* reading the converter */ /* 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 = Pl.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 } }//if( rcvd ... }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. } В строке 82 пытался отправить данные, но в ответ ничего не приходит
если я правильно понял, там есть и i2c и uart и даже аналоговый выход. если это так, то нафига всё это юсб
Надо запросить API для USB у производителя. Если про USB не знаете ничего, то лучше отдать тем, кто знает.