Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/abserari/jx-co2-101-sensor


https://github.com/abserari/jx-co2-101-sensor

Last synced: 1 day ago
JSON representation

Awesome Lists containing this project

README

        

# jx-co2-101-sensor

## Preview
![image](https://user-images.githubusercontent.com/32089134/107248353-2df5e000-6a6d-11eb-910e-34affce080ea.png)

## Sensor code
树莓派 Raspberry model 3B+ 和 JX-CO2-101 传感器. [更多文档](https://www.yuque.com/abser/solutions/telmsy)

```go
package main

import (
"log"
"time"

. "github.com/abserari/jx-co2-101-sensor"
"github.com/tarm/serial"
)

// pi3 should open uart and communicate with device: /dev/ttyAMA0 | /dev/serial0
func main() {
c := &serial.Config{Name: "/dev/ttyAMA0", Baud: 9600, ReadTimeout: time.Second * 5}
s, err := serial.OpenPort(c)
if err != nil {
log.Fatal(err)
}

sensor := NewCO2Sensor(s)
sensor.SendActiveModeChange()

// go func() {
// for {
// sensor.SendQuery()
// time.Sleep(3 * time.Second)
// }
// }()
for {
data, _, err := sensor.ReadLine()
if err != nil {
LogError(err)
}
value, err := ReadData(data)
LogInfo(value)
}

}
```

![](https://cdn.nlark.com/yuque/0/2021/png/176280/1612499197873-7c58f77f-f8b9-40a5-8061-1aeb4f9ba4e8.png)
![](https://cdn.nlark.com/yuque/0/2021/png/176280/1612496135723-4376f1f6-188e-45a3-b9de-beea7f2761e3.png)
![](https://cdn.nlark.com/yuque/0/2021/png/176280/1612599825170-64b0b09a-d041-4ade-a2fc-15066d385df9.png)