Creating my own Android App

Hello folks :blush:

First, I’m gonna put you guys in context:
I am developing a desing for EEG using Spark, so I currently can get the wave form through Serial port of Spark and visualize it in Matlab. I had to turn off the cloud due to sample rate I needed is higher than loop with spark cloud on. Now, if I want to visualize this wave form in my cellphone I need to turn on wifi, send data and turn off wifi afterwards so I can get more data… and so on. I fear that the time between sending code to turn on wifi and connect the cloud be late (a couple of seconds), but it’s a trouble that I could see at another time.
I know that my startpoint is to use the andoid app source code.

I get 216 bits for each data (there are 9 channels with 24 bits each one, I got 216bits as one), which are 500 (my sample rate) data per second. What I need is to store them for maybe (not exactly) 10 seconds while wifi is turned off and then send them. Using serialprint I don’t have any problem because I get the data and automatically send it (do not need the cloud).
My point is: Anyone could point me out a good place to start if I want store too many data so I can send them through cloud. It is possible? I would be very grateful.
I am sorry for the parchment by the way.


@afromero, 9 samples of 3 bytes each (24 bits) is 27 bytes per second. At 500 samples per second, that’s 13,500 bytes of data per second! For 10 seconds, that is 135,000 bytes!

The Core core does not have enough RAM for even a 1 second sample size. Using the external flash of the Core via the flashee-eeprom library will allow to store a 10 second sample but you may wear out the flash if you write very frequently to it. You could use @kennethlimcp’s SPI FRAM/SD shield with two 64Kx8 FRAM chips or the on-board SD and I think the read/write speed on the SD is fast enough to handle the data rate. The SD would allow you to store a long run of data which you can then transmit as required.

Another thing is you can do interrupt-based sampling of your EEG data, avoiding the timing limitations of loop(). You interrupt service routine would buffer the data and your loop() program could then send it at regular intervals. :smile:


Hello @peekay123
I don’t know if I get what you told me at the forum. What you mean is can I use Spark core in AutomaticMode and only interrupt it when I need to read my 216 bits per sample (500 samples per second) and everyone of them? Do I need to use AttachInterrupt? I would really appreciate it. :smile:

how did you turn off the cloud?

@afromero, You could use a hardware timer (SparkIntervalTimer) to create a 2ms (500 samples/s) timer interrupt to sample your data, assuming the sampling is fast so as not to delay the interrupt service routine. The data would go in a circular buffer, possibly on FRAM, SD or external flash, which would be “flushed” by loop() at regular intervals. You could stop the timer interrupts when you are sending the data in loop() so your buffer is not over-written. That is the gist of the idea. :smile:

@silashowe, please read the documentation before asking these questions :smile:

Hi @peekay123, I’m having some troubles here. This is for my thesis, I spoke with my tutor and he told me that it’s not possible a lost of data, so we couldn’t afford a stop in timer interrupts. I proposed a solution but I don’t know if it’s possible, so I would really really appreciate it if you can give me a hand with this:
Could I send only 24bits (just one channel, maybe 3 at most) through wifi so I can proccess it (at cellphone) every time I get data with interruptions? So I don’t lose any EEG data. Data rate of wifi spark can afford this? Every 2ms sending 24bits?
Very thankful for all you have done for me.

@afromero, I doubt you could get 24bits of data sent every 2ms to your phone since it would have to do so via the cloud which limits updates to once per second. Even with a local cloud, 2ms intervals may be difficult. You may be able to reduce the data bandwidth if you can do some pre-processing in the Core. What is your data processing requirement (ie what do you do with the data)? Do you average, do you run fast fourier, etc?

We want to process data with fourier transform. What is the maximun data rate I need if I want to send through wifi? (Ie I do not know what is the data rate for wifi spark).
I think I have a really big problem here.

@afromero, you will have to experiment but perhaps @BDub and @mdma can advise.