i2c pyb or machine for sgp30 adafruit sensor?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Sat May 09, 2020 6:58 am

Hi,
I have tried to use the sgp30 sensor from adafruit... with a pyboard.
So, I have download the sgp30 lib from github, which indicate a procedure of installation with a i2c.MASTER command, and after, when the sensor is initiated, have to accept a "writeto" command.
I have use the i2c's machine installation without success. With Master parameter error...
The same issue with pyb's i2c. With writeto command error...
So, i2c'pyb accept master parameter but not writeto command, and i2c'smachine accept writeto command but not master parameter...

I don't know well i2c behaviour....
Maybe there is a simple way for resolve it...

Thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by pythoncoder » Sat May 09, 2020 10:46 am

I suggest you use the machine library and eliminate the i2c.MASTER arg. Slave mode is not supported by machine, so the argument is not accepted.
Peter Hinch
Index to my micropython libraries.

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Sat May 09, 2020 1:35 pm

Hi Peter,

Thanks for your availability.

I have tried yet a command with i2cmachine without master parameter, but it doesn't works. The sensor isn't initiate on i2c canal.
I have tried too this solution : viewtopic.php?f=6&t=3250&p=24707&hilit= ... ine#p24707. It doesn't work too.
I have tried other i2cmachine command's write, alls without success.

When I used pyb, the sensor looks initiate correctly on i2c canal. I have his i2c adress. But when I tried to initiate the object, I have the "writeto" error.

So maybe I could try to replace "i2cmaster" by "i2c" in the sensor library?
Or change "i2c.writeto" by "write.mem_write" and use pyb librarie?
...?
I will try ...

Thanks for your support.
Best.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by pythoncoder » Sun May 10, 2020 10:23 am

It would help if you gave us a link to the library you are using.
Peter Hinch
Index to my micropython libraries.

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Tue May 12, 2020 9:38 am

Hi,

I use the only one library that I have found for sgp30 and micropython:
https://github.com/alexmrqt/micropython-sgp30
... Maybe you have an other one which wok fine, like for uv sensor that I can use now until I have found a good advise in this forum about this uv sensor, which need an other libarary than the first one that I have found about SI1145 sensor and micropython.

Thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by pythoncoder » Wed May 13, 2020 6:03 am

That driver has evidently been adapted from the Adafruit one to work with MicroPython. At a glance the driver itself looks plausible, but the test program looks wrong. Aside from the I2C.MASTER which should be eliminated, the I2C bus number of 0 is wrong. Pyboard I2C buses are numbered 1 and 2.
Peter Hinch
Index to my micropython libraries.

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Fri May 15, 2020 6:19 am

Hi,

Yes for sure.

So, how can I change this sgp30 lib for that it works with a pyboard?

Thanks.

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Wed Jun 17, 2020 10:39 am

Hi,

I'm trying to change sgp30 library... I have choiced the machine library of i2c wich contain commands more closed of circuit python's library...

First, I have had a problem with "featuerset part" which return error.
So I have changed "self.__i2c = i2c" in the init part of circuit python's library, by "self.__device". Now I have a problem with "self._i2c_read_words_from_cmd" . This command looks not beeing in micropython language...

So, is there anybody who know how change this "i2c_read_words_from_cmd" 's circuit python, by a micropython i2c's machine command?

Thanks.

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Wed Jun 17, 2020 5:49 pm

Yes!

I have got it!!!!

For that everything woks fine with sgp30 and the micropython library at https://github.com/alexmrqt/micropython ... t_sgp30.py on pyboard...

1- First change on library:
"_SGP30_FEATURESET = const(0x0020)" by "_SGP30_FEATURESET = const(0x0022)"

2-For initiate correctly on pyboard:

Code: Select all

import sgp302
from machine import I2C

i2c = I2C(scl='Y9', sda='Y10', freq=100000)

sgp = sgp302.Adafruit_SGP30(i2c)
It looks simple but I have passed all this day on this.
Finally, not for nothing...

Enjoy!

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

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by IHOXOHI » Wed Jun 17, 2020 7:34 pm

a simple example with lcd160cr, for my poor pollued town...

Code: Select all

import sgp30
from machine import I2C
import lcd160cr
from time import sleep

lcd = lcd160cr.LCD160CR('X')
lcd.set_orient(lcd160cr.LANDSCAPE)
lcd.set_font(1, scale=1)

i2c = I2C(scl='Y9', sda='Y10', freq=100000)

sgp = sgp30.Adafruit_SGP30(i2c)


while True:

    co2eq, tvoc = sgp.iaq_measure()
    print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))

    if co2eq <= 800 and tvoc <= 500:
        lcd.set_text_color(lcd.rgb(0, 0, 255), lcd.rgb(0, 0, 0))
    if co2eq >= 800 or tvoc >= 500:
        lcd.set_text_color(lcd.rgb(0, 255, 0), lcd.rgb(0, 0, 0))
    if co2eq >= 1200 or tvoc >= 1000:
        lcd.set_text_color(lcd.rgb(255, 0, 0), lcd.rgb(0, 0, 0))

    co2eq = str(co2eq)
    tvoc = str(tvoc)

    lcd.erase()
      
    lcd.set_pos(5, 15)
    lcd.write('CO2eq = ')
    lcd.set_pos(100, 15)
    lcd.write(co2eq)
    lcd.set_pos(5, 60)
    lcd.write('TVOC = ')
    lcd.set_pos(90, 60)
    lcd.write(tvoc)

    sleep(1)


    




Post Reply