robert-hh / SH1106

MicroPython driver for the SH1106 OLED controller
Other
163 stars 38 forks source link

Pi Pico UV sensor(veml6070) #20

Closed Kratos800 closed 2 years ago

Kratos800 commented 2 years ago

The code below is my code on pi pico I have installed all the libraries needed.

import digitalio
import time
import board
import radio
import bmp280
import UV

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
led.value = True
cansat_temperature = bmp280.read_temperature()
cansat_pressure = bmp280.read_pressure()
room_temp = cansat_temperature
room_pressure = cansat_pressure

print("T: {:.3f} P: {:.2f}".format(cansat_temperature, cansat_pressure))

while True:
    led.value = not led.value
    print("Radio message sent")
    time.sleep(1)
    cansat_temperature = bmp280.read_temperature()
    print(cansat_temperature)
    cansat_pressure = bmp280.read_pressure()
    print(cansat_pressure)

    radio.send(
        "[CGS] Temperature: {:.2f} Pressure {:.0f}".format(room_temp, room_pressure)
    )

I am trying to code veml6070 UV sensor and the code is:

import board
import adafruit_veml6070

i2c = board.i2c()

but I am getting error: AttributeError: 'module' object has no attribute 'i2c'

robert-hh commented 2 years ago

What is the relation of you post to the SH1106 driver?

And not related to that: it seems as if you use CircuitPython. I cannot tell you more about CircuitPyhton than you can find in it's documentation. The error you get is a CircuitPython question. You can get the list of object in the board module with:

dir(board)

It shows that the name of the object is I2C, not i2c. So the line should most probably be:

i2c=board.I2C()

Using the default SDA and SCL pins.

Kratos800 commented 2 years ago

I already tried to do that but still it was showing the same error

robert-hh commented 2 years ago

What is the output of:

import board dir(board)

Kratos800 commented 2 years ago

code.py output:

Code done running.

robert-hh commented 2 years ago

That#s not the output of the dir(). Try:

import board print(dir(board)).

Kratos800 commented 2 years ago

code.py output: ['class', 'name', 'A0', 'A1', 'A2', 'A3', 'GP0', 'GP1', 'GP10', 'GP11', 'GP12', 'GP13', 'GP14', 'GP15', 'GP16', 'GP17', 'GP18', 'GP19', 'GP2', 'GP20', 'GP21', 'GP22', 'GP23', 'GP24', 'GP25', 'GP26', 'GP26_A0', 'GP27', 'GP27_A1', 'GP28', 'GP28_A2', 'GP3', 'GP4', 'GP5', 'GP6', 'GP7', 'GP8', 'GP9', 'LED', 'SMPS_MODE', 'VBUS_SENSE', 'VOLTAGE_MONITOR', 'board_id']

robert-hh commented 2 years ago

So no I2C in the list. You have toi get the I2C object from another class. As far as I recall, it's busio. See https://docs.circuitpython.org/en/latest/shared-bindings/busio/ SCL and SDA are PIN objects of the pins, to which the device is connected. Please consult the documentation for further details. Pin handling is in the digitalio class.

Kratos800 commented 2 years ago

I tried with the busio but i am already using it for bmp280 sensor.

robert-hh commented 2 years ago

I2C is a multi-device bus. You can connect multiple devices to it, as long as the device addresses are different.

Kratos800 commented 2 years ago

This is the code in my main file it is in true loop uv_raw = UV.uv_raw print(uv_raw)

this is the code of the sensor (veml6070)

import code import adafruit_veml6070

i2c = code.I2C()

uv = adafruit_veml6070.VEML6070(i2c) uv_raw = uv.read

when i run the code in the main file it shows AttributeError: 'module' object has no attribute 'uv_raw'

robert-hh commented 2 years ago

What is UV? How is it defined? Please make yourself familiar with the the scoping rules of Pyhton.