Saturday, June 11, 2016

ESP8266 PWM Android Controller

Control ESP8266 PWM outputs* with Android.

Android app: play.google/wifipwm
Android src: github/esp_wifi_pwm

demo:


ESP8266 init.lua :
wifi.setmode(wifi.STATION)
wifi.sta.config("WIFI_SSID","WIFI_PASSWORD")

local GP0 = 3
local GP2 = 4
local port = 3456

print(wifi.sta.getip())

srv=net.createServer(net.UDP)
srv:on("receive", function(cli, rcv)
    --print(rcv)
    rx={}
    for i, s in string.gmatch(rcv, "(%w+)=(%w+)") do
      rx[i]=s
      --print(i, rx[i])
    end
    if rx.d0 then
      pwm.setduty(GP0,rx.d0)
      --print("GP0 duty",rx.d0)
    elseif rx.d2 then
      pwm.setduty(GP2,rx.d2)
      --print("GP2 duty",rx.d2)
    elseif rx.f0 and rx.c0 then
      pwm.setup(GP0,rx.f0,rx.c0)
      pwm.start(GP0)
      print("GP0 freq",rx.f0,"cycles", rx.c0)
    elseif rx.f2 and rx.c2 then
      pwm.setup(GP2,rx.f2,rx.c2)
      pwm.start(GP2)
      print("GP2 freq",rx.f2,"cycles", rx.c2)
    end
    cli:send(rcv)
  end)
srv:listen(port)


*PWM outputs nodemcu pwm
  • pins GP0 and GP2
  • up to 1kHz only
  • 0-100%duty (note: 1023 cycles = 100% duty)

5 comments:

  1. Selam siteniz cok guzel ve guzel konular haberler basarilarinizin devamini bekleriz tenku admin

    ReplyDelete
  2. Android devices running Android 4.0 Ice Cream Sandwich (or Android 3.2 Honeycomb) or newer support game controllers natively. You aren’t necessarily out of luck if you’re stuck on older software — most controllers will pair to older Android devices — but you can expect them to work unpredictably, unreliably, and sometimes not at all. mobile game development UAE

    ReplyDelete
  3. Thanks for sharing valuable stuff.
    Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
    Best video editing services in Hyderabad,ameerpet
    Best Graphic Designing services in Hyderabad,ameerpet­
    Best Ad Making services in Hyderabad,ameerpet­

    ReplyDelete