claws / BH1750

An Arduino library for the digital light sensor breakout boards containing the BH1750FVI IC
MIT License
248 stars 107 forks source link

Hello, the library dont really want to work with my esp32s, anyone? #56

Open marius240 opened 5 years ago

marius240 commented 5 years ago

my code:

#include <Wire.h>

BH1750 lightMeter(0x5C);

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  Serial.begin(115200);
  lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
  delay(2000);

}

void loop() {
  // put your main code here, to run repeatedly:

  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light level: ");
  Serial.println(lux);

  delay(5000);

}

The cabling:

D21 -> SDA D22 -> SCL GND & ADDR -> gnd VCC -> 3.3V

marius240 commented 5 years ago

btw my it gives me error: [BH1750] ERROR: received NACK on transmit of address in the start and then for the rest of the time just: Device is not configured! Light level: 65534

marius240 commented 5 years ago

the board is NodeMCU ESP32S

marius240 commented 5 years ago

i2cdetect just gives me

Udklip
marius240 commented 5 years ago

Need help ASAP! @claws @wridgers @goebish @NuTTeR

thanks <3

goebish commented 5 years ago

try with Wire.begin(21, 22);

marius240 commented 5 years ago

@goebish nope aint working

marius240 commented 5 years ago

still same error, just ERROR: received NACK on transmit of address

goebish commented 5 years ago

Have you tried to add pull up resistors between SDA<->3.3V and SCL<->3.3V ? I'm not sure Wire.begin takes care of that. If that doesn't work, then I don't know, have you tried with another i2c device such as a small oled display ?

marius240 commented 5 years ago

nope dont have another ic2 device, and dont think i got a pull up resister,

marius240 commented 5 years ago

but im pretty sure there is no need for a pull up resistor

goebish commented 5 years ago

just use any 1k-30k resistors, that should be fine, you need 2

marius240 commented 5 years ago

so a resistor between D21 -> SDA and D22 -> SCL ?

marius240 commented 5 years ago

why should a resistor change anything? just asking :D

goebish commented 5 years ago

no, between SDA -> 3.3V & SCL -> 3.3V

goebish commented 5 years ago

because i2c lines need to be pulled up https://rheingoldheavy.com/i2c-pull-resistors/ It could be done in software in the i2c lib, but I'm not sure that's the case, just check with pull up resistors, you've nothing to lose ;)

marius240 commented 5 years ago

not sure what you mean, there is no between SDA and 3.3v i think photo otw

goebish commented 5 years ago

well, just connect a 10k or so resistor between +3.3V and SDA ... same for SCL

marius240 commented 5 years ago

im trying to say, i connect direct from the board to scl, there is no connection to 3v between i can interact with

marius240 commented 5 years ago

54523241_558077871358896_6261248468510048256_n

marius240 commented 5 years ago

i have a 3v pin ofc, but i sounds weird if i should hook the up to them

marius240 commented 5 years ago

btw the blue line is ground and the red is 3.3v

marius240 commented 5 years ago

@goebish

goebish commented 5 years ago

yes, just connect this 3.3V line to SDA through a resistor ... same for SCL, don't change anything else

marius240 commented 5 years ago

lul ok,

goebish commented 5 years ago

don't worry, you can't get the magic smoke out just by adding pull up resistors ;)

marius240 commented 5 years ago

hmmm it didnt work just hooking 3.3v onto scl and sda

marius240 commented 5 years ago

without resister tho

goebish commented 5 years ago

... don't do that, that could damage the esp! resistors are important!

marius240 commented 5 years ago

oh something changed, when i unplug both 3.3v it says ERORR: received NACK on transmit of address but if i connect 3.3v to either one or both i get ERROR: received NACK on transmit of data

marius240 commented 5 years ago

@goebish

marius240 commented 5 years ago

get same result, when im using 0x23 and 0x5c i thought it maybe could be cause that address was wrong

goebish commented 5 years ago

At least that seems better with the pull up resistors, but I don't understand why you get an error on transmit of data then, the library is only using standard Arduino lib commands, nothing specific to a platform. Have you tried the i2c scanner with pull up resistors ? you can also try to use GPIO 16 & 17 Wire.begin(16, 17); // sda, scl don't forget to change your wiring accordingly

marius240 commented 5 years ago

ok, i just tryed running i2cdetect, while have connected the 3.3v's, and it just give a billion errors per mili second, so i guess i need a resistor

goebish commented 5 years ago

There's something I don't understand, are you connecting scl & sda directly to +3.3V ? Never do that! Use resistors or nothing at all, but don't connect directly!

marius240 commented 5 years ago

just tryed with a resistor on both with the strength of 15 Ω * 10^5

marius240 commented 5 years ago

just got the error with the address

goebish commented 5 years ago

Use resistors between 1k and 30kΩ, not 150kΩ or 1.5MΩ, are you reading my messages?

marius240 commented 5 years ago

yep

marius240 commented 5 years ago

oh sorry did just catch the 1k - 30k / i forgot it

coelner commented 5 years ago

Did you solder the pins to the boards or do you just push it through? Solder it and check the resistance with a multimeter. If you solder the pins as seen in the picture then it is wrong. (The board itself contains usually the needed pullup resistors)

marius240 commented 5 years ago

Yea the pins is soldered, but the board is a esp32, I have a esp8266, but I need it to work on esp32

coelner commented 5 years ago

I'm aware of your board, but I want to know whether the sensor works with another board. The library supports the esp32, I tested it right away and it works flawless.

marius240 commented 5 years ago

hmm, which address are you using?

coelner commented 5 years ago

The default one (0x23). I use the lolin32lite, Pin 22 and 21 for i2c.

marius240 commented 5 years ago

ye i use pin 22 and pin 21 to, have tryed both 0x23 and 0x5C

coelner commented 5 years ago

To sum it up. Your wiring, your board, your sensor. Not the library.

marius240 commented 5 years ago

hm ok

marius240 commented 5 years ago

so something is wrong with the wirering?

coelner commented 5 years ago

I think so.

marius240 commented 5 years ago

i use the latest arduinoIDE, im not sure what the power rail is, what do you mean with soldered to the wrong side?