极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14933|回复: 2

关于2块GY-30同时显示的问题

[复制链接]
发表于 2016-9-14 23:58:40 | 显示全部楼层 |阅读模式
本帖最后由 smyhz 于 2016-9-15 00:00 编辑

想用2个GY-30做个光照比较,但是改BH1750程序时,无法加入第二个BH1750
程序如下
//VCC-5v
//GND-GND
//SCL-SCL(A5)
//SDA-SDA(A4)
//ADD-GND     ADD接VCC为0x5c ADD接GND为0x23
//*/
#include "Wire.h"
#include "math.h"
int BH1750address1 = 0x23;//BH1750 I2C地址、
int BH1750address2 = 0x5c;
byte buff[2];
void setup()
{
  Wire.begin();
  Serial.begin(9600);
}
void loop()
{
  Serial.print( BH17501() );
  Serial.print( “/” );
  Serial.print( BH17502() );
  Serial.println("[lx]");
}
double BH17501() //BH1750设备操作
double BH17502()
{
  int ia = 0;
  int ib = 0;
  double vala = 0;
  double valb = 0
                //开始I2C读写操作
  Wire.beginTransmission(BH1750address1);
  Wire.beginTransmission(BH1750address2);
  Wire.write(0x10);//1lx reolution 120ms//发送命令
  Wire.endTransmission();
  delay(200);
  //读取数据
  Wire.beginTransmission(BH1750address1);
  Wire.beginTransmission(BH1750address2);
  Wire.requestFrom(BH1750address1, 2);
  Wire.requestFrom(BH1750address2, 2);
  while (Wire.available()) //
  {
    buff[ia] = Wire.read(); // receive one byte
    buff[ib] = Wire.read();
    ia++;
    ib++;
  }
  Wire.endTransmission();
  if (2 == ia)
  {
    vala = ((buff[0] << 8) | buff[1]) / 1.2;
  }
  return vala;
  if (2 == ib)
  {
    valb = ((buff[0] << 8) | buff[1]) / 1.2;
  }
return vala;

}
主要是看不懂BH1750()是从double里读取的还是其他地方读出来的
问题简介如下

gy-30:24: error: expected initializer before 'double'

double BH17502()

^

exit status 1
expected initializer before 'double'
谢谢各位大神了
回复

使用道具 举报

 楼主| 发表于 2016-9-26 15:29:13 | 显示全部楼层
好吧,没人回。。。
研究了好久终于弄好了
顺便发发
#include "Wire.h" //IIC库
#include "math.h"
int BH1750address1 = 0x23;//芯片地址为16位23
int BH1750address2 = 0x5c;
byte buff[2];

void setup()
{
  Wire.begin();
  Serial.begin(9600);

}

void loop()
{
  int ia;
  int ib;
  int sumcd;
  uint16_t vala = 0;
  uint16_t valb = 0;
  BH1750a_Init(BH1750address1);
  BH1750b_Init(BH1750address2);
  delay(1000);
  if (2 == BH1750a_Read(BH1750address1))
  {
    vala = ((buff[0] << 8) | buff[1]) / 12 - 3;

  }
  if (2 == BH1750b_Read(BH1750address2))
  {
    valb = ((buff[0] << 8) | buff[1]) / 12;


  }

delay(150);
Serial.print(vala, DEC);
Serial.print("/");
  Serial.print(valb, DEC);
Serial.println("[lx]");


}
int BH1750a_Read(int address1) //
{
  int ia = 0;
  Wire.beginTransmission(address1);
  Wire.requestFrom(address1, 2);
  while (Wire.available()) //
  {
    buff[ia] = Wire.read();  // read one byte
    ia++;
  }
  Wire.endTransmission();
  return ia;
}
int BH1750b_Read(int address2) //
{
  int ib = 0;
  Wire.beginTransmission(address2);
  Wire.requestFrom(address2, 2);
  while (Wire.available()) //
  {
    buff[ib] = Wire.read();  // read one byte
    ib++;
  }
  Wire.endTransmission();
  return ib;
}


void BH1750a_Init(int address1)
{
  Wire.beginTransmission(address1);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();
}
void BH1750b_Init(int address2)
{
  Wire.beginTransmission(address2);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();
}
回复 支持 反对

使用道具 举报

发表于 2018-5-31 22:14:30 | 显示全部楼层
请问这个芯片地址是怎么确定的?我很想请教下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-23 14:44 , Processed in 0.045981 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表