Hall Effect Sensor with I2C Sensor

Hello everyone,

I recently created my first custom PCB, producing what is essentially an Arduino pro mini clone with a few devices on the PCB, those being a logic level shifter, LTC4311, DRV2605L, and ms560702ba03-50. Off of the PCB, I also have an adafruit clear turbine water flow sensor. I've been using this library for the pressure sensor using the stock example code here:

/*
    MS5xxx.h - Library for accessing MS5xxx sensors via I2C
    Copyright (c) 2012 Roman Schmitz

    This file is part of arduino-ms5xxx.

    arduino-ms5xxx is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    arduino-ms5xxx is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with arduino-ms5xxx.  If not, see <http://www.gnu.org/licenses/>.

*/

#include <Wire.h>
#include <MS5xxx.h>

MS5xxx sensor(&Wire);

void setup() {
  Serial.begin(9600);
  if(sensor.connect()>0) {
    Serial.println("Error connecting...");
    delay(500);
    setup();
  }
}

void loop() {
  sensor.ReadProm();
  sensor.Readout();
  Serial.print("Temperature [0.01 C]: ");
  Serial.println(sensor.GetTemp());
  Serial.print("Pressure [Pa]: ");
  Serial.println(sensor.GetPres());
  test_crc();
  Serial.println("---");
  delay(500);
}

void test_crc() {
  sensor.ReadProm();
  sensor.Readout(); 
  Serial.print("CRC=0x");
  Serial.print(sensor.Calc_CRC4(), HEX);
    Serial.print(" (should be 0x");
  Serial.print(sensor.Read_CRC4(), HEX);
  Serial.print(")\n");
  Serial.print("Test Code CRC=0x");
  Serial.print(sensor.CRCcodeTest(), HEX);
  Serial.println(" (should be 0xB)");
}

I used a simple interrupt function to use the flow sensor.


int flowPin = 0;
double flowRate;
volatile int count;


void setup() {

pinMode(flowPin, INPUT);
attachInterrupt(2, Flow, RISING);
Serial.begin(9600);
}
void loop() {
  count = 0;
  interrupts();
  delay(100);
  noInterrupts();

  flowRate = (count / 0.5);

  Serial.println(flowRate);

   
}

void Flow(){
  count++;
}

However, the instant I try to use these sensors at the same time, my controller seems to freak out and I have to go through the process for de-bricking the processor found here. I can't even have the text "noInterrupts();" written in the pressure sensor code, or it will brick the processor. Is there something here that I am missing, or is it possible to read the flow sensor without interrupts? Any help is appreciated, thanks.

Please show your code where the two sketches are combined.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

That MS5xxx library has bugs, but it should still work with a ATmega328P.
See this Issue: Wire.requestFrom() should not be followed by Wire.endTransmission(). · Issue #5 · Schm1tz1/arduino-ms5xxx · GitHub
The author does not know how to use the Wire library, he does not fix it, and simply closes the Issue :angry:

Here's the combined sensor code:

#include <Wire.h>
#include <MS5xxx.h>

int flowPin = 0;
double flowRate;
volatile int count;

MS5xxx sensor(&Wire);

void setup() {

  pinMode(flowPin, INPUT);
  attachInterrupt(2, Flow, RISING);

  Serial.begin(9600);
  if(sensor.connect()>0) {
    Serial.println("Error connecting...");
    delay(500);
    setup();
  }
}

void loop() {
  sensor.ReadProm();
  sensor.Readout();
  Serial.print("Temperature [0.01 C]: ");
  Serial.println(sensor.GetTemp());
  Serial.print("Pressure [Pa]: ");
  Serial.println(sensor.GetPres());
  test_crc();
  Serial.println("---");
  delay(250);


  count = 0;
  interrupts();
  delay(100);
  noInterrupts();

  flowRate = (count / 0.5);

  Serial.println(flowRate);
}

void test_crc() {
  sensor.ReadProm();
  sensor.Readout(); 
  Serial.print("CRC=0x");
  Serial.print(sensor.Calc_CRC4(), HEX);
    Serial.print(" (should be 0x");
  Serial.print(sensor.Read_CRC4(), HEX);
  Serial.print(")\n");
  Serial.print("Test Code CRC=0x");
  Serial.print(sensor.CRCcodeTest(), HEX);
  Serial.println(" (should be 0xB)");
}

void Flow(){
  count++;
}

As I mentioned though, even having a single line that disables interrupts is enough to break everything in the pressure sensor code. I've also tried using this library, and had the same issues with the board bricking, so it seems like the library might not be the issue. @Koepel I'm using an ATmega32U4 not a 328p, does that matter?

A Pro Mini is a ATmega328P.
A Pro Micro is a ATmega32U4.
They are both part of the AVR family microcontrollers.

Which pin of the ATmega32U4 is pin 0 on the Pro Micro ? Is that PD2, pin 20 on the chip ?
Would that be interrupt INT2 ? I'm not sure if you can use the number '2' for attachInterrupt().
This is recommended:

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);

I don't see the problem, sorry. Can you use 115200 baud instead of 9600 ? Can you remove the disabling of the interrupt ? If millis() is checked, then the time is known and that can be used in a calculation.
While you are at it, remove also the delay() from the loop().

Hi,
Can you please post a schematic of your project and some jpg EXPORT images of your PCB?

What are you using to power your project?
Do you have capacitive bypassing on your PCB?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.