Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

Inputs: values on the input pins are changing automatically

918 Views - Created 17/11/2020

17/11/2020

Posted by:
jozegorisek2

jozegorisek2 Avatar

As the title mentions, we are having some issues with ExpanderPI inputs, let me describe it a bit more in detail:
We are using NodeJS ExpanderPI's library, which we wrapped with out helper class, the whole code related to the ExpanderPI is available here:
https://pastebin.com/BXYbtZ33

The basic idea about our proble is to read values from the pins. All the pins are set as input pins, on 3 of them we have buttons, where we want to track when they are being pressed.

Once the input of the button is changed, it's being detected and "inputPinChanged" is being called accordingly. Everything works as expected. After some time we notice, that the value of the inputs automatically changes, even though the button isn't pressed. It even happens for all the other pins that are unused which is super weird.

We are running this on RPI4 and the latest version of Raspberry OS:


Release date: August 20th 2020
Kernel version: 5.4


Would really appreciate if you could help out on this one or have any idea at all that could point us into the right direction.

17/11/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hello

Your initInputs() function is only setting the first pin on each port as an input.

The setPortDirection function takes an 8-bit value between 0 and 255 for the second parameter. Each bit within the number represents one of the pins on the selected port so for example if you wanted to set pin 3 as an input and the other pins as outputs you would write 0b00000100 or 4 to the port. As you want all of the pins to be inputs you need to use setPortDirection(0, 255); and setPortDirection(1, 255); setInterruptType() works in the same way so you need to write 255 instead of 1 to each port.

Try changing your function to the code below and see if this helps.


initInputs() {
    this.expanderIO.setPortDirection(0, 255);
    this.expanderIO.setPortDirection(1, 255);
    this.expanderIO.setInterruptType(0, 255);
    this.expanderIO.setInterruptType(1, 255);
    this.startListening();
}


On your inputs do you have pull-down resistors connected between the input and ground?

When using buttons if they are connected to 5V you will need pull-down resistors connected to ground so the input is pulled to 0V when the button is not pressed.

If the button is connected to ground you need pull-up resistors connected to 5V to pull the input high when the button is not pressed.

Without any pull-down or pull-up resistors when the button is open the input will be left in a floating state where it is neither at 0V nor 5V. When the input is floating any stray capacitance or noise on the input wire can cause the input to register a change in state which could be the cause of your problems.

17/11/2020

Posted by:
jozegorisek2

jozegorisek2 Avatar

Hi andrew, thanks for a quick reply!

First of all thank you for mentioned that issue, will fix port direction for all of the pins.

As for the schematics, we are using the following example - the bottom part of the image:
- buttons are directly supplied with 5V

- the button "output" is directly connected to the input pin (without resistor)

- there is another wire going from the button "output" to GND, we are using 100k resistor there

As mentioned, there is no resistor between input pin and button.


forum image

17/11/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Your button circuit should be correct. Hopefully changing the code will fix the issue.

17/11/2020

Posted by:
jozegorisek2

jozegorisek2 Avatar

Thanks again for all the help. I'll be back in touch once I test this out, first thing in the morning!

18/11/2020

Posted by:
jozegorisek2

jozegorisek2 Avatar

Andrew,

currently testing with the changes to the code you suggested, will take some time to see if any random inputs are appearing.

We do have another problem however.. We are using BME680 sensor for temperature, humidity and air pressure which also communicates over i2c. Some time ago we were having issues using both ExpanderPi and BME at the same time because they were unable to work at the same time. Someone from ABE suggested that we rewrite the logic of BME into ExpanderPI, so we use it out of the same scope. We did that but it seems that BME and ExpanderPI are stil unable to cooperate. I am attaching expanderpi.js lib file we modified if you want to check that out. (basically just added another module for BME). https://pastebin.com/xZ4E2tYA

The problem is that when BME is connected and the app is started, ExpanderPI isn't receiving any inputs at all. Once the sensor is disconnected, the buttons are working normally. Any idea on what could be the reason for this?

18/11/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

When the BME sensor is connected can you run "sudo i2cdetect-y 1" and see if the sensor and expander pi are showing up on the I2C bus? The Expander Pi should appear on addresses 0x20 and 0x68, the BME680 should be on address 0x76.

If the Expander Pi or BME680 do not appear on the i2c bus when connected together try them individually and see if they show up.

If both devices appear on the I2C bus that means the problem is most likely software related. If they don't appear then it is a hardware issue.

18/11/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Is your BME680 sensor on a module PCB or have you made a custom PCB for the sensor? If it is a module please can you let me know which one you are using and I will order one to test with an Expander Pi.

Also, are you using the version 1 Expander Pi with the 26-pin GPIO header or version 2 with the 40-pin GPIO header?

18/11/2020

Posted by:
jozegorisek2

jozegorisek2 Avatar

Hi Andrew,

first of all reporting back to let you know, that the software suggestion you provided did not resolve our issue with input buttons. The problems still remain as input randomly changes from 0 to 1 or the opposite.

We are using ExpanderPI version 2, with 40pin header. Our BME sensor is directly soldered to GPIO pins on the ExpanderPI module (5V, SDA, SCL, GND).

Sorry I will test the suggestions you posted in the next week since we are in a rush to roll this project out of the office. For now we resolved the issues like this: instead of using ExtenderPI inputs, we are using GPIO pins from the header and disabled ExpanderPI pins (disabled meaning we are not using them as inputs). BME is working alright and the buttons also work like a charm using rpio library. For now we have to go with this option, will have to investigate the issues with ExpanderPI later.



Thanks for all the help!

Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.