Using ARDUINO MICRO Board as a USB

Board :->> Arduino MICRO
Project: USe the Arduino Micro as a USB device

SO I was successfully able to change the VID & the PID and the device name for the arduino micro board. Successfully, I was able to write my custom Win.inf file and use the WIN_usb driver to communicate with the arduino board. I Used the end points for the arduino Micro board and I can write to the board and read from board. here is a snap of the code

ULONG Bufferlength = 101024;
UCHAR ReadBuffer[10
1024];

ULONG ByteRead ;

ReadResult = WinUsb_ReadPipe(Associated_UsbHandel,
Read_EndPoint, //PipeID,
ReadBuffer, // Buffer,A caller-allocated buffer that receives the data
Bufferlength, // BufferLength,
&ByteRead, // LengthTransferred,
NULL);

String^ msg = gcnew String(reinterpret_cast< char*>(Bufferlength));

MessageBox::Show (msg, "Working", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

SO far so good, but the issue is

IF I unplugged the board and plugged it back in , I can only connect , initialize , write to it but I can't read from it. WHen I try to read, the program sends the command and try to read data but it get stuck ,like nothing coming back. Not even timing out.

and to be able to read I have to uninstall the driver, re program the board with the new boot loader, and re upload the IDE sketch and then re install the driver in order for me to be able to read again.

,
Have anyone experienced this issue before? What is possible solutions ?

I don't see the (Arduino) problem at the moment. It might be necessary to start by explaining why you think it's necessary that your Arduino board has a different product- and vendor-ID. What do you try to achieve?

pylon:
I don't see the (Arduino) problem at the moment. It might be necessary to start by explaining why you think it's necessary that your Arduino board has a different product- and vendor-ID. What do you try to achieve?

the problem that if I unplugged the board then plugged it back, I can't read data from it any more

Update

I think when i unplug the board and plug it back , for some reason the serial become unavailable- here is my sketch

void setup() {
// put your setup code here, to run once:
// wdt_disable();
Serial.begin(9600);
pinMode(13,OUTPUT);
//getSettings(); //start serial settings menu to chooe WDT setting
//if(wdtsetting ==1) setWDT(0b01000000);// set for interrupt onlt
//else if (wdtsetting ==2 ) setWDT(0b00001000);//set for reset
// else setWDT(0b01001000);// set for interupt and then reset

}

void loop() {
//digitalWrite(13,HIGH);
// put your main code here, to run repeatedly:
// Read Values fro sensor

int READFREQ [20];
int READENR [20];

if (Serial.available() ){
Data = Serial.read();

// Print value
if (Data == 't'){ // read Tempreature
SensorValue = analogRead(SensorPin);
// map it to the range of the analog out:
outputValue = map(SensorValue, 0, 1023, 0, 5000);outputValue=outputValue/1000;
outputValue = (SensorValue5.0)/1023.0;
Serial.print(outputValue);
//Serial.print("e ");
//Serial.println();
delay(100);
//wdt_reset();
}
else if(Data == 'n'){
digitalWrite(13,HIGH);
delay(10) ;
// wdt_reset();
}
else if (Data == 'w'){ // write Cal data
for (int i = 0 ; i < 1024 ;i++) {
//EEPROM.write(i,CalData
);*

  • //digitalWrite(13,HIGH); *

  • }*

  • // digitalWrite(13,LOW);*

  • }*
    else if (Data == 'r'){ // read cal data

  • BLINK (13, 500,3);*

  • for (int k = 0 ; k < 5 ; k ++) {*

  • READFREQ[k] = pgm_read_word_near(&Frequency[k]);*

  • READENR [k]= pgm_read_word_near(&ENR[k]);*

  • // wdt_reset();*

  • Serial.println(READFREQ[k]);*

  • Serial.println(READENR [k]);*

  • }*

  • delay(100);*

  • BLINK (13, 500,5);;*
    }

  • else {*

  • digitalWrite(13,LOW);*

  • }*

}
}
/*void setWDT(byte sWDT){

  • WDTCSR |= 0b00011000; //initializing*
  • WDTCSR= sWDT | WDTO_2S; // set for 2 seconds interval*
  • wdt_reset();*

}
ISR (WDT_vect)
{

  • digitalWrite(13,HIGH);*

}*/
void BLINK (int LED, int Interval_msec, int num_of_blink ){

  • for (int i = 0; i < num_of_blink ; i++){*
  • digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)*
  • delay(Interval_msec); // wait for a second*
  • digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW*
  • delay(Interval_msec); // wait for a second*
  • }*
    }
    [/quote]

Learn to use code tags, quote tags are for quotes, code tags are for code (use the </> button in the editor)!

You have several delay() calls in that sketch. What are they used for?

the delays is used to give enough time for me to read data using my VC++ application

I'm pretty sure you VC++ application can handle data coming in at 9600 baud without any delay on the Arduino side. If it can't you've found your error.

the problem that if I unplugged the board then plugged it back, I can't read data from it any more

Does your VC++ application always run while you unplug and replug the Arduino? If yes, that's the problem probably. I no Windows expert but I guess in this situation it behaves like most operating systems and keep the driver loaded, so it will change to another port if the Arduino is plugged in again.