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.

81 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
false positives and false negatives.
A little noise breaks the while loop, throws the whole thing off
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Also, even if I did attach an interrupt to the pin, wouldn't the whole noise issue still be there?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Oh I have no control over this data, I can't just add a checksum.
I'm "hacking" an old toy
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
You added a checksum to it?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Data is read via a jumper cable direct from pin A3 into the signal_out connection of the toy
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Bandai's Digimon VPet toy line
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Sorry, not sure what this question means
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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
E.g.

Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
There are thousands of users already with prebuilt systems already using pin A3 which I would be screwing over lol
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Lol this is how you read the register directly for pin A3
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
It is one way, I assure you
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Since I also use pin A2 to write signals back
I suppose, but it's not harmful
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I was going for very very low latency, so avoiding the macros baked-in functions
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Corrected myself there
I thought thats what you meant by macros
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Yes
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Long wait is my "non blocking" wait.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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.

Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Multple reasons
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Remember, my question is only about the preamble section at the start here

Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
Actually has to be done in under approx 60ms because of other overheads
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View