I checked to see if there was a question like this specific for the MIT app and some were close but did not address the issue. I tried something with a previous help suggestion: the arduinoBluetoothClient = PollingRate from 0 to 10, but did not work.
Here is an example file that you can copy from (via Backpack), to make your code more robust. Note for example that you must set a Delimiter Byte to tell the App where the end of the data is.
You must also ensure that the App time interval is approx 20% faster than the Arduino time interval to ensure the App can process the data packet before receiving the next one. Note that the Arduino time interval should be as long as is practical for the goal of the App to be met. Since you are receiving a sensor reading, use a millisecond time lapse to control the Arduino time interval, rather than a delay() - delay() can have a negative effect on the accuracy of the sensor reading.
The error you are receiving is, in cases like this, usually related to what is being sent by the Arduino - the message implies that there may be two values being sent in one data packet. If you are not sure (perhaps you didn't write the Arduino Sketch yourself), upload the .ino file to your Topic (the file, not the text of the file).
Here is my standard Delimiter advice, in case the previous posts missed something ...
Please see the Delimiter article in FAQ
Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.
In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.
In your Clock Timer, you should check
Is the BlueTooth Client still Connected?
Is Bytes Available > 0?
IF Bytes Available > 0 THEN
set message var to BT.ReceiveText(-1)
This takes advantage of a special case in the ReceiveText block:
ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.
Thank you for the response, but I do not understand it.
Within the code [not the blocks in the MIT App Inventor] I have this below but the error seems to me I need to modify something at the Block area.
Thanks,
RichardM
*/ #include <OneWire.h> #include <DallasTemperature.h>
// Data wire is connected to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
unsigned long previousMillis = 0;
const long interval = 5000;
void setup() {
// Start up the library
sensors.begin();
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// Call sensors.requestTemperatures() to issue a
// global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
// Celsius temperature
// Why "byIndex"? You can have more than one IC
// on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
//Fahrenheit temperature //Serial.println(sensors.getTempFByIndex(0));
}
Thanks for the comment. I do not find how to add those comments in the blocks or change it to that...couldn't find the specific blocks. Not sure how to proceed.
It looks like you do not understand what we are suggesting... I therefore recommend you to take a step back to first learn the basics and after that continue with your project...