Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abserari/jx-co2-101-sensor
https://github.com/abserari/jx-co2-101-sensor
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/abserari/jx-co2-101-sensor
- Owner: abserari
- License: mit
- Created: 2021-02-06T06:58:24.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-08T16:25:09.000Z (almost 4 years ago)
- Last Synced: 2024-11-24T17:13:28.656Z (about 2 months ago)
- Language: Go
- Size: 71.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 mainimport (
"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)