Dabble Bluetooth Terminal not allowing input number to be used in calculations

I am a freshman in college and my group and I are working on making a mini oven for our freshman design project. This project uses Dabble's Bluetooth Terminal to receive numbers which are supposed to be used as a basis for other calculations. As it stands, when using the Terminal.readNumber command, I can store the number and print it to the console, but when I try to call on the int value that it's supposed to carry, it's almost as if that number doesn't exist. I have reached out to Dabble's company, and have searched both the web and the forum, but I haven't seen anything similar to what I'm needing help with.

What I'm trying to accomplish is taking the Terminal.readNumber input and store it in the variable setpointF so I can then finish the rest of the temperature calculations. setpointF can be printed to the console with a value, but none of the other calculations work.

I am also using an Arduino Uno board and an HC-05 Bluetooth module with the Dabble app and Library

#define CUSTOM_SETTINGS
#define INCLUDE_TERMINAL_MODULE
#include <Dabble.h>

float setpointF ;
float setpointC;
int setpointA;
int stdev = 1;
int UCL = 0;
int LCL = 0;
int currentTempA = 0;
float currentTempC = 0;
float currentTempF = 0;

int RGBTemp;
int redRGB = 0;
int blueRGB = 0;
int low = 0;
int high = 255;

int redPin = 9;
int bluePin = 11;
int heaterPin = 7;
int fanPin = 4;

int fan;
int heater;

void setup() {
  pinMode(heaterPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  Dabble.begin(9600);
  Serial.begin(9600);
  
  Terminal.println("Set Temperature?");
}

void loop() {
//The problem starts here
  Dabble.processInput();
  int termNum = Terminal.readNumber();
  if(termNum > 90 && termNum <= 150) {
    setpointF = termNum;
    Terminal.print("Setting to ");Terminal.print(setpointF);Terminal.println(" Degrees F");
  }
  if(Terminal.compareString("warm")) {
    setpointF = 150;
    Terminal.println("Setting to 150 Degrees F");
  }

  setpointC = (setpointF - 32) * (5 / 9);
  //setpointA = (11.702 * setpointC) + 241.57;
  //The problem ends here

  UCL = (11.702 * (((setpointF + (stdev * 3)) - 32) * (5/9))) + 241.57;
  LCL = (11.702 * (((setpointF - (stdev * 3)) - 32) * (5/9))) + 241.57;
  
  currentTempA = analogRead(5);
  RGBTemp = currentTempA;
  
  currentTempC = ((.0855 * currentTempA) - 20.644);
  currentTempF = ((currentTempC * (9 / 5)) + 32);
  
  redRGB = map(RGBTemp, LCL, UCL, low, high);
  blueRGB = map(RGBTemp, LCL, UCL, high, low);
  
  Serial.println("   LCL       Analog Setpoint       Fahrenheit Setpoint       UCL       Analog Temperature       Fahrenheit Temperature");
  Serial.print("   ");Serial.print(LCL);Serial.print("        ");
  Serial.print(setpointC);Serial.print("                   ");
  Serial.print(setpointF);Serial.print("                    ");
  Serial.print(UCL);Serial.print("         ");
  Serial.print(currentTempA);Serial.print("                  ");
  Serial.println(currentTempF);
  Terminal.print("The current temp is ");Terminal.print(currentTempF);Terminal.println(" Degrees F");
  
  if(((RGBTemp < LCL) || (RGBTemp == LCL))) {
    redRGB = 0;
    blueRGB = 255;
    
    digitalWrite(heaterPin, HIGH);
    
    analogWrite(redPin, redRGB);
    analogWrite(bluePin, blueRGB);

    Serial.print("Red RGB = ");Serial.println(redRGB);
    Serial.print("Blue RGB = ");Serial.println(blueRGB);
  }
  
  if((RGBTemp < setpointA)) {
    digitalWrite(fanPin, LOW);
  }
  
  if(((RGBTemp > UCL) || (RGBTemp == UCL))) {
    redRGB = 255;
    blueRGB = 0;
    
    digitalWrite(heaterPin, LOW);
    digitalWrite(fanPin, HIGH);
    
    analogWrite(redPin, redRGB);
    analogWrite(bluePin, blueRGB);

    Serial.print("Red RGB = ");Serial.println(redRGB);
    Serial.print("Blue RGB = ");Serial.println(blueRGB);
  }
  
  if(((RGBTemp > LCL) && (RGBTemp < UCL))) {
    analogWrite(redPin, redRGB);
    analogWrite(bluePin, blueRGB);

    Serial.print("Red RGB = ");Serial.println(redRGB);
    Serial.print("Blue RGB = ");Serial.println(blueRGB);
  }
  
  heater = digitalRead(heaterPin);
  fan = digitalRead(fanPin);
  
  if((heater == 0)) {
    Serial.println("Heater = Off");
  }
  
  if((heater == 1)) {
    Serial.println("Heater = On");
  }
  
  if((fan == 0)) {
    Serial.println("Fan = Off");
  }
  
  if((fan == 1)) {
    Serial.println("Fan = On");
  }
  
  Serial.println();
  Serial.println();
  delay(4000);
}

What Arduino board?

Post a schematic, please.

you might want to check if Terminal.available(): before calling Terminal.readNumber();

Thank you, I knew I was forgetting something. It's and Arudino Uno board and an HC-05 Bluetooth Module

How would you recommend going about that?

Take a look at the Dabble library example 02.Terminal which show how to read when .avaliable() != 0

Alright, Thank you

So I went and implemented this part of the code

if(Terminal.available())
  {
    while (Terminal.available() != 0)
    {
      Serial.write(Terminal.read());
    }
    Serial.println();
  }

so that my code now looks like this:

Dabble.processInput();
  if(Terminal.available())
  {
    while (Terminal.available() != 0){
      Serial.write(Terminal.read());
    }
  }
  termNum = Terminal.readNumber();
  if(termNum > 90 && termNum <= 150) {
    setpointF = termNum;
    Terminal.print("Setting to ");Terminal.print(setpointF);Terminal.println(" Degrees F");
  }
  if(Terminal.compareString("warm")) {
    setpointF = 150;
    Terminal.println("Setting to 150 Degrees F");
  }

and both the terminal and the console are not receiving the inputs now.

Try this for receiving the number

Dabble.processInput();
  if(Terminal.available())
  {
    while (Terminal.available() != 0){
      //Serial.write(Terminal.read());
      termNum = Terminal.readNumber();
    }
  }
  Serial.println(termNum);
  //termNum = Terminal.readNumber();
  if(termNum > 90 && termNum <= 150) {
    setpointF = termNum;
    Terminal.print("Setting to ");Terminal.print(setpointF);Terminal.println(" Degrees F");
  }

probably (?) the second part should be within the if(Terminal.available()) otherwise it will always be executed even if you did not read anything and termNum has not been initialized

Yes, I think you are correct.
Revised Code for OP

Dabble.processInput();
if (Terminal.available())
{
  while (Terminal.available() != 0)
  {
    //Serial.write(Terminal.read());
    termNum = Terminal.readNumber();
  }
  Serial.println(termNum);
  //termNum = Terminal.readNumber();
  if (termNum > 90 && termNum <= 150)
  {
    setpointF = termNum;
    Terminal.print("Setting to "); Terminal.print(setpointF); Terminal.println(" Degrees F");
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.