Serial.write inside #ifdef inside setup() function doesn't work with Teensy LC

Status
Not open for further replies.

alexandros

Well-known member
In my setup() function I have the following:
Code:
#ifdef ANALOG_RESOLUTION
    analogReadResolution(ANALOG_RESOLUTION);
    int local_index = 1;
    transfer_data[local_index++] = NUM_OF_MODULES + 1;
    transfer_data[local_index++] = 2;
    transfer_data[local_index++] = 0;
    transfer_data[local_index++] = ANALOG_RESOLUTION;
    Serial.write(transfer_data, local_index);
  #endif

I have defined a macro ANALOG_RESOLUTION 12, and the analogReadResolution is called, as I can see values from potentiometers going from 0 to 4096 (well, a bit less than that, but I think that's a matter of the circuit), but I don't receive the things Teensy is supposed to print to my laptop (it's some data sent to Pure Data).
I tested this with an Arduino UNO and the bytes after analogReadResolution() are being written to the serial line and printed in Pure Data. Is this something known with Teensy?
 
Perhaps something is subtly wrong with your code, maybe the definition of transfer_data? Can't see the whole program, so difficult to guess...
 
The whole program is 550 lines of code, so I thought it would be a bit of an overkill to share the whole thing. I'll try to narrow it down to the problematic part and send that one. Probably tomorrow, no time now.
Could also be sending before the serial monitor opens
That's not the case, the serial port is opened before this preprocessor stuff.
Thanks for the tips though.
 
You do realize, Serial is the USB serial emulation, right?

How did you set up the USB type for your board? The HID version of serial (USB type doesn't include Serial) doesn't support binary data with 0-values.
 
That's not the case, the serial port is opened before this preprocessor stuff.
Do you have:
Code:
while(!Serial);
after Serial.begin() ? If not, that is probably the problem.

Pete
 
Status
Not open for further replies.
Back
Top