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
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?
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 .
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.
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.
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?
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?
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.