RPM Load cell and OLED conflict

Hi.
Trying to put together a unit to test the thrust and RPM on Brushless motors.
The code for the RPM using a standard IR transmitter receiver code works with the OLED and is displaying the correct information on the OLED.
And the code for the Load cell and HX711 works as expected with the OLED.
The issue I an having is :- After combining the codes together all works as it should. OLED display the height and the Load cell is working.
But as soon as I trigger the IR unit the Arduino Nano reboots.


Circuit Above.
SH1106_128x64_i2c_and_load_cell_RPM.ino (3.4 KB)
The code is from various sources as described in header off Code.

The IR input uses a interrupt on Pin 2.
I have little idea on why the Arduino Nano is rebooting when the IR triggers.
Any help with this would be helpful.

Not sure if I have uploaded the picture and Sketch OK ...

Regards

A hand drawn sketch, with all connections clearly labeled, is much preferred over Fritzing diagrams.

The reboot could be due to a wiring error. Double check all connections, and verify that each module works independently of the others.

Or, you might be overloading the 5V pin in the Arduino. The output of that pin is very limited, so use a regulated 5V supply instead. Be sure to connect all the grounds.

1 Like

Thanks for the reply.
Ok I remade the circuit on another board. No Difference. Checked the wiring.
I used a wall socket 5V 2Amp supply to see if this makes any difference. None.
Removed the HX711 from the circuit. Still reboots when IR triggered.
Reloaded the IR and OLED sketch and that worked OK.
Not sure what to check next.... Edited: Replaced the Arduino Nano with new one. and replaced the IR sensor unit. No change.
Regards.

I cannot read the fuzzy picture, it is useless to me. As jremington post a proper schematic showing how you have it wired and links to technical information on all the hardware items.

A variable used in both an ISR and the main code should be declared volatile. Yours isn't. Read about interrupts here: Gammon Forum : Electronics : Microprocessors : Interrupts That may not be the source of your problem, but you should fix it.

And, you aren't changing the scale calibration factor, so why reset the scale every time through loop()? Move calibration to setup(). Also probably not the source of reboot.

Some HX711 libraries disable interrupts when doing a read, which could screw up your rpm readings. And if the HX711 lib blocks until a reading is ready, as many do, that may also be a problem. Hard to imagine either causing a reboot, but who knows. You could try the following "libraryless" code, but first modify it so it doesn't block (edit to add: since you have a delay(1000) in loop, there will be plenty of time for an HX711 reading to become ready, so the following could be used as-is).

2nd edit to add that this..

...is a bit hard to believe, since the combined code you linked to doesn't include the usual HX711 code to set up the device. Please post the "code for the load cell and HX711 that works as expected." To make it simple for us, put it between code tags and not as a linked document. Use this button...
image

HX711 library-less code:

  unsigned long count = 0;

  while(digitalRead(pinDAT));  // wait (block) until goes low (occurs when data is ready)

  for(byte i=0;i<24;i++)            // get 24 bits, MSB first
  {
    digitalWrite(pinCLK, HIGH);   
    count=count<<1; 	          // shift left, zero goes into LSB; 1st time thru just shifts all zeros
    digitalWrite(pinCLK, LOW); 
    if(digitalRead(pinDAT))  count++;   // read a bit; if high, change count LSB from 0 to 1
  }
  digitalWrite(pinCLK, HIGH);     // set channel A w/ 128 gain
  count=count^0x800000;         // see notes below
  digitalWrite(pinCLK, LOW);     // leave low
  // count will be...
  // min = 0
  // mid-point = 8,388,608 <-- no load raw value on scale with zero offset
  // max = 16,777,215

Your diagram does not show any decoupling on the 5V rail. Perhaps triggering the IR unit is causing a brownout?

There has been a few comments about the drawing. Its drawn with Paint with a size of 1776X928 pixels. This looks clear to me. But OK. Will do next time. BTW it is NOT Fuzzy.

Hi DaveEvans.
Both the RPM and the Thrust are working fine before combining the code.

The Load cell code.



#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

#include "HX711.h"
#define DOUT  4
#define CLK  3
HX711 scale(DOUT, CLK);
float weight;
float calibration_factor = 676750; // for me this value works just perfect

/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1   //   QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000
};

void setup()   {

  Serial.begin(57600);
  scale.set_scale();
  //scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading

  delay(250); // wait for the OLED to power up
  display.begin(i2c_Address, true); // Address 0x3C default
  //display.setContrast (0); // dim display

  display.display();
  delay(2000);

  // Clear the buffer.
  display.clearDisplay();
}
void loop() {
  scale.set_scale(calibration_factor); //Adjust to this calibration factor
  display.display();
  delay(1000);
  display.clearDisplay();
  display.setCursor(0, 25);
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.print("Reading: ");
  weight = scale.get_units(5);
  display.print("Kg ");
  display.print(weight);

  delay(10);
}

And the IR code.

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1   //   QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

unsigned long rpmtime;
float rpmfloat;
unsigned int rpm;
bool tooslow = 1;

void setup() {
  Serial.begin(9600);
   display.begin(i2c_Address, true); // Address 0x3C default
   display.display();
  delay(2000);

  // Clear the buffer.
  display.clearDisplay();
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1B |= (1 << CS12); //Prescaler 256
  TIMSK1 |= (1 << TOIE1); //enable timer overflow
  pinMode(2, INPUT);
  attachInterrupt(0, RPM, FALLING);
}

ISR(TIMER1_OVF_vect) {
  tooslow = 1;
}

void loop() {
display.display();
  delay(1000);
display.clearDisplay();
display.setCursor(0, 0);
display.setTextSize(2);
  display.setTextColor(SH110X_WHITE);
 
  if (tooslow == 1) {
   display.print("Too Slow");
  }
  else {
    rpmfloat = 120 / (rpmtime/ 31250.00);
    rpm = round(rpmfloat);
    display.print("RPM = ");
    display.setCursor(0, 15);
    display.print(rpm);
  }
}

void RPM () {
  rpmtime = TCNT1;
  TCNT1 = 0;
  tooslow = 0;
}

Johnerrington.
The power supply does have a decoupling circuit in.

Thanks for the inputs.
Regards.

Thx. Which of the many available HX711 libraries are you using?

Hi Dave.
The one by Rob Tillaart .
That is downloadable vis the Library manager.
Thanks.

Hmmm. Not sure about that, since Rob T's examples all have a format different than yours:

#include "HX711.h"
HX711 scale;

and then in setup()

scale.begin(dataPin, clockPin);

But whatever... Rob T's library (as well as the Bogde library, also downloadable via LibMan, and perhaps others), do disable interrupts when reading the HX711. That may occasionally screw up your rpm reading, as noted in post #5.

So, the first three points/suggestions of post #5 are still valid. Suggest you fix/try them.

Also, when you read or write to TCNT1 (which you do in RPM), the 328p datasheet says you must disable interrupts (see page 116 thru 118 of the datasheet...page nums based on October 2009 edition). So do that.

Thank you.
I think you are on to something there. Will look at this later on when time permits.
Cheers M8

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