Radio Modules:
Power Supply: which I have measured to output 300 mA while only dropping to 3.24V.
Code: Running on Arduino Uno, but I also ran on a Nano with no change.
Relevant Images:
The first image is taken when I have unommented the "printPrettyDetails" line. As far as I can tell there, everything is up to scruff. I do see that the SPI lines are at 0MHz, but I have told them to run at 100kHz because I thought slowing it down might help with the fact that I am using jumper wires at the moment. (I have shortened them and straightened them and lined them up as nicely as I can, but it's not a great solution for high speed. I just can't really invest in anything better until I know I can make this work.
The second image is essentially the problem. I did modify the code slightly from normal so that it wouldn't try to work its way through the state machine. All it's doing is having one of the radio modules transmit the same 4 bytes 3 times over, then doing a different 4 bytes 3 times over, and repeat. You can see that there is a 1-to-1 correspondence between messages sent and messages received. The code even checks to make sure 4 bytes were transmitted. And there seems to be no randomness to the mistranslation as the values are completely repeatable. Even when my code wraps around to run the first 4 bytes again, it gets the same response the first time around.
The last image is closer to what my final code is, except because all the data is garbled, I had to comment out all error checking and just take all values as if they are correct. I also shifted the printing around a bit to make sure each put out the same number of lines to make it easier to read what's happening. And just in the first interaction for visual aid, I highlighted values that are supposed to be the same. Values that were transmitted by one module and received by the other, but with value distorted.
each of the images showing the incorrectly transmitted (or incorrectly received, not sure which) data has a comment in Imgur with the commit hash (they're just the two most recent commits). (Also, please don't judge me by my commit history, it's a personal project. I'm not going to put in the same effort I do when I code for work to make things neat and tidy and have useful messages or distinguish which changes were for what reason.)
A quick overview of how the code is intended to work:
- The transmitter sends a known code (RUN_LEFT, RUN_RIGHT, or RUN_BOTH). Eventually, a button will trigger this, but for now, it just loops through the commands with a 5 second delay between interactions
- The receiver will (if it recognizes the command) generate a prompt (using millis) and send that prompt to the transmitter. It also runs that prompt through a digital woodchipper (it's nothing fancy, I wrote it myself, it's not super high security or anything, just think of it like using the prompt as the seed for an RNG. The function is called calculate_response and it exists in the garble module (not included in the repo)
- The transmitter gets the prompt, runs it through the same woodchipper, and sends the response back.
- If the response from the transmitter matches the one expected by the receiver, the receiver will enact the command from step 1, and blindly blast back a few copies of an acknowledgement (CMD_SUCCESS).
I had been fiddling with this code for over a month before I finally had it basically working. Except it was jam packed with dozens of ugly debug messages and in desperate need of a refactor. Like an IDIOT, I didn't commit, and forged on because I didn't think I was actually changing anything. I cleaned it all up, got back to a state that was pretty close to what I was hoping would be the final product, and suddenly, all the data is messed up again, and I can't get it back to where it was. I'm relatively confident it's not hardware because I didn't even physically touch them between it working and it not working. Plus, I can't imagine I'd even get this much responsiveness with bad hardware. Any tips?
