Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active February 15, 2022 13:31
Show Gist options
  • Select an option

  • Save ksasao/506823250a4dd8196de3098f8ad9feb3 to your computer and use it in GitHub Desktop.

Select an option

Save ksasao/506823250a4dd8196de3098f8ad9feb3 to your computer and use it in GitHub Desktop.
Renesas FS3000 monitor with PCA9548AP. See https://twitter.com/ksasao/status/1493564005017059329
#include <M5StickCPlus.h>
#define PCA9548AP_I2C_ADDRESS 0x70
void setup()
{
M5.begin();
Wire.begin();
}
uint8_t selectI2CPort(uint8_t channel){
Wire.beginTransmission(PCA9548AP_I2C_ADDRESS);
uint8_t returnCode = Wire.endTransmission();
if(returnCode == 0){
Wire.beginTransmission(PCA9548AP_I2C_ADDRESS);
uint8_t ch = 1;
ch = ch << (channel&7);
Wire.write(ch);
returnCode = Wire.endTransmission();
}
return returnCode;
}
int readFS3000(uint8_t channel){
int flow = -1;
// Check PCA9548AP (I2C multiplexer)
uint8_t returnCode = selectI2CPort(channel);
if(returnCode == 0){
// Check FS3000 (flow sensor)
Wire.beginTransmission(0x28);
returnCode = Wire.endTransmission();
if(returnCode==0){
Wire.requestFrom(0x28, 5, true);
uint8_t b1 = Wire.read();
uint8_t b2 = Wire.read();
uint8_t b3 = Wire.read();
uint8_t b4 = Wire.read();
uint8_t b5 = Wire.read();
flow = ((b2&0x0F) << 8) | b3;
}
}
return flow;
}
void loop()
{
for(uint8_t i =0; i<3; i++){
Serial.print(readFS3000(i));
Serial.print(",");
}
Serial.println();
delay(100);
M5.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment