writing and reading a binary word on some pins

If doesn't fit into any other category ....
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

writing and reading a binary word on some pins

Post by its1000 »

hello to all
I search in the help but could not find the way to do this.
I would like to be able to encode and decode 8 infos from an annex esp to another one, using only 3 wires max.

i could use an I2C module but I don't thing it will work fine after a 2m cables.

my idea is to use 3 ouputs as a binary word and decode this binary word at the other side.
I don't find a function directly implemented in Annex to declare something like :
"set pin 5,6,7 as binary binout"
then say "write value 0 to binout" and automatically the outputs goes "0 0 0"
or "write value 3 to binout" and automatically the outputs goes "0 1 1"

same as input.

is there a function directly implemented to do this? if not I will write all the code to do it.

thank you for your help.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: writing and reading a binary word on some pins

Post by Electroguard »

H,you could use 2-wire serial to transmit an 8bit serial strung of pulses then decode the pulse string back to it 2wire 8 bit serial data pulses.
You could even latch the 8 bit data into a port expander if that's what you need, giving you 8 latched data lines from your 8 bit data stream.
If you turn down the serial clock baud rate the transmission length goes up as the data rate drops, and can achieve hundreds of metres.
It might help to explain what you are trying to achieve?
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: writing and reading a binary word on some pins

Post by BeanieBots »

As Electroguard has already stated, it sounds like your best bet would be to use the serial commands to simply send 8-bit data from one device to another. That's exactly what it was designed for. (just two wires).
There is no command to do exactly what you describe but it would only require a few lines of code to implement.
Again, as already mentioned, if you can explain how/why you want to do in more detail, we can come up with a solution for you.
If it is litterally just to send data, then there are many "standard" ways of doing it, including wireless.
If it's ESP to ESP, the obvious choice would be ESPnow. Very fast, very easy and wireless without even the need for a router.
You could even use PWM on the sender and count on the Rx!
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

thank you for your answers guys.

my 1st esp is managing the external power supply of a tube amplifier.
the power supply is linked to 2 mono bloc by some cables transfering the HT power, heating power, etc.
I have 4 cables left to transfer some informations to the 2 mono blocs

the esp is managing a tempo to apply HT after heating,
I deactivate wifi in order to avoid interferences between esp and tubes (so no wireless com)
it's also managing a screen 640*480 color
the ESP is keeping a counter of lamps life from 0hours of run to 4000hours
this counter is also calculating a remaining life for the tube :

0 = 0% left
1 = 20% left
2 = 40% left
3 = 60% left
4 = 80% left
5 = 100% left

in each mono bloc I have another esp managing a small screen OLED 124*68
I want the second ESP in each mono bloc to indicate the % remaining life on the screen coming from the 1st esp.
I could use 5 pinpout in the 1st esp and 5 pin-in each amplifier ESP to detect the % and screen it, but it's 5 cables.

that is why i thought using a 4 bits word in order to use only 4 cables and beaing able to have 16 information coming from the 1stp in to the 2 others "slave" esp.

I hope it's clear... maybe a little be confuse don't hesitate to tell me what is not clear
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: writing and reading a binary word on some pins

Post by Electroguard »

A very interesting project.
I'm still not sure how you plan to implement things, but I suspect it is a combination of devices communicating with others, and using local controlling connections. Which gives 2 problems, device communications, and device local control capabilities.

Local control is easily catered for using port expanders where necessary, I did an example project here... https://sites.google.com/site/annexwifi ... -8-outputs

I lost count of how many ESP devices are being used which need wired comms, but I think was more than 2.

Each device is limited to 2 point-to-point serial connections using serial1 and serial2 - it is possible to daisy-chain multiple devices together so that intermediates pass-through data not intended for them... but that requires some form of addressing.

An enhanced alternative could be to use RS485 modbus modules which allow 1 serial to many rs485, which is how multiple cctv cameras and controllers (Pelcom) can be connected together on a single twisted pair.
All devices on the modbus would receive all 8 bit transmissions, which could utilise some bits for address, so only the addressed device will respond to the data.

CAN bus twisted pair works very well on Annex32, but is not available on esp8266, so all CAN devices would need to be ESP32's.
Its what keeps planes in the air and cars on the road, so would allow your system to become as sophisticated as you wish, and relatively easily
To give an idea of hobby CAN bus, I actually did an Annex32 version similar to this arduino example, but never published it because of google hijacking further changes to the website...
https://www.youtube.com/watch?v=3GmVrIWT3Bo
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: writing and reading a binary word on some pins

Post by BeanieBots »

From what I can make out, you only have two ESPs which need to talk to each other and four spare wires.
If I'm right, then it's very easy. Simply use the built-in serial commands. Only two wires for one-way comms and three for two-way comms.
There is even 'onserial' which can trigger an action if something is received without you having to keep 'looking' to see if something has been sent.
Even if you have a multitude of ESPs, you do what is called 'multidrop' on the serial and have many devices on the same line.
Let us know and we can help you with the details.

Really pleased to see that tubes (or valves as we call them in the UK) are still being used. Much better than trannys for audio :D
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

Thanks you guys it’s gaving various options. I have one esp32 master in the power supply and 2 slaves in eac mono bloc. I will try to make you a diagram and schematic .All esp they start at the same time and donsome autonomous routines. Then the master esp determine the valve remaining life (VRL) and store it in a value between 0 and 6 for example. The 2 slaves they do their start routine then they read the VRL and show the value on the screen. Then they screen something else Except is value is 0 . In this case they screen a warning message telling to change the valves.
BeanieBots
Posts: 325
Joined: Tue Jun 21, 2022 2:17 pm
Location: South coast UK
Has thanked: 173 times
Been thanked: 104 times

Re: writing and reading a binary word on some pins

Post by BeanieBots »

If it were me, I would use serial.
The ESPs support two serial ports, so the master could use one for each slave.
An assumption I've made about your settup is that all ESPs share a common 0v line.
If not, then you will need to consider using opto-isolators.
If they do, then simply connect the Tx from the master to the Rx on the slave (just one wire + common ground) and
the Tx(serial2) on the master to the Rx on the second slave.
The rest is just software.
That will be enough to 'send blind' a bit like sending UDP packets.
If you want to know that what you have sent got there and was received OK and maybe even include 'processed OK' then you will need to add another wire between each of the master Rx inputs and each slave Tx output as well. (4 + Gnd wires to the master. 2 + gnd to each slave).
I am not very familiar with CAN bus so cannot comment on its reliability speed or likewise but serial has been around even longer than I have. :o
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Aug 08, 2022 4:25 pm If it were me, I would use serial.
The ESPs support two serial ports, so the master could use one for each slave.
An assumption I've made about your settup is that all ESPs share a common 0v line.
If not, then you will need to consider using opto-isolators.
If they do, then simply connect the Tx from the master to the Rx on the slave (just one wire + common ground) and
the Tx(serial2) on the master to the Rx on the second slave.
The rest is just software.
That will be enough to 'send blind' a bit like sending UDP packets.
If you want to know that what you have sent got there and was received OK and maybe even include 'processed OK' then you will need to add another wire between each of the master Rx inputs and each slave Tx output as well. (4 + Gnd wires to the master. 2 + gnd to each slave).
I am not very familiar with CAN bus so cannot comment on its reliability speed or likewise but serial has been around even longer than I have. :o
I have common 5v and common 0v for all ESP.
i have 4 cables to each slave so 8 coming out from master
then I need to understand what command I can send and receive from master to Slave.

as I am in serial, maybe I can send more than some basic info?
the best would be to send a variable name, and the value of this variable. if possible...
its1000
Posts: 76
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 3 times
Been thanked: 1 time

Re: writing and reading a binary word on some pins

Post by its1000 »

I was also considering using i2C moduels PCF8574 but maybe more complicated
Post Reply