If I want to print numbers, however, it won't show anything. I'll send both my arduino code and mit block, so that you can see better. Thanks in advance!
Well, we can't see all of your Blocks. In future right-mouse in the Blocks work area and select "Download Blocks as image".
Your Arduino Sketch is very odd, where did you find it? Note that you typically have only 23 bytes for your data so you should only send values, decoration such as "T=" and "deg C" can be done in the App if required, which you seem to have discovered yourself. Your Sketch correctly uses Serial.println() to indicate end-of-data but have you set this in the App Blocks too?
...... and your data receive should be like this (note, -1 means "read all bytes")
Note that to avoid buffer overrun (aka phone lock-up or crash) it is important that the app timer interval is approx 20% faster than the Sketch Loop time interval, but it must be an adequate length of time for the App to perform the processes required. The Sketch Loop time interval should suit the task in hand. It is pointless sending values super-fast for real-time display because the human eye cannot cope with that.
the video above, so i am using an FSR sensor and i print "d" when FSR > 200 else it just prints "n", in my app i want it to trigger an alarm whenever "d" is detected but it doesnt work
TimerAlwaysFires: If the Phone is falling into 'black screen mode', you can use this setting and the timer will persist. Ensure that on exit of the App, the Clock is terminated.
Do not enable the Timer until there is a connection and the App is ready to start receiving data.
With the Sketch interval @ 400 milliseconds, the App Clock Timer interval should run @ 300 milliseconds.
The App needs to know the EOD (End of Data). Serial.println() is Ascii LineFeed Char number 10.
You should not use delay() with sensors. Please upload the full Sketch and I will modify it for you. Change the file extension to .txt
Here is a Basic BT Classic Project for you to plunder - study it carefully to take away the best tips, in particular the DelimiterByte.
There is a Procedure to exit the App - since you are using TimerAlwaysFires, set TimerAlwaysFires to false.
Note that it is best to make all Clock settings in the Blocks rather than the Designer palette, easier to use at tweaking time.
Okay thank you and in the code where u used Serial.connected, I used if(Serial) and the app connects but when I put pressure on the sensor the app doesnt seemed to respond to what it suppose to do (setting the label colour and stuff)
What we can do is set a temporary label in the GUI and just stream the data into the label without any qualification (I think my example Project does that) - we then at least know the data has been received.
Ah yes - remove if (Serial.connected()) , that's only required when using the software serial.
//BtSendChar.ino Chris Ward 28/03/2022 00:01:56
#include <Wire.h>
//vars
unsigned long lgUpdateTime;
int fsrAPin = A1; // FSR is connected to analog
int iFSR; // the Analog reading from the FSR resistor divider
void setup(void) {
Serial.begin(9600); // Send data to App
lgUpdateTime = millis();
}
void loop(void) {
if(millis() - lgUpdateTime > 400) //Loop approx every 400 milliseconds
{
lgUpdateTime = millis();
iFSR = analogRead(fsrAPin);
if (iFSR >200){
Serial.print("d");
Serial.println(); //This tells App "End of Data" = Ascii LineFeed Char Num 10
} else{
Serial.print("n");
Serial.println(); //This tells App "End of Data" = Ascii LineFeed Char Num 10
}
}
}