iPhone app microcontroller control

Any iPhone apps that I can use to control a microcontroller over wifi. I know of a few but they are incredibly expensive. Can also do android but I’ve got a bunch of unused iPhones.

1 Like

Hey @Josh286640,

I know of a few decent ones but most of them are designed to work with a particular type of microcontroller.

What kind of microcontrollers would you be using this with?

1 Like

You don’t need an app to control a MCU over WiFi - a browser is sufficient. See, for example:
Control an ESP32 via Wi-Fi

3 Likes

Thanks Jeff, I’ll check it.

2 Likes

Looking to do this without the internet, using soft access mode.

The internet would only be relevant if you wanted to access the MCU from anywhere in the world. Do you mean you want to do it without using a router? That simply involves setting the MCU up in AP mode rather than as a station on your existing WiFi network. That will give you a network ID to connect the phone to, so you can browse that network. Typically, that network will have only the single server and you will connect direct to that server. There will not be any option to connect to the Internet. There is a thorough discussion here:
Creating a Wireless Network With ESP32 AP Mode - Instructables

Hi @Josh286640

That would be possible we have a guide on doing so with a Pi Pico, although a ESP will be reasonably similar Hosting a Wi-Fi Access Point & Web Page.

Sorry, I’m not asking the right questions.

I want to pull pins on and off, use pwm on a microcontroller.
———- Esp///01///32cam///and anything else that has wifi abilities.
I want to do control the GPIO pins from a phone .
Happy to use the computer to program.

But the controls need to be on a mobile device,

First option is IPhone 11

Second option is android tab (Samsung)

Third option will be “esp now” not sure if the protocol allows gpio control

This looks like I may be able to modify the code to suit.

Depending on what you really want to do, the above advice seems correct to me.
I have done this sort thing on a few projects.

  1. Setup ESP32 in AP mode (for stand alone) or connect to my home wifi as a Station (if I want easy access while at home)
  2. On the ESP32 setup HTTP(s) server
  3. Setup some code to spit out a web page.
    e.g. this could just be a series of buttons “pin 1 on” “pin 1 off” etc.
    Then have the action for that button call a “changepin” page on the ESP32.
    You can then get more advanced were you send json in javascript.

I normally setup a spiffs partition and save small images and css files etc that I can send back via a generic get/filename

Not sure why you would use PWM to turn a GPIO on or off, but the code to execute on the MCU when the command is processed is the easiest part of the example to modify. You can test it on the MCU without needing the remote control part, then just add the web page to provide the options.

I have a remote control for an 8-relay board and 74HC595 shift register, with a ESP12E controller that simply shifts the 8 bits of data into the register and sets all 8 relays at once. The web page is 50 lines of code (very repetitious - 8 buttons). There are 8 copies of the same HTTP Get request handler and no code needed in the main loop! The important bits are below.

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
  <head>
    <title>Relay Control Web Server</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
      body { font-family: Arial; text-align: center; margin:0px auto; padding-top: 30px; }
      .button {
        padding: 10px 20px 10px 10px; font-size: 24px; text-align: center; outline: none; 
        color: #fff; background-color: #2f4468; border: none; border-radius: 5px;
        box-shadow: 0 6px #999; cursor: pointer;
        -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none;
        -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0);
      }  
      .button:hover {background-color: #1f2e45}
      .button:active {
        background-color: #1f2e45; box-shadow: 0``````` 4px #666; transform: translateY(2px);
      }
    </style>
  </head>
  <body>
    <h1>Click Button Relay Web Server</h1>
    <button0 class="button" type="button" onmousedown="checkboxDown(this, '0');">Relay 0 OFF</button0><br><br>
    ...  
     <script>
      function checkboxDown(el, x) {
        if (el.innerHTML == "Relay " + x + " ON") {
          el.innerHTML = "Relay " + x + " OFF";
          var xhr = new XMLHttpRequest();
          xhr.open("GET", "/" + x + "off", true);
          xhr.send(); 
        } else {
          el.innerHTML = "Relay " + x + " ON";
          var xhr = new XMLHttpRequest();
          xhr.open("GET", "/" + x + "on", true);
          xhr.send();
          }
        }
      </script>
  </body>
</html>)rawliteral";

  // Receive an HTTP GET request
  server.on("/0on", HTTP_GET, [](AsyncWebServerRequest *request) {
    //digitalWrite(output0, HIGH);
    setBit(0, true);
    request->send(200, "text/plain", "ok");
  });
  ...

Duplicate the button create and request handler for each button, add the code at the beginning to create the AP, a few extra standard functions to handle other HTTP events, and the code to set the relays from the bit sequence, and you’re done.

1 Like

Hay thanks for the reply .

What I want to do is operate a 4 pin motor driver with the 4 GPIO pins of the Esp01, it’s an ambitious project for me. The motor driver is sold as l298n mini, but looks just like mx1508.
Once the Esp01 has been programmed the pins are free to do other things (I think). But I’m trying to work out how to communicate with the wifi of the Esp01. I can’t find anything on the net about anyone doing anything remotely interesting with the Esp01. So I thought this might work, I may be wrong. :man_facepalming:

Yeah…. My comprehension of what you’re saying is what’s lacking. But I’ll work on it. Is that code in c++?

The ESP01 should work, but there are some tricky bits because of the limited number of GPIOs available. In particular, GPIO0 must be high on startup, and that might create problems with the motor driver. For GPIO1 (and perhaps even GPIO3) you might get pulses at startup that could do odd things to the driver. In any case you will want to do your programming over OTA in order to avoid a lot of plugging and unplugging.

Because you are controlling a motor the simple on/off that you will find in most examples won’t work. If you look at the code I posted you will see that I have merged the relay number and the on/off state into a single value which gives the control and the state: each combination is it’s own page and its own handler. This allows very fast processing, but is somewhat of a kludge. In your case you will be passing a number (-255~+255) straight from the control (for instance a slider bar) so this kludge isn’t going to work. For this arrangement you will have a single page, a single handler, and a parameter.

The code is C++, but the big embedded text string is HTML - that’s the web page on the server.

This is what I’ve got to test it and it works straight off 3.3v on and off with a button, I did originally want pwm but I don’t think I can do that with the Esp01.

Why did you want pwm ? is it a servo where PWM sets the movement ?

I would not rule out a big bang pwm (not sure what the hardware supports) depending on the PWM requirements.

The pwm can control the speed of the motor.

Ok. Given the notes in this thread, I would try to get the basic on/off working first, then expand to PWM after that.

PWM should have a defined “on/off” times valid to suit the device accepting the PWM signal. it will be those times that will dictate how much play room you have.
Assume there is enough time something like

pwmTotal = 1000; // made up number for the example
pwmOn = 20; // current on time needed.
CurrentCPUTime = get time/ticks;

set PWMPin High.
wait unitl CPUTime = CurrentCPUTime + pwmOn
set PWMPin Low
wait unti CPUTime = CurrentCPUTime + pwmTotal;

then repeat if needed.

What is the pwm motor control board so we can look up the datasheet.