BLE112

Tinyduino BLE and Accelerometer demo

A demo sketch that carries Bosch’s BMA250 accelerometer data over BLE specifically for the TinyDuino BLE shield and accelerometer shield.

The sketch is available here: Sketch

An android app for it is available here: App

Note the app was designed for a more complex sketch, therefore all the functions in the app such as “Sample Rate” and “Frequency Sweep” will not be available. You can still export accelerometer data from the app to the phone’s SD Card however.

Have fun!

Extracting Bio-impedance Parameters from Measured Data

First post of the new year! I figured, I’d start with something interesting.

Over winter break, I went home to the lovely warmth of West Africa, and had an epiphany of sorts as to how to extract the resistive values for intracellular water (ICW), extracellular water (ECW) and the capacitive value for the cell membrane after performing a frequency sweep on biological tissue (or model circuit) of interest.

(more…)

Hypothesis confirmed: Software serial libraries are bad for complex sketches

Earlier today I tested the Z_BLE_3 sketch on an Arduino Mega using its hardware serial and the results were fantastic.

It just goes to show, you may have a pretty good software serial library, but it’s nowhere near as good as the real hardware serial.

Downsides of software serial libraries

The default Arduino SoftwareSerial library proved to be non-tolerant with simple libraries when used for BLE communication, even more so with fairly complex libraries on top of that.

We switched to Paul Stoffregen’s AltSoftSerial library and things have been great… till now. From the documentation:

Interrupt Latency Requirements

AltSoftSerial can withstand approximately 1 bit time of interrupt latency from other libraries or functions. Most libraries, HardwareSerial, and the millis() timekeeping interrupt are designed to minimize CPU time spend executing interrupts or accessing data with interrupts disabled.
However, some libraries may disable interrupts for longer than 1 bit time. If they do, AltSoftSerial will not work properly. If you discover erroneous results from AltSoftSerial, please try testing without other libraries.

SoftwareSerial would break with relatively low complexity I2C communication using Arduino’s Wire library, it proved impossible to use with the AD5933 library for similar reasons.

AltSoftSerial works very well in this regard, but as we begin to write multiple sampling rates and frequency sweeps that request timer interrupts and reset commands to the AD5933 more frequently, the time window for interrupts to be handled shrink considerably.

With the sketch BLE_Debug_Timer that just carries a psuedo sine signal, setting a sampling rate of 90 Hz is no issue. Z_BLE_3 however that has to measure and send impedance values, breaks at sampling rates over 80 Hz and completely garbles serial communication with AltSoftSerial library, you only need to look at Arduino’s serial monitor to see the gibberish it spouts and functions it calls that it really shouldn’t.

We therefore probably need to move to the Arduino Mega for development and use the multiple hardware serial port it provides for BLE communication.

All this of course is a working hypothesis, I will be testing my claims tomorrow in lab, but I’m fairly certain they’re right from past experience with SoftwareSerial and AltSoftSerial.

On we go again.

Updating Gatt Structure on Android App after Change on Slave / Peripheral

If your Android app has paired with your device before, and you update the Gatt structure of your BLE Slave / Peripheral, you will need to clear the cache Android side, else the Android app will continue to show the old Gatt structure.

To clear the cache, all you need to do is toggle Bluetooth on and off. With this done, the cache should be clear and your new Gatt structure will be picked up when you scan and connect to your device again.