Arduino and app interactions

Hi,

I'm aware that you can use apps to control your Arduino projects but what about the other way around? For example, can data read from a sensor using an Arduino be interpreted by the app itself and then output a particular display.

Say I have a temperature sensor and I want my app to use the data from the Arduino to create a quirky thermometer scale that returns an image representing the temp (e.g. snowflake, fire etc).

Thank you, any guidance would be greatly appreciated.

What language are you using?

I haven't used anything just yet. Just wanted to know if it was doable and the best way to approach it.

Any language suggestions appreciated.

I was originally thinking to create the app using Xcode and perhaps importing sensor data from the Arduino via bluetooth for the app to respond to.

Writing code for the Arduino to send data via Bluetooth is the easy part.

Writing code that works on a smartphone is the hard part.
Choose whichever language you know and use it to write your app.
While getting apps that are not in the Google Play store onto an Android smartphone is not difficult last I did it,
it is a different story for iPhones.

.

So the way to approach this would be to export data from the Arduino into my code for the app to interpret and output accordingly.

Are there any app development softwares you would recommend? Also my preferred language is C++ but I am open to to others. Thanks.

ghostnote_hans:
So the way to approach this would be to export data from the Arduino into my code for the app to interpret and output accordingly.

If that means what I think it means then it is all wrong.

The code for your app is written once and then the app is uploaded to your phone. I presume you will wish the Arduino to send data to the app lots of times. That means that the app must contain the necessary code to receive data from the Arduino. Using Bluetooth may be the simplest way but WiFi is another obvious choice.

Are there any app development softwares you would recommend? Also my preferred language is C++ but I am open to to others. Thanks.

A lot depends on the eventual artistic quality of the app that you want to create. If you want to create a polished app that looks good enough that someone would pay money for it then you will probably need to use one of the advanced app creation systems. You should use Google to find them. I suspect they will all have a steep learning curve. I don't think any of them use C++. Java is the standard Android language. I believe there is a newer language called Kotlin that is claimed to be easier to use - but I suspect it is just easier relative to the very arcane Java.

Another thing to be conscious of is the requirement of Android apps (I have no experience of iPhone stuff) to obtain "permissions" for the use of various features on the phone. This is very different from the free-and-easy way that PC programs can be created and distributed.

If you just want to create a simple app for your own use and are more concerned that it be functional rather than beautiful I suggest that you use Pydroid or QPython (which use the Python language) and create an app that uses the browser as the display mechanism. That way the visual design can be done with HTML and CSS. You can use the Python Bottle web framework with Pydroid and QPython. I think Pydroid is slightly easier to use. The other convenient thing is that you could probably create the whole thing on your PC with regular Python and then copy it over to your phone - maybe with some minor tweaking needed.

There is also a Python library called Kivy that allows you to create native Android (and IPhone) apps but, again, there is a steep learning curve and I have so far have had no need to create a native app.

Finally, if you are content to run the program on your PC and just view it on your phone's browser (via WiFi) then, of course, there is no need for any app on the phone. That would avoid any requirement for the Arduino to communicate with the phone.

...R

Thank you very much for the lengthy response :slight_smile:

You're right I would rather my app be more functional rather than look really nice. I'd be happy for it to display as a webpage too.

So the best approach would be to use python to create my code and have this interface with the Arduino to receive its data (via bluetooth or wifi). With that data i'd be able to output a diagram using python (e.g. a thermometer scale with images such as a snowflake) which can then be updated on the webpage?

Thank you for the help so far.

There are many ways to do this. A common approach is for the Arduino to send the data to a persistent store somewhere and for your app to get it from there. Then you're not reliant on your phone being in Bluetooth range of the Arduino.

You can keep the information in a database of your own or perhaps use an existing IOT service in the cloud - there are a number of them with free tiers. Then your phone can display your stuff from anywhere in the world where you have connectivity. Many IOT services already have the facility to make dashboards and in that case, you would not even have to write an app. MQTT is another thing to look at.

wildbill:
There are many ways to do this. A common approach is for the Arduino to send the data to a persistent store somewhere and for your app to get it from there. Then you're not reliant on your phone being in Bluetooth range of the Arduino.

I had not thought of that. It would be quite compatible with what I said in Reply #5

I guess it depends on whether the OP will always be using the App within wireless range of the Arduino or whether he wishes to be able to use it from a much greater distance.

Another point ... if the Arduino program will be using WiFi to send data (wherever) an ESP8266 or ESP32 board might make sense as they are cheap and have built in WiFi. The ESP32 also has Bluetooth. Both can be programmed with the Arduino IDE.

And more ... if you use an ESP32 and if it can be set up so it is accessible from the public internet then it could host the server that produces the images so there would be no need for an app on the phone. It would just connect with the ESP32 using the browser. And, going back to a preference from the Original Post, the ESP32 would be programmed in C++. However my own opinion is that it would be a lot easier to create the web program using Python and Bottle. Web programs are mostly about text and C++ is not convenient for that.

...R

Thank you. I suppose my biggest concern is actually receiving the data from the Arduino and updating my diagram/image. I do like the sound of the webpage display mentioned in the earlier reply as that sounds more straightforward.

Do you think programming in python is a good way to go to create my diagram and have it updated with the data from my Arduino?

ghostnote_hans:
Thank you. I suppose my biggest concern is actually receiving the data from the Arduino and updating my diagram/image. I do like the sound of the webpage display mentioned in the earlier reply as that sounds more straightforward.

Do you think programming in python is a good way to go to create my diagram and have it updated with the data from my Arduino?

I suggest that you figure out your overall architecture (and requirements) first. Then choose whichever language you like for the non-Arduino bits. On the Arduino side, as far as I know, you have C++ or C++. Actually, I think some of the Adafruit variants can use Micro-Python, so if you're a Python fan you can use it for multiple parts of your project.

ghostnote_hans:
Do you think programming in python is a good way to go to create my diagram and have it updated with the data from my Arduino?

In what I suggested earlier the diagram would be created using HTML and CSS. The Python code would create the webserver that presents the HTML and CSS files in response to requests from the browser.

If you are thinking seriously of going down that route I suggest you get Python and Bottle working on your PC. With it you can have a very basic web server working (just on your PC) in 10 or 20 minutes. That way you can see whether you like the idea for very little effort.

Another way of creating a GUI (graphical user interface) with Python is using the TKinter library. I believe that works on Pydroid. However I gave up using it as I found it tedious to program and its appearance has not advanced much since the style of Windows3.

...R

Thanks i’ll give that a go.

This may be a stupid question but say I did all that you said with creating the webserver using python. Would that mean that if I gave my arduino with the sensors to a friend to use. Would they have to download python as well to coordinate the sensor data in order for them to see their diagram on the webpage?

Also I presume it’s python that will coordinate the data from my arduino sensors?

ghostnote_hans:
Would that mean that if I gave my arduino with the sensors to a friend to use. Would they have to download python as well to coordinate the sensor data in order for them to see their diagram on the webpage?

Assuming you have built your App on your Android phone using Pydroid then, yes, if you want to run the App on another Android phone that would also need Pydroid.

The alternative is to make a native Android App - but as I said earlier that almost certainly involves a steeper learning curve.

...R

Ahh I see. I think ultimately I would like to share this project with someone by them just taking my arduino and sensors and not have to download anything except maybe an app out of convenience but I will start with the web-server approach for now.

Is there not a way to have the code stored in the arduino that can carry out the task which is then viewable on a web browser, bypassing the need for a PC?

In the same way how a simple project like using motion sensors to light up an LED has no need for a PC?

ghostnote_hans:
Is there not a way to have the code stored in the arduino that can carry out the task which is then viewable on a web browser, bypassing the need for a PC?

In the same way how a simple project like using motion sensors to light up an LED has no need for a PC?

I really think you need to educate yourself about the business of creating projects for smartphones so that you are aware of the options and can then make a rational decision about what is appropriate for your project and your preparedness to spend time developing it. Google can find you a huge amount of information about this. What we say here is no substitute for you gaining your own understanding of the issues.

At the bottom of Reply #8 I mentioned the possibility of hosting the web server on an ESP32 - that way all that would be needed on the smartphone (any phone) is a browser - and a WiFi connection to the ESP32. Someone else mentioned that an ESP32 can also be programmed with MicroPython - which might be simpler way to create a web program than using C++

...R

Yes will give it all a read. I just wanted to know how an expert would approach this project and not waste time going down the wrong route.

I think I got carried away asking questions.

Thank you for all your help!

ghostnote_hans:
Yes will give it all a read. I just wanted to know how an expert would approach this project and not waste time going down the wrong route.!

The problem is that an expert will know a great deal more than you (or me) and he (or she) will choose a solution that builds on that expertise. Experts will be quick to tell you that XXX is the by far the best way to build an app. But that is usually only true for someone who has the same expertise as the expert.

The other essential point is that the expert is an expert because he has spent hundreds or thousands of hours doing that stuff.

Non-experts like you and me have to find a solution that delivers an acceptable product with the amount of effort we are prepared to devote to the project.

I have dabbled with various programming things and have concluded that, for me, building my apps using Python, Bottle, HTML and CSS gives me an acceptable product with an acceptable amount of effort. I have been a hobby programmer for about 40 years and what I know now is an accumulation of bits and pieces that I have picked up along the way. You might conclude that what satisfies me is not suitable for you. But it is my firm belief that you will need to experiment with at least some of the options before you can make up your own mind.

...R

Fair enough. I see your point. I think i’ll research all that you guys have said and make a decision.

Thank you once again!