Custom light controller for Spektrum receiver/ESC

This site may earn a commission from merchant affiliate
links, including eBay, Amazon, and others.
What I found when writing this for the RP2040 is that it's hard to do this fast enough in software to get precise figures. e.g. using an interrupt on edges and measuring the timer value to establish the pulse width gave some variation in the measured values for the same pulse width. Using PIO gives extremely consistent values. It looks like the ESP32 has a feature in its PWM hardware that can automatically measure the period between transitions. That said, doing it in software is probably good enough, as we're mostly using the RC inputs as a switch, rather than needing an analog value.

As far as I can tell, the pulse width is fairly well standardised, and ranges from about 1ms to 2ms, with neutral around 1.5ms, but the the frequency varies. 50Hz is "normal", but the Spektrum gear seems to run at 200Hz. I spent quite a long time convinced that my code was wrong because I can find absolutely no documentation of this! But as long as you can accurately measure the pulse width, it doesn't really matter how often you get pulses.
 
It's been...10+yrs but I believe there was a discussion on RC-universe where folks looked at the PWM outputs on different brands. The cheap ones would use between 50 -200Hz frames per channel while the top-end flagship models of the big companies would use up to 400Hz frames.

Other than that, yeah the 1ms - 2ms with the center point being 1.5ms, it kind of makes sense why we don't see anything higher than 400Hz because a 2ms full throttle signal of 2ms would use the entire period of a 500Hz signal whereas the 400Hz clocks in at 2.5ms allowing the device being controlled to have at least a 500us off time on the input.

On my end of things, I have my modules, and I've loaded them up with Micropython and started a Github (https://github.com/Psylenceo/ESP32_uPy_testbed) to start keeping stuff in order and to play around with over the area updating of the code. And I got it to work! Currently, on power-up or reset it goes through a boot.py script that turns on wifi as a station, and tries to log in to my home wifi, if successful it checks github and compares the local file to the one on Github. If the file on GitHub is newer it will auto-download, overwrite, and restart the device. Sometimes it doesn't work, but I think that was just from me testing the updates in rapid order debugging a Micropython version issue that caused PWN to not work on frequencies below 612Hz.

Not sure what I want to tackle next;
BLE / wifi webserver to monitor signals
Porting your code over
Or starting on data logging stuff

Porting your stuff over may be difficult as I do not have a Spectrum unit or anything with a Sbus to start interpreting signals, and some of the data logging stuff I don't have, like the 6 DOF IMU, I thought I had one but it turns out it was just an accelerometer since that's all that was needed for input shaping on my 3d printer, which I still haven't done yet...
 
Yeah, I found various references to 300Hz (or 330?) being a common "high speed" mode, but absolutely no references to 200Hz being used, so I was bit surprised to discover that something mainstream like Spektrum was using it.

The boards I got recently are using the LSM6DS3s as the accelerometer.

My code now works fine with normal RC signals, and in theory it's just a case of porting pwm.py. There's some code in there to detect whether it's looking at a PWM signal or an SRXL2 signal, but in the first instance you could just short-circuit that to assume it's a PWM signal.

It looks like MicroPython doesn't currently support the PWM Input Capture mode on the ESP32, so it looks like some work would be needed there if we wanted to use that. Again, we could probably just do PWM measurement in software in the short term.

Which ESP32 board are you using?
 
https://www.amazon.com/gp/product/B08FWXFSVN/ref=ppx_yo_dt_b_asin_title_o00_s01?ie=UTF8&th=1

Just did a chip_id on it and its using a ESP32-D0WDQ6-V3

-Cheapest I could find without digging through a bunch of stuff on amazon.
-It exposes enough pins and has the right dimensions to either fit inside a Typhon RX housing or in a 3d printed box that would fit in that same footprint, like if you wanted to mount it on top of the RX lid.

As for the PWM read, we'd just need to use a timer and sample it via pin polling or interrupts. It'd be the same thing we'd probably do if we were programming in C or C++.
 
Last edited:
Partial High jacking of thread but, I'll let oops decide if he wants me to post here or start my own thread since my version of the code and project is more about being a datalogger/webserver WITH a light controller included. While the Ooops version is centered around being a light controller WITH sensors connected to it. Not to mention I'm no longer attempting to do this in python, but in C, and as of the last time I worked on it, I was converting stuff to C++ to allow a more versatile code layout.

Here's my GitHub with my current progress and code: https://github.com/Psylenceo/ESP32_testbed_with_git_update

Between having to work 3rd shift in July, being busy in August, and college classes have started at the end of August. I have not had much time to continue working on my version so I wanted to share it with everyone in case someone was interested and wanted to try their hand at progressing the code and project. I'll get back to working on it but I don't know when and it's highly dependant on class and work schedule.
 
Is that so..?
Did I just mis-read that other post then??

So, oops = kenm04

Because I could've swear they are two different people from just the above postings post#64 ,#65
I was sure it's the same guy...until you came along so, thanks for that. You're correct however. I either misunderstood or misread a post or two. Found this in another thread:

"Partial High jacking of thread but, I'll let oops decide if he wants me to post here or start my own thread since my version of the code and project is more about being a datalogger/webserver WITH a light controller included. While the Ooops version is centered around being a light controller..."
 
I was going a different route to make a custom light controller, Oops was using a Raspberry RP2040 chip, I am using Esp32 to give it wifi to use the webpage to configure it, and Bluetooth to push notifications to cell phones, tablets, or computer once I got around to adding temp sensors and other features.

I made a different forum post so that the work I am doing isn't hi-jacking this thread.
 
Old Thread: Hello . There have been no replies in this thread for 90 days.
Content in this thread may no longer be relevant.
Perhaps it would be better to start a new thread instead.
Back
Top