Best way to *listen* for known signal patterns

I am working on a project where I use an Arduino (Nano, atmega328p) to read a digital signal from another 3v3 logic device. I have some code which works half the time and I want to make it more efficient. The digital signal always starts with the same synchronising pattern: 60ms LOW, 2ms HIGH, 1ms LOW (See image) The subsequent signals are a series of 16 bits, and finally 15ms HIGH to signal the end. What technique would you guys recommend to use to "listen" for this initial synchronising pattern? My current method is to use three while loops in series that look at the state of the pin. Also, am I using the term "preamble" correctly with respect to data communication? Thanks.
No description
81 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
false positives and false negatives. A little noise breaks the while loop, throws the whole thing off
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Well, in theory? I don't think completely removing noise is a reasonable thing to pursue though? I tried adding a simple RC filter w/ a 100k resistor, a 1uF cap, and a 100nF cap but that broke the signal itself
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Yeah the program does a few other functions. Those are focused around handling the data from those 16 bits on the middle and passing the data back over Serial. But the main loop just called a function which looks for that starting synch signal. If it does not find it, the func returns 0, and the main loop restarts. If it successfully finds it, the func returns 1, and the main loop processes the 16 bits in the middle
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
There are a few limitations for this project however. Specifically, I need to use pin A3 for reading the signal. I'm not sure if I can attach a hardware interrupt to that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Also, even if I did attach an interrupt to the pin, wouldn't the whole noise issue still be there?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Oh I have no control over this data, I can't just add a checksum. I'm "hacking" an old toy
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
You added a checksum to it?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
As a side note, the thing im hacking does (in some instances) use a checksum lol. But that won't help with identifying the synchronising signal specifically here
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
I am both sending and receiving. But the sending half of my code appears to be working fine. Its the receiving half that I'm seeing issues with Nah just direct pins connection Some proprietary series connection from an old Bandai toy
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Data is read via a jumper cable direct from pin A3 into the signal_out connection of the toy
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Sorry, I'm not sure how to answer that. The toy has its own microcontroller. I haven't looked into that though. I just want to send and receive comms. I have the comms data structure fully mapped out. I just want to make the connection more reliable
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
www.alphahub.site Here is my website. The project is actually quite big. I'm going back to basics now with it though
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Normally, the two users press the pins of the toys together. It has two "pegs" to help align them. With my system, they use an arduino with some means to emulate this IRL. There are a few different ways people do this. Though, jamming some jumper cables in works just as well Yes, I plug the Arduino into a PC, where the PC (or mobile) pretends to be another one of these toys. Lets you spoof opponents or unlock items etc
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Bandai's Digimon VPet toy line
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Sorry, not sure what this question means
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
ah, that's just a coincidence. I'm constrained to pin A3 because that's what people in the fanbase already use. People who are not techy people so couldn't change it themselves. I'm using pin A3 digitally
ben9063
ben9063OP3y ago
E.g.
No description
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
There are thousands of users already with prebuilt systems already using pin A3 which I would be screwing over lol
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
In theory, yes. In practice, most of them won't/cant. Many people have soldered prebuilds, so its not that simple. Many others simply don't have the mindset for it or are scared of electronics.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Lol this is how you read the register directly for pin A3
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
It is one way, I assure you
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Ah I see what you're saying Yes, I suppose it is. It just made sense in my head when I wrote it It lets me see more easily which pin I'm playing with
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Since I also use pin A2 to write signals back I suppose, but it's not harmful
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
I was going for very very low latency, so avoiding the macros baked-in functions
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Corrected myself there I thought thats what you meant by macros
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Yes
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Long wait is my "non blocking" wait.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Since in this case, the only issue that blocking would cause it late arrival of serial data. So long wait just blocks for 1us at a time, checking for serial data in between, until the specified time is over
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
longWait(1); is effectively a wait of 0 time. Or rather, negligible time. The importance here is that this custom wait has within it a check for serial events. Yes, I could de-couple those two, and rteplace longWait(1) with a direct check for serial events.
ben9063
ben9063OP3y ago
No description
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Data from the toy is read from the toy, then sent out over Serial. Data is send to the Arduino from the PC via Serial. This is then sent to the toy. Two way comms
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Just for reference. My program does work. I can get two-way comms working. But I get a lot of terminated comms because of breaks in the synchronising signal at the start So it works its just not consistently reliable
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
toy hooked to pin A3 of arduino => Arduino receives data from toy => Arduino converts bits into HEX chars => Arduino writes HEX chars on Serial => PC receives HEX chars PC receives HEX chars => generates response HEX chars => PC sends response HEX via serial => Arduino receives these HEX chars => Arduino converts HEX to bit signals in format of toy => Arduino sends signal to toy This loops for a while
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Multple reasons
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
The single most important is that I'm building a system that creates a "virtual cable" here. I.e. I'm trying to abstract away the arduino, the PC, and the internet. So that two people with these toys. Person 1 London, Person 2 in Paris. Person 1 connects their toy to their arduino. Person 2 connects their toy to their arduino. The two toys may now connect as if they were physically both together
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Its not about verifying the data. Its about knowing when data has arrived. I don't really care for the contents of the packet. I just need to make sure packets are sending at the right time. This is because, when my system does succeed in knowing when a packet has arrived, I rarely get broken data.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Remember, my question is only about the preamble section at the start here
No description
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Trying to accurately listen only for when these specific events occur So that it knows when to look for the 16bits of subsequent data approx 290ms
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
I've had successful connections. I've already built the early version. It uses the WebRTC protocol, which I'm getting very impressive sub-10ms latency between my location (UK) and France
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
Actually has to be done in under approx 60ms because of other overheads
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
ben9063
ben9063OP3y ago
E.g. the time to re-produce the 139ms signal over on the other person's side Ah sorry, I'll DM it to you if that's okay
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?