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.
If you are on Linux:
$ luarocks install sgp30
Otherwise, you can use the Lua module from within a Go app via glua-periphery.
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
...
local periphery = require 'periphery'
local sgp30 = require 'sgp30'
local device = 0x58
local i2c = periphery.I2C('/dev/i2c-1')
assert(sgp30.measureTest(i2c, device))