Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Python Library for Raspberry Pi #4

Closed
cpietsch opened this issue Jan 28, 2021 · 7 comments
Closed

Python Library for Raspberry Pi #4

cpietsch opened this issue Jan 28, 2021 · 7 comments
Assignees
Labels
Seeed_Arduino_MultiGas Label for Seeed_Arduino_MultiGas UAY Unassigned yet

Comments

@cpietsch
Copy link

It would be great to have a Python Library for Raspberry Pi.
On the Grove Website it says: "To Do" for Platform Raspberry Pi.

Any news on that topic ?

@fdiazsmith
Copy link

Or at least a proper documentation of the I2C registers?

@cpietsch
Copy link
Author

after fiddling with the bme680 and its software, I doubt that without proper computing these sensors won't yield plausible results

@elloza
Copy link

elloza commented Jan 19, 2023

Has anyone made any progress on this?
I'm looking for how to port it but it's a bit difficult without the register information.

I have only found the following but it does not seem to work:
Python port

@elloza
Copy link

elloza commented Jan 19, 2023

This is what I have managed so far by looking at the Arduino code but I am not able to make it work.

import time
import smbus2
import struct

class GAS_GMXXX:
    GM_102B = 0x01
    GM_302B = 0x03
    GM_502B = 0x05
    GM_702B = 0x07
    CHANGE_I2C_ADDR = 0x55
    WARMING_UP = 0xFE
    WARMING_DOWN = 0xFF
    GM_VERF = 3.3
    GM_RESOLUTION = 1023

    def __init__(self, bus, address):
        self.bus = smbus2.SMBus(bus)
        time.sleep(1)
        self.address = address
        self.is_preheated = False

    def write_byte(self, cmd):
        self.bus.write_byte(self.address, cmd)

    def read_32(self):
        data = self.bus.read_i2c_block_data(self.address, 0, 4)
        return struct.unpack('>I', bytes(data))[0]

    def preheat(self):
        self.write_byte(GAS_GMXXX.WARMING_UP)
        self.is_preheated = True

    def un_preheat(self):
        self.write_byte(GAS_GMXXX.WARMING_DOWN)
        self.is_preheated = False

    def get_gm102b(self):
        if not self.is_preheated:
            self.preheat()
        self.write_byte(GAS_GMXXX.GM_102B)
        return self.read_32()

    def get_gm302b(self):
        if not self.is_preheated:
            self.preheat()
        self.write_byte(GAS_GMXXX.GM_302B)
        return self.read_32()

    def get_gm502b(self):
        if not self.is_preheated:
            self.preheat()
        self.write_byte(GAS_GMXXX.GM_502B)
        return self.read_32()

    def get_gm702b(self):
        if not self.is_preheated:
            self.preheat()
        self.write_byte(GAS_GMXXX.GM_702B)
        return self.read_32()

    def change_address(self, new_address):
        self.write_byte(GAS_GMXXX.CHANGE_I2C_ADDR)
        self.write_byte(new_address)
        self.address = new_address

    def calc_vol(self, adc):
        return adc * self.GM_VERF / (self.GM_RESOLUTION * 1.0)

Any help would be welcome.

Thank you very much!

@elloza
Copy link

elloza commented Jan 20, 2023

@cpietsch or someone, please, could you test if my code works with the sensor if you have one?

I am trying to test with the sensor I have but the example in Arduino always gives me all the values at 0.

The same thing that happens to this user:

SeeedStudioForum

I don't understand anything, I don't know if the sensor directly doesn't work or what happens.

@atsclct
Copy link

atsclct commented Mar 17, 2023

Try code under:
https://github.com/atsclct/atsc_sensors
two versions of python code work for raspberry pi and pico respectively.

@brmmm3
Copy link

brmmm3 commented Mar 18, 2023 via email

@MatthewJeffson MatthewJeffson added UAY Unassigned yet Seeed_Arduino_MultiGas Label for Seeed_Arduino_MultiGas labels Oct 9, 2024
@Lesords Lesords self-assigned this Oct 14, 2024
@baorepo baorepo closed this as completed Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Seeed_Arduino_MultiGas Label for Seeed_Arduino_MultiGas UAY Unassigned yet
Projects
Status: Done
Development

No branches or pull requests

8 participants