W3-4: “Welcome to Wireless Hell”
Continuing to Figure Out Wireless Connectivity
Attempts at making the Xbee modules work yielded a whole lot of nothing. The guide I was following had bad code and since I don’t understand how it works yet, I couldn’t debug it. That put me back at square one and quite behind schedule.
So, I tried looking into alternative options. What I’m attempting to do should be pretty similar to something like a remote controller for an RC car - surely it shouldn’t be this difficult to figure something out. Apparently it is…
I finally came across a tutorial from How To Mechatronics that used an nRF24L01 radio transceiver with Arduino. This was significantly easier than using the Xbees. Straightforward and worked on the first shot.
In order to use the nRF24L01 transceivers with this project, I’d need a smaller microcontroller and one that would have enough pins. If I was going to have to buy new microcontrollers anyway, why not find one that has connectivity baked into it? Onto more confusion…
Searching for a board that has everything included in it came down to three (maybe four?) connectivity options: WiFi, Bluetooth/BLE, or radio. I wanted to avoid WiFi because the plan is to send a prototype off to Lisa Jellison for her to test prior to when I can meet with her over Thanksgiving break. Therefore, I couldn’t use something that requires connecting to existing WiFi networks, since I don’t have access to hers from two states away. Most boards with Bluetooth kept specifying BLE, which a guide from Adafruit about how to choose a microcontroller said: “If you want wireless communication between microcontrollers, you almost certainly do not want BLE.” That leaves radio. The nRF2401 operate on 2.4GHz, which was not at all confusing with the fact that that’s also what WiFi boards operate on. Turns out the protocol that those transceivers use is proprietary to the chip manufacturer and would not be achievable with just any board. There were other radio boards that operated on 433MHz, 900MHz, etc, but when looking into what frequency would be better, it was looking like there might be some weird legality issues with prolonged use of a radio device on the aforementioned frequencies. I have no intention of accidentally getting Lisa into legal trouble, so that’s a hard nope.
Arduino has a page discussing device to device communication and how ESP-NOW is a good protocol to use for it. Not confusing at all, considering boards with ESP-NOW capable chips have WiFi, Bluetooth/BLE, possibly radio, and (for good measure) Zigbee/Xbee capability, from my understanding. Because I was short on time, I ordered two SparkFun Thing Plus ESP-32 C6s - now officially named Thing 1 and Thing 2. Overkill for what I need, but since it seems to have capability for all of the protocols, I might be able to try multiple approaches if ESP-NOW didn’t work.
How I miss the simplicity of the nRF24L01s….
ESP-NOW is definitely more complicated and nobody seems to have a tutorial for communication between two devices to just turn an LED on and off. I followed this guide from Random Nerd Tutorials and eventually kind of figured out the process. How ESP-NOW actually works, I have no idea yet. It seems WiFi based, since it includes a WiFi library and sets up the device as a WiFi station before engaging ESP-NOW, however there is never any point where an actual network’s name and password need to be used.
It did work, eventually. My laptop sounded like it was working way too hard when sending information to the receiving board, but I’ll work on that when I get the real code written.
This brings us to where I am now. Because nothing can ever be straightforward, now there is a wonky problem when I switch to a potentiometer. The value range that the board is receiving from the potentiometer is all over the place instead of the standard 0-1023. Instead it yields 115-800, 625-2225, 0-3000, etc. After conferring with Zack, the current theory is that the physical connection with the potentiometer is iffy - just wiggling the potentiometer around a little bit in the breadboard was enough to change the value range. So, at his suggestion, the next step will be to create a soldered connection and see what happens then.
Hopefully that will resolve the issue and I can finally move onto an enclosure. Despite how frustrating it has been to find a board that has everything I need included in it, it is also saving me the step of having to make a custom PCB this time. So even though I’ve fallen behind schedule in this process, I also gained back about two weeks’ worth of time.