Hello.
I am just getting started with AppInventor and have created a simple Android app which just needs to send a character to my Arduino based upon the click of a button. I have a BLE device on my Arduino (SH-HC-08), so I have, within the last day, downloaded and installed the BluetoothLE extension. I can connect successfully from the app using the MAC address. I can also connect by scanning and finding the device and connecting to it that way. So connection is all good.
The manufacturer DSD Tech provides a simplistic app that can send and receive text with my application. That connects and works fine. My intent with MIT AppInventor is to create a more tailored app for my application rather than manually typing in and seeing text strings to/from my Arduino.
Where I'm having trouble is sending any kind of data. For the BLE device, it looks like my options are things like WriteByte, WriteString, WriteShort, etc. So I am trying to use WriteString:
I double checked my UUIDs (which are the same) and they are correct. I've tried various ways of doing this. Here, I directly provide a constant string for the value. I also tried providing a list of one element, that element being the one string I wish to send. On every attempt, a call to WriteString just crashes the app instantly. It exits suddenly with no message or other indication.
I see others are successfully using the BLE extension and these particular Write methods, so I assume this is something I'm doing wrong, or maybe something's gotten corrupted? I did a lot of searching and I don't see anyone else reporting this experience. I'm looking for a little advice on how to resolve it. Do I need to start fresh and reconstruct the app?
Thank you!
UPDATE: Here's the whole collection of app blocks:
Here's the associates sketch:
float temperatureCtoF(float t) {
return (t * 9.0)/5.0 + 32.0;
}
float temperatureFtoC(float t) {
return (t - 32)*5.0/9.0;
}
// R from V, given that the series resistor (Rs) goes to ground
//
float computeRfromV(float V) {
const float Rs = 10010; // Series resistor
return (Rs * (1023.0 - V)) / V;
}
// Simpler formula, using B coefficient
// Compared to an independent sensor, this formula appears more accurate
//
float computeTemperature(int Vo) {
const float B = 3950; // Middle value taken from the data sheet
// Computed as ln(Rt1/Rt2)/(1/t1 - 1/t2)
const float Rt = 10950; // Resistance of thermistor at nominal temp
const float T0F = 75; // Nominal temp (F)
float R = computeRfromV(Vo);
float T0 = temperatureFtoC(T0F) + 273.15; // nominal room temperature, degK
float Tc = (B * T0) / (B + T0*log(R/Rt)) - 273.15;
return Tc;
}
float average(float value) {
const byte nvalues = 8;
static byte current = 0; // Inde for current value
static float sum = value * nvalues;
static bool first = true;
static float values[nvalues];
if (first) {
for (int i = 0; i < nvalues; i++)
values[i] = value;
}
else {
sum = sum - values[current] + value;
if (++current >= nvalues)
current = 0;
values[current] = value;
}
return sum/nvalues;
}
volatile char scale = 'F';
void displayTemperature(float temp, char scale) {
if ( scale == 'F' )
temp = temperatureCtoF(temp);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(scale);
}
void getTemperature() {
static char last_scale = scale;
static int last_temp = 9999;
int V0 = analogRead(A1);
float Tc = computeTemperature(V0);
int t = Tc;
if ( t != last_temp || scale != last_scale ) {
displayTemperature(t, scale);
last_scale = scale;
last_temp = t;
}
}
void setup() {
// Serial port for tracing/debugging
Serial.begin(115200);
// Configure bluetooth serial
Serial1.begin(9600);
}
void loop() {
const uint32_t tempReadTime = 1000; // Read temperature once per second
static uint32_t lastTime = millis();
// Check to see if we have a bluetooth request to change the temperature scale
if (Serial1.available()) {
char s = Serial1.read();
if (s == 'C' || s == 'F') {
scale = s;
Serial1.print(scale);
}
}
uint32_t currentTime = millis();
if (currentTime - lastTime > tempReadTime) {
getTemperature();
lastTime = currentTime;
}
}