Hello,
I'm having a lot of troubles with my Arduino Micro's virtual Serial Port.
For example i can not even run the Basic Sample AnalogReadSerial, it simply does nothing.
When I add a while(!Serial) ; into the Setup Loop it seams to work.
Now I understand what that is supposed to mean, if it starts writing to the virtual serial after its open it works and if it starts writing right away and the port is opened later on it fails.
But to my understanding thats wrong it should drop all send data before opening the port and that work as it should.
Now while(!Serial) ; does not always solves the issue for example I tried to use the Micro as a ISP Programmer following this guid: ArduinoISP on the Leonardo | PeterVH using arduino IDE 1.0.3 and well it failed.
I also head some code for example to read a parallel to serial register chip and while(!Serial) ; in Setup was not enough i needed a wait before every send to see something in the Serial Monitor.
Using the Serial1 and a usb adapter works fine.
Now whats the issue here?! I would guess its not a faulty chip as the boot loader works...
I really need help with this one as it stands its not usable for me
EDIT: with that scatch
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
#define LED_HB 13
// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta;
hbval += hbdelta;
analogWrite(LED_HB, hbval);
delay(20);
}
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
heartbeat();
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
the heartbeat stops when the port is open and resumes after its closed, really strange
That while loop is needed in setup(): while(!Serial) ;
And you might want to try the Arduino 1.5.8 BETA.
You can also get in trouble when you sent too much data to the (virtual) serial port without delay.
That will also cause troubles in other Arduino boards, but more in the Leonardo board.
The (virtual) Serial port on the Leonardo board is a mix of (usb)hardware and software.
The Serial1 is a real hardware serial port inside the ATmega32u4 microcontroller.
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
while(!Serial) ;
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(100); // delay in between reads for stability
}
this one does not work eider, that can't be normal!
Thank you for the small test sketch.
I don't have an Arduino Micro, so I used my Arduino Leonardo.
Ubuntu Linux 14.04 64-bit, Arduino IDE 1.5.8 BETA, Official Arduino Leonardo board (bootloader version unknown).
After pressing the reset button on the Leonardo (and the serial monitor is still open) the sketch stops, waiting for the serial monitor to be opened. Sometimes the (virtual) serial ports is /dev/ttyACM0 and sometimes it is changed to /dev/ttyACM1, because linux gets confused. Removing the "while(!Serial) ;" will only work if the serial monitor is opened after the Leonardo has been started. The 'hartbeat' runs, but there is no serial output.
During development, the "while" should be there, and open the serial monitor only after the Leonardo has started.
I did remove the "while" for a runtime version, but in that situation the serial port is opened after the Leonardo was connected and running.
Do you want to have a serial monitor open all the time ?
Should I test it in Windows ?
Your test sketch with hartbeat:
// the setup routine runs once when you press reset:
void setup() {
pinMode( 13, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
delay(100); // this delay doesn't help
while(!Serial) ;
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(100); // delay in between reads for stability
// hartbeat
digitalWrite( 13, HIGH);
delay(180);
digitalWrite( 13, LOW);
}
I'm glad you found the problem. I have used Arduino behind a hub many times, never had a problem.
Is there something special about the hub ? Perhaps an old usb 1.1 hub ?
Well all other arduinos work just fine, just the micro that has a diferent USB handlig does not want to.
The hub is an reasonably old 2.0 hub, but its connected to a PVMp Switch.
I guess its some kind of odd bug.