Use a phone flashlight to send data #872
floitsch
started this conversation in
Show and tell
Replies: 1 comment
-
This is so cool, to use what's readily available, to communicate from the phone to the ESP32. I'm sure it will be very useful for someone's project in the near future. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Today I found the time to play with an idea I had for a while: use a phone's flashlight to send data to the ESP32.
This could actually be useful in sending WiFi credentials to devices that haven't been configured yet.
Initially I hoped I would be able to just use the screen itself (turning it white/black), but that didn't show me enough differences. It might be possible to do that in a more controlled environment (where the LED is nicely shielded), but in my room, with my setup, the flashlight was just easier.
This was just an experiment and I haven't cleaned up the code, but it ended up being surprisingly easy.
I simply put an LED in series with a 330 Ohm resistor on pin 32. The resistor is then connected to GND. The LED is thus fully functional. I can turn it on and off as usual.
However, LEDs also function as photodiodes (admittedly not as well as the specialized sensors one can buy). I just need to set the direction of pin 32 to input and measure the voltage with the ADC peripheral. Using the flashlight of the phone induced a significant change of voltage. In the code below I just hard-coded it to 1 Volt.
phone_led.mp4
screen_capture.mp4
Edit: I uploaded the code to a repository: https://github.com/floitsch/ledcom
Here is the full Toit code.
I wanted to be as precise as possible when measuring the pulse widths, so I just counted in a while-loop how many iterations I can do.
In retrospect that's probably not necessary, and I could have just used
Time.monotonic_us
or something similar (for timings that are independent of the speed of the interpreter/CPU).The phone application was written in Flutter.
I used the torch_controller package, and initialized it in the
main
function (as documented in their README).Then I hacked the demo application to spit out same data when the button is pressed.
I added a new field to the
_MyHomePageState
class:and then changed the
_incrementCounter
function to transmit the data. (The following code was just added after thesetState
call):Beta Was this translation helpful? Give feedback.
All reactions