Determine WHICH pin is high

Hey Guys,

I use the Arduino environment for quite a while and I now came to a point where I didn't find anything in the docs.

I wonder if I can get which of the digital pins are set to high without iterating over all digital pins. This would be great, because I've got the following setup:

I'm building a set of big buttons on different boards. Each of them should do almost the same (call a website via wifi). But this website differs depending on which input is used

(e.g.: button one is connected to a microcontroller. So it calls Give yourself a better website » MY DOMAIN if the button is pressed. Button two is connected to another microcontroller via another pin. So it calls Give yourself a better website » MY DOMAIN)

Is this possible to do or do I have to iterate over all digital pins and check for it? For this project I'm planning to use a bunch of ESP8266 boards.

Greeting
bliepp

Have a google of direct port manipulation - you should be able to read multiple ports with one instruction

do I have to iterate over all digital pins and check for it?

Is that such a big deal?

Have a google of direct port manipulation - you should be able to read multiple ports with one instruction

A starter, that shows how to setup and port and further down read several at once :
https://www.google.co.uk/amp/s/hekilledmywire.wordpress.com/2011/02/23/direct-port-manipulation-using-the-digital-ports-tutorial-part-3/amp/

hammy:
Have a google of direct port manipulation - you should be able to read multiple ports with one instruction

A starter, that shows how to setup and port and further down read several at once :
Direct port manipulation, using the digital ports [tutorial part 3] | HeKilledMyWire

Does that cover the 8266?

bliepp:
(e.g.: button one is connected to a microcontroller. So it calls Give yourself a better website » MY DOMAIN if the button is pressed. Button two is connected to another microcontroller via another pin. So it calls Give yourself a better website » MY DOMAIN)

This is a bit confusing.

If there is only one button attached to each ESP8266 then there is no need to iterate over all the pins because you KNOW which pin the button is connected to.

If the problem is that the server needs to know which ESP8266 makes the call then just put an identifier in the message sent by the each ESP8266.

But why you are not planning to connect all the buttons to the same ESP8266 which is surely the simpler option?

...R

Is this possible to do or do I have to iterate over all digital pins and check for it?

Why would that be a problem ?
Compared to the speed of Web access then iterating over an array of pins is lightning fast

Oops ...Nope ! i got carried away there and forgot the 8266 bit ! On the positive side it’s worth a read and then look at the 8266 architecture to see if a similar course of action is possible - that is an investigation route to follow and google shows some results on here and elsewhere.

But as already said , reading each input in turn should not be a big deal or be a big overhead .

Thx for pointing that out !!

No worries - I think it's about time we had a dedicated 8266 section of the forum.

It's getting harder and harder to cover all the variants, "official" or otherwise.

hammy:
But as already said , reading each input in turn should not be a big deal or be a big overhead .

It's less effort than the discussion. :wink:

AWOL:
No worries - I think it's about time we had a dedicated 8266 section of the forum.

It's getting harder and harder to cover all the variants, "official" or otherwise.

ESP8266 and ESP32 Combined Section.
Tom... :slight_smile:

Robin2:
This is a bit confusing.

If there is only one button attached to each ESP8266 then there is no need to iterate over all the pins because you KNOW which pin the button is connected to.

If the problem is that the server needs to know which ESP8266 makes the call then just put an identifier in the message sent by the each ESP8266.

But why you are not planning to connect all the buttons to the same ESP8266 which is surely the simpler option?

...R

Well, using only one board is not possible, because the devices are in seperate spaces (about 10-20 m away from each other with a party dancefloor between them). And putting an individual identifier in the message would be possible, but I then had to change the code for every device.

My idea was to program everything only once and then the identifier is based on where the button is connected, so you just have to change the pin being used to add new ones.

bliepp:
My idea was to program everything only once and then the identifier is based on where the button is connected, so you just have to change the pin being used to add new ones.

That's a reasonable strategy.

Iterating over all the I/O pins is very quick - even on a Mega with 50 of them.

How many different devices will you be using?

Another strategy is to set aside a few pins for identifiers and put a jumper between one or more of them and ground when the device is being deployed. Then the MCU can check those pins in setup() so it can identify itself.

...R

Well, thanks for your responses! I know it is very unclear what I want to do, so I'll give it a try:
I'm on a party planning team. We've got a Raspberry Pi server running via python. Over there the current consumption of drinks is beeing tracked by the people selling those. Every time they sell a drink, they push a button and the server knows about it. Our location is in some kind of a wide range, so we can't connect them via a wire. We have to use Wifi or something like that.

AWOL:
Is that such a big deal?

No, it is not a big deal. I just wondered if there was a cleaner / more C++-like way or something to achieve that. If theres no other way I would just iterate over all ports and check for them, of course.

I just wondered if there was a cleaner / more C++-like way or something to achieve that

The clean and portable way would be to iterate over some form of list of pins.

Robin2:
That's a reasonable strategy.

Iterating over all the I/O pins is very quick - even on a Mega with 50 of them.

How many different devices will you be using?

Another strategy is to set aside a few pins for identifiers and put a jumper between one or more of them and ground when the device is being deployed. Then the MCU can check those pins in setup() so it can identify itself.

...R

So there's no other way to check for HIGH pins than checking every pin individually?

There are other ways, but they're not usually clean or portable.

Hi,
As I understand it , each 8266 has one button, only one button, you want to know at a central WiFi point which button is pressed.
Why poll, just wait for the button with its address to send a packet out over the WiFi when it is pressed.

You do not need customised code for each 2866, each 2866 can have a set of dip switches on its PCB.
They are used to set the ID of each 2866.

When the 2866 boots, it reads the dip switches with it unique ID.

Or am I missing something?

Can you post a simple block diagram explaining your system?

Tom..... :slight_smile:

bliepp:
So there's no other way to check for HIGH pins than checking every pin individually?

Jeez, you would have written the 4 or 5 lines of code to iterate over the pins 100 times since you started this Thread - what's the big aversion to a simple reliable and portable solution.

What I suggested using jumpers is just a less elegant version of @TomGeorge's proposal to use a DIP switch.

...R

AWOL:
The clean and portable way would be to iterate over some form of list of pins.

Ok, thanks. Guess that's the best way to go.