#include <Arduino.h>
const int adcPin = A0;
#include <EEPROM.h>
#include "GravityTDS.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define TdsSensorPin A1
GravityTDS gravityTds;
float temperature = 25,tdsValue = 0;
const float m = -5.436;
void setup()
{
Serial.begin(9600);
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin();
sensors.begin();
delay(1000);
}
void loop()
{
//temperature = readTemperature(); //add your temperature sensor and read it
gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print(tdsValue,0);
Serial.print(",");
float Po = analogRead(adcPin) * 5.0 / 1024;
float phValue = 7 - (2.5 - Po) * m;
Serial.print(phValue);
Serial.print(",");
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1024.0);
Serial.print(voltage);
Serial.print(",");
;
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.print(sensors.getTempCByIndex(0));
Serial.println(",");
delay(1000);
}
Instead of a | use a comma. On the other hand, I would rewrite the arduino code a bit and modify the blocks a bit.
i used it gives same error
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.
Upload it to arduino. Set the DelimiterByte as instructed by ABG
#include <Arduino.h>
const int adcPin = A0;
#include <EEPROM.h>
#include "GravityTDS.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define TdsSensorPin A1
GravityTDS gravityTds;
float temperature = 25,tdsValue = 0;
const float m = -5.436;
void setup()
{
Serial.begin(9600);
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin();
sensors.begin();
delay(1000);
}
void loop()
{
//temperature = readTemperature(); //add your temperature sensor and read it
gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print(tdsValue,0);
Serial.print("|");
float Po = analogRead(adcPin) * 5.0 / 1024;
float phValue = 7 - (2.5 - Po) * m;
Serial.print(phValue);
Serial.print("|");
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1024.0);
Serial.print(voltage);
Serial.print("|");
;
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}
tell about block blocks
this
is all blocks for four sensors readings
Exactly, you have blocks. Just add text break to "|" to get the list, in procedure "process"
No.
This solves the problem of getting incomplete messages.
It is up to you to add blocks to the process procedure to
- split the input message at ','
- store the split list into a variable
- check if the length of list of the variable is at least 4
- handle items 1 to 4, or complain if too short.
this showing all readings in one block i have four and four block for readings i want to show in differents blocks
thaxx alot
Give or take a '|' or a ','
I corrected his arduino code to "|".
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.