using tsl2561 light sensor with a pyboard

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: using tsl2561 light sensor with a pyboard

Post by pythoncoder » Mon Sep 17, 2018 8:06 am

rp346@njit.edu wrote:
Sun Sep 16, 2018 6:57 pm
...
Is this correct way to access HW I2C.

import tsl2561
from machine import Pin, I2C
i2c = machine.I2C(scl = machine.Pin(12), sda = machine.Pin(13), freq = 10000)
sensor = tsl2561.TSL2561(i2c)
sensor.read()
No, that is how to set up software I2C. To set up hardware I2C you need to specify the bus number. The pins are defined in hardware.

Code: Select all

i2c = machine.I2C(1)
will provide I2C on pins X9 (scl) and X10 (sda). You can provide freq = 10000 to override the default 400KHz.
Peter Hinch
Index to my micropython libraries.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: using tsl2561 light sensor with a pyboard

Post by IHOXOHI » Mon Jun 22, 2020 5:26 pm

Hi,

I can use the tsl2591 and pyboard with this library at :https://github.com/jfischer/micropython-tsl2591

And the code:

Code: Select all

import tsl2591
import machine

i2c = machine.I2C(-1, scl = machine.Pin('Y9'), sda = machine.Pin('Y10'), freq = 10000)


sensor = tsl2591.Tsl2591(i2c)

full, ir = sensor.get_full_luminosity()  # read raw values (full spectrum and ir spectrum)

lux = sensor.calculate_lux(full, ir)  # convert raw values to lux

print(lux, full, ir)

Post Reply