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.

gre_gor
1,6824 gold badges18 silver badges28 bronze badges
asked Nov 15, 2018 at 7:04
4
  • Did you enabled the serial communication on arduino by using Serial.begin(9600)? Commented Nov 15, 2018 at 9:22
  • 1
    What's z = (y, DEC); supposed to do? Commented Nov 15, 2018 at 16:18
  • Yes, I enabled it. What if I change 9600 to another value? @svtag Commented Nov 16, 2018 at 9:46
  • I think it converts the values to decimals @Gerben Commented Nov 16, 2018 at 9:47

1 Answer 1

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

answered Nov 15, 2018 at 10:14
1
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Nov 16, 2018 at 18:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.