This code snippet might help you:
The best method would be to connect the arduino to the internet. Then you could save data all the time without android help. The android app could only be used to read the saved data.
What about using TinyDb is there a way to save it directly through the app
Well, if you want to use TinyDB, you can do it. Thought you wanted to use some external database. You just have to remember that the phone screen must be on all the time for your app to work and read data from arduino.
Noted, and no external database will be necessary.
Essentially, I'll need to receive data from the arduino via bluetooth (HC-05), plot that data in real time on a line graph and then store that data so it can be viewed at a later time.
How can I go about doing this?
Hi, Was there ever a solution to this? I'm doing something almost exactly the same and I've been struggling to store the data. Any suggestions would be greatly appreciated.
Hello zy wang
Do you want to send the data to your App and let the App manage the storage?
So I've got an Arduino sensor that is sending data to the app via bluetooth. I have this part down already. I want to be able to store the live data in some type of file (preferably excel) so I'm able to access and analyse the data at a later point. My current data is appearing in a label live, but once it scrolls out of sight, it is gone. Thanks
The solution would be a neutral CSV file. You could stream it into a file without displaying it in the App, or you could display it in a variety of ways (Chart?) by importing the .csv the App has saved. The file can be stored in the App's ASD (App Specific Directory), which is the default in App Inventor. If you want to examine the file with a separate App you can share the file by copying it to a Shared Folder such as Documents or upload it to the Cloud if you want to use a PC to work on it.
What is the Arduino Model?
What Bluetooth are you using, Classic or BLE?
Also, how often and for how long is the data sent? This affects whether the file can simply be built in the Apps memory allocation or incrementally added to the file (file append) directly in the directory.
I'm currently using an Arduino uno with a HC-05 Bluetooth classic module. Data point sent every 50ms and the length of time for the dat can range from 30s to 5 minutes.
On a side note, if I were to change to arduino nano 33 ble, would the file location and type have to change?
Thanks so much
No, not at all. A lot of the App code would need to be replaced and the Arduino Sketch too, because BLE is a different animal. Also, your Android device would need to have BLE.
Does it really need to be that frequent? The Golden Rule for collecting sensor data is to use the longest time interval possible that still satisfies the goal of the Project.
5 minutes @ 50 milliseconds = 6000 records.
Enable the Clock Timer "Clock_TimerDataReceive" when the Bluetooth connection is made.
Ensure that all Clock Timers are disabled before the App is exited (and before changing to another Screen in the App if applicable).
StreamSensorData.aia (3.6 KB)
That makes sense. I trying to find the peak point of a chemical based reaction so the more points I have, the more accurate I'm able to pin the point hence the frequency. I haven't found the best interval of time yet so the frequency of data collection can definitely be changed and tweaked.
Thank you so much for the help, I will try the code out
This may be a stupid question. I'm still a beginner so trying to learn as much as I can. The code you provided seem to have worked but I have no idea where to find the actual file when saved. Would you mind explaining to me what each part of the code means and where the file might be saved? I really just want to have the data that's coming in saved somewhere so I can access it for analysis later.
Sorry for all the questions, there's just a lot of materials online and I'm struggling to put the bits together.
Thanks so much
The file is stored in ASD - Application specific directory, see also Some basics on Android storage system
You can access that directory with a good file manager, for example Total Commander
Which parts of the blocks do you have problems with?
A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .
Hi zy wang
Well, the file location defaults to the App's ASD (App Specific Directory). When you run the App, the filename is initially displayed in Label_Msg. The name is saved as a global variable "SensorValueFile"
You can load the file into your App (put the contents in a Label that has automatic height for example):
Amazing, it worked thank you so much for the help