0

I tried to represent the values of TSL 2591 Adafruit light sensor on my Arduino Serial Monitor, but for some reason, I could not do that. The Arduino Serial Monitor just enters some blank values and scrolls down. Here is the code:

uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
y = float(tsl.getLuminosity(TSL2591_VISIBLE));
z = (y, DEC);
Serial.write((byte)z);

x, y, and z are floats initially.

migrated from stackoverflow.com Nov 15 '18 at 13:55

This question came from our site for professional and enthusiast programmers.

  • Did you enabled the serial communication on arduino by using Serial.begin(9600)? – svtag Nov 15 '18 at 9:22
  • 1
    What's z = (y, DEC); supposed to do? – Gerben Nov 15 '18 at 16:18
  • Yes, I enabled it. What if I change 9600 to another value? @svtag – Асмир Абдимажитов Nov 16 '18 at 9:46
  • I think it converts the values to decimals @Gerben – Асмир Абдимажитов Nov 16 '18 at 9:47
3

Use Serial.println(x); to print a number as text. Function write() sends the raw byte and Serial Monitor shows the character with that ASCII code, which is not valid or a not visible control character.


For the z = (y, DEC); from Wikipedia:

In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

so z is always 10 (value of constant DEC), which is ASCII code for the new line character

  • Comments are not for extended discussion; this conversation has been moved to chat. – Majenko Nov 16 '18 at 18:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.