Delimiter to select mcu

I am programming a hydroponics/mini-greenhouse system that will use an esp8266 and two stm32f103s one being the c8 and the other a c6 I had my code almost perfect until i realised i needed another stm32 as not enough wires in my few meters of 8 strand cable to control everything in the third box thats where the c6 came in. So problem is i don't have enough spare serial ports as i am also trying to use a gps on Serial3 of first stm32 connected by short serial cable to esp for satelite time. So I want to have a start delimiter for each controller say '~' for esp, '£' for "stm32f 128k", and '$' for "stm32f 32k" and final delimiter "^" as well as delimiter to identify what data and delimiter to identify the actual numbers so what I am strugling with is code to ignore everything if say $ is received until the "^" is received then start looking for '£' or '~' depending of what mcu is being addressed
another problem I am having is when the stm32f103 sends lots of data on Serial2. it seems to freeze, would that be the tx buffer filling up or a stack issue? The stm32f103 does the sensor reading/sending and lights and pumps timing and control while the esp8266 just shows info on webpages and toggles some data via webpage the 3rd stm32 will do a little similar to first but far less intense. To further clarify, if I was sending temperature to esp the serial output would be ~|temp1¬<22.60>^ so ~|¬<>^ are all delimiters ... maybe there is a better way but this project has gone on too long and just want to wrap up for now till I have time to improve it. Hope this is clear enough. As for second problem well i control pumps and lights with 74hc595 so i need to send the spi data to esp so it can show on page whats on or off but if i put that Serial2.print in my set595 function whole thing freezes after 3 or 4 spi transmisions I can send code if needed but its rather large and ugly but kind of works if i remove my serial prints but then the webpages don't update. Also the esp8266 is the 01 so no chance of 2 serials there although I did manage to solder wires to gpio4 and gpio5 without an electron microscope!

I may have solved my second problem, not sure yet but basically every spi transfer from function set595 is 16 bits as there are two daisychained 595s but bits 0-6 are switching in and out 4 temp sensors and three hc165s that read water levels so i don't need to send this data everytime one of these bits change only when the other 9 bits change which is far less frequent so i shifted the data called one lot old and one lot new compared with < if (hc595data & 1111111110000000 != hc595dataOld & 1111111110000000) {
static uint16_t nineBits = (hc595data << 7);
update595(nineBits);} /> and created a function update595() to send the 9bits over serial but another issue to overcome from previous post is if another microcontroller is sending data to yet another the one in hand has to stay quiet until it receives the '^' delimiter but I may work this out, I just started having a brain overload after everything I have already worked out. seems I have forgot how to use code tags properly... i tried 3 times

sounds like you just want a bandage and aren't really interested in other approaches

sounds like you're communicating between board over separate serial interfaces to each. rs-485 allows multiples devices but only one device can transmit at a time, which typically requires a master that polls each device

as for delimiters, why not send a line terminated with a line-feed, '\n' and used Serial.readBytesUntil() to read a complete line and extract fields from the line that identify the destination, label of the data and the value of data (e.g. "1 temp 23.5\n"). fields such as this can be extracted using sscanf() or strtok()

Thankyou gcjr yes you are right in that i am looking for a temp bandage but the esp is using serial. to communicate with 2 stm32's and the stm32' are also using one serial to communicate. I will look into rs-485 a bit further to see if it will help me but I think I have worked out a temp solution in my main loop i look for a serial input of 'char for this mcu' ('£') for stm32f103c8
if true i call function to process the '|'data name'¬' and '<'data'>' else dontUseSerial2=true until it receives the'^'. If this works I will mark as solved but I need to change a number of functions to test it, thanks for advice and suggestions oh and the serial processor fills a buffer for data name then another for data then sends to the esp8266 so each device will do the same and hopfully keep quiet untill '>' followed by its select delimiter.Hope that makes sense. I could change the end delimiter from '^' to '/n' or '/r' but they pretty much tell it the same thing, I am down I'm gone byebye.

why at all so many MC? has esp 8266 not enough flash or is it too slow? if you need more pins it ia a bunch of port extender or shift register.
and GPS in greenhouse!? what? are it in Low Earth Orbit?

love your questions! ok

So my esp8266 is fast but one core doing wireless network and webserver with a number of updates to page variable frequently but only having 4 gpio's available on the 01(8 pin version) and only one analog input
so my first stm32f103c8 can turn on and off 2 pumps and calculate their timing and do all water level calculations and similar with lights and ldr sensors to keep a steady light spread regardless of dusk dawn etc (they out outside in plain sight of the sun!) but two boxes one just green house and the other hydroponics )are close the other is a few meters away and i ran 8 core wire but it can not deal with temp, humidity, soil moisture, heat, light, and lux sensors, I think I miss out something but anyway another or 3rd mcu can deal with that. The whole three were less than £8 so its worth it if the few meters can handle 115200 baud serial, So esp8266 is fast compared to uno type mcu but does lack analog sensor ability and would be highly taxed with all other jobs and would lack control pins for 74hc595 and 74hc165 which I am using 2 and 3 of respectively
but the best question
My favorite

... aren't we all? Well no it is firmly attached to my front garden by gravity, dang what kind of force is that? anyway ya the stm32 has real time clock which is great for not having to worry about millis() roll over and timing the events on real time to display next pump/light on off time on web page. So Satelite time is free and accurate and after only gettin fibre this year and losing connection for over 3 weeks means it is cheaper and more reliable than internet which often depends on satelites anyway. But if ever the world stops turning at least I could get a position on where in space relation to me my home grown food is!

Ah yes and there is a software rtc for esp8266 but I get the impression it has not a fully functional rtc of its own but a non replaceable bit of kit all the same!
So just trying to keep it all running cool and doing its own quota ... I hate it when they make me do everything! mcu's might be the same when AI takes over! and they might not care if they are quantum mcu or stm32 or expresso coffee... been a long day my focus is dying.
G'night

you all 7 lucky people working on ISS. me and the rest are all on the surface.

well. anyway, are MCU communication connected in a ring?

I was originally using stm32 connected to esp8266 tx-rx and rx-tx but now the other stm32 connects on same serial line so if it sees data on the rx line it
it looks for a char that identifies which mcu it is for, if not for itself it shuts up till end of message as do the other two mcus... but still implementing the system but should work.

no it is not.
every your board has two UART. connect them in chain.

last on chain:

Serial.print(char(1));
Serial.println(data);

next one:

Serial.print(char(2));
Serial.println(data);
while (Serial1.available>0)Serial.write(Serial1.read());

first one, the ESP:

if(Serial1.available>0)Serial.print(Serial1.read(), DEC);
while (Serial1.available>0)Serial.write(Serial1.read());
Serial.println();

if you see in serial monitor messages from all STMs then try recognition

I think my head went into an orbit higher than the 5-6 feet its used to and missed a few details. The esp sends data from webpages when client connect but the two stm32's send sensor data and switch status so my concept was connect both stm32 to esp same way but only just realized they will both be trying to send sensor values and will not see the character they are sending to esp8266 to say they are sending it data only the esp will know that it has two stms talking over each other because their tx will be to tx and rx to rx oh well duh again. Soooooo I have i2c that seems to work ok on both stm32's. It just means the hardest working stm32, will have to work harder, being messenger to the esp and the other wee stm32. I might drop the third box for now or make it self sufficient without a webpage as it has no pumps, and has been producing lovely baby lettuce for my sandwiches, and parsley for my wife's parsley sauce covered fish. I need to get working on a far further fetched project. But nice to have a great community like arduino.cc to help at times and real people with real sense of humour.

I like the look of that definately worth playing with but may probably after i impliment what i have. As i have plants crying at me to be put into hydroponic state! before its too late. But thanks for that and I bet there are other people that might find that useful too when the situation is requiring of it. If they see this title whilst trying to do similar it may be a better solution than so many delimiters , thanks kolaha

Actually the esp8266 -01 does not have pins available for a second uart but your answer is the closest thing for what I was trying to do. Your cool calm advice made me think enough to find a temporary bandage of a different sort well I already use a walking stck but thanks so much and you deserve a solved!!! I wanted to do more before answering but time is pushing on and I don't even like just walking away so Happy Days! I hope lol

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