有幸收到FireBeetle 2 ESP32 C6 板子,先体验下相关性能;
先测试I2C 接口功能:
从FireBeetle 2 ESP32 C6 引脚分别可以知道,I2C 默认是19,20;

再看GY-30 的硬件;
总共有5个引脚,其中ADDR 接到GND则Address 为0x23;
GY-30 板载芯片为BH1750FVI 数字环境光感应芯片,内置16bit 的ADC 进行采样, 可以直接输出lx 的数字,内部框图如图所示;

GY-30 的模组原理图:

将GY-30 与FireBeetle 2 ESP32 C6 通过杜邦线连接起来;(主要ADDRESS 需要与GND连在一起);

软件编写:
软件采用Arduino IDE 和C6 的库,代码如下:
- #include "Wire.h"
- #include "math.h"
-
- int BH1750address = 0x23;
- byte buff[2];
- uint16_t val=0;
-
- void setup() {
- pinMode(15,OUT_PUT);
-
- Serial.begin(115200); //Debug UART
- Serial1.begin(115200); //UART Print
-
- Wire.begin(); //I2C Init
- BH1750_Init(BH1750address);
- }
-
- void loop() {
- int i=0;
-
- if(2 == BH1750_Read(BH1750address))
- {
- if(buff[0]==255 && buff[1]==255)
- {
- val=65535;
- }else{
- val = (buff[0]<<8 | buff[1])/1.2;
- Serial1.print(val,DEC);
- Serial1.println("[lx]");
- }
-
- }
- delay(500);
-
- for (int i=0; i <= 255; i++){
- analogWrite(15, i);
- delay(10);
- }
- Serial.print("helloWorld");
- Serial1.print("123");
- }
-
-
- int BH1750_Read(int address)
- {
- int i=0;
- Wire.beginTransmission(address);
- Wire.requestFrom(address,2);
-
- while(Wire.available())
- {
- buff[i] = Wire.read();
- i++;
- }
- Wire.endTransmission();
- return i;
- }
-
- void BH1750_Init(int address)
- {
- Wire.beginTransmission(address);
- Wire.write(0x10);
- Wire.endTransmission();
- //delay(500);
- }
复制代码
最终显示采用串口1 通过串口工具显示;


最终所得数据:

|