Coder Social home page Coder Social logo

lua-sgp30's Introduction

SGP30 Lua driver

A lua-periphery based driver for the SGP30 air quality sensor.

The SGP30 requires a delay between making a request and reading a response, which is why a luasocket dependency exists for its sleep capability.

Installing

If you are on Linux:

$ luarocks install sgp30

Otherwise, you can use the Lua module from within a Go app via glua-periphery.

Usage

Measure Air Quality

Note that this particular sensor must be asked to perform measurements at 1-second intervals for at least 15 seconds before it begins to function.

local periphery = require 'periphery'
local sgp30 = require 'sgp30'
local socket = require 'socket'

local device = 0x58

local i2c = periphery.I2C('/dev/i2c-1')
sgp30.initAirQuality(i2c, device)
for i = 1, 20 do
	local co2PPM, vocPPB = sgp30.measureAirQuality(i2c, device)
	print(string.format('--------------------------:---------'))
	print(string.format('Carbon Dioxide            : %4i PPM', co2PPM))
	print(string.format('Volatile Organic Compounds: %4i PPB', vocPPB))
	socket.sleep(1)
end

Sample output, obtained by waiting for 15 seconds, then breathing on the sensor:

...
--------------------------:---------
Carbon Dioxide            : 400 PPM
Volatile Organic Compounds:   0 PPB
...
--------------------------:---------
Carbon Dioxide            :  400 PPM
Volatile Organic Compounds:    0 PPB
--------------------------:---------
Carbon Dioxide            :  406 PPM
Volatile Organic Compounds:    1 PPB
--------------------------:---------
Carbon Dioxide            : 1409 PPM
Volatile Organic Compounds:   68 PPB
--------------------------:---------
Carbon Dioxide            : 2710 PPM
Volatile Organic Compounds:  147 PPB
...

"Press to test" sensor self-test

local periphery = require 'periphery'
local sgp30 = require 'sgp30'

local device = 0x58

local i2c = periphery.I2C('/dev/i2c-1')
assert(sgp30.measureTest(i2c, device))

lua-sgp30's People

Contributors

drauschenbach avatar mikegray avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.