5180 views|3 replies

6062

Posts

4

Resources
The OP
 

[Review of SGP40] + Testing the sensor I2C communication with Arduino [Copy link]

This post was last edited by damiaa on 2021-3-2 08:43

[Review of SGP40] + Testing the sensor I2C communication with Arduino

It was easy to test SVM40 I2C communication with Arduino, but it took some time.

1. Download the arduino-snippets-main package and unzip it.

2. Use the example in \arduino-snippets-main\arduino-snippets-main\SVM40_I2C_minimal_example.

3. Prepare to connect the circuit, connect the sensor board VCC GND to the stm32F767 board VCC ground, 3-pin SDA to PB8, 4-pin SCL PB9, 5-pin to ground

4. Connect 4.7K pull-up resistors to PB8 and PB9. Remember, otherwise the data will remain unchanged.

5,打开\arduino-snippets-main\arduino-snippets-main\SVM40_I2C_minimal_example

6. Open SVM40_I2C_minimal_example.ino with arduino1.8.13

Note that the stm32duino package has been installed here. For details, please see my post Let Arduino play with your useless stm32 board.

7. Change the I2C clock to 100K . The details are as follows

#include <Wire.h>
// SVM40
const int16_t SVM40_ADDRESS = 0x6A;
void setup() {
 Serial.begin(115200);
 // wait for serial connection from PC
 // comment the following line if you'd like the output
 // without waiting for the interface being ready
 while(!Serial);
 // output format
 Serial.println("VOC_Index\tRH\tT");
 // init I2C
 Wire.setClock(100000L);//修改I2C时钟 据说模块最多100K
 Wire.begin();
 // wait until sensors startup, > 1 ms according to datasheet
 delay(1);
 // start up sensor, sensor will go to continous measurement mode
 // each second there will be new measurement values
 Wire.beginTransmission(SVM40_ADDRESS);
 Wire.write(0x00);
 Wire.write(0x10);
 Wire.endTransmission();
 // wait until sensors is ready, fan is initialized
 delay(1000);
}
void loop() {
 uint16_t voc, humidity, temperature;
 uint8_t data[9], counter;
 // read measurement data
 Wire.beginTransmission(SVM40_ADDRESS);
 Wire.write(0x03);
 Wire.write(0xA6);
 Wire.endTransmission();
 // wait 5 ms to allow the sensor to fill the internal buffer
 delay(5);
 // read measurement data svm40, after two bytes a CRC follows
 Wire.requestFrom(SVM40_ADDRESS, 9);
 counter = 0;
 while (Wire.available()) {
  data[counter++] = Wire.read();
 }
 // VOC level is a signed int and scaled by a factor of 10 and needs to be divided by 10
 // humidity is a signed int and scaled by 100 and need to be divided by 100
 // temperature is a signed int and scaled by 200 and need to be divided by 200
 voc = (uint16_t)data[0] << 8 | data[1];
 humidity = (uint16_t)data[3] << 8 | data[4];
 temperature = (uint16_t)data[6] << 8 | data[7];
 Serial.print(String(float(voc) / 10));
 Serial.print("\t");
 Serial.print(String(float(humidity) / 100));
 Serial.print("\t");
 Serial.print(String(float(temperature) / 200));
 Serial.println();
 delay(1000);
}

8. Compile and download. Run.

The results are out, 24.8 degrees tonight

This post is from Sensor

Latest reply

Haha, this operation of flying resistors in the air is quite interesting. I have used this method before!   Details Published on 2021-3-3 19:40

赞赏

1

查看全部赞赏

 
 

6555

Posts

0

Resources
2
 

You can also play like this, use the stm32duino installation package

Thanks for sharing

This post is from Sensor
 
 
 

6062

Posts

4

Resources
3
 
Jacktang posted on 2021-3-2 14:04 You can also play like this, using the stm32duino installation package. Thanks for sharing.

Yes, it is very convenient. You can play with the board in your hand.

This post is from Sensor
 
 
 

1942

Posts

2

Resources
4
 

Haha, this operation of flying resistors in the air is quite interesting. I have used this method before!

This post is from Sensor
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list