Serial Monitor input for valve positioning TEST IND.IO

I'm sure this is just something easy that I don't know, but for testing purposes, I wanted to pass a 0-10VDC signal to a valve I am testing and I wanted to do it through the serial Monitor. I've played around and I can't get it to recognize anything I pass via the monitor.  I do have SerialUSB.begin(9600) and while (!SerialUSB) in my setup portion of the code. I've also noticed that the window freezes after about three inputs.  I'm sure its something fundamental that I am missing. Thanks!

I had this included in my code to capture input ANY INPUT, and I get nothing.       

if (SerialUSB.available() > 0) {

                // read the incoming byte:
                incomingByte = SerialUSB.read();

                // say what you got:
                SerialUSB.print("I received: ");
                SerialUSB.println(incomingByte, DEC);
        }

Kelly Sprayberry
Kelly Sprayberry
34
| 2 1 2
Asked on 12/10/18, 6:32 PM
0
vote
2487 Views

 That works! Thanks Tom! Had to come back and edit this. It works without anything to do with Analogread statements If you comment out these two lines, this works fine, but will not accept input if they're not commented out.

  mAValue = Indio.analogRead(1);
  myhumid = Indio.analogRead(2);

Could it be for the moment I am running it on USB power only? No 12 or 24V .......YEP! That's IT. I turned on my 12 volt wall wart and Voila, its working. 

#include <Indio.h> //load Indio library

String inString = "";    // string to hold input

float lastvalvesetpoint = 0;
float valvesetpoint;
int myhumid;
int inputInt = 0;
float inputFloat = 0.0;
float temp;
int mAValue;
float sensorVal1, sensorVal2, sensorVal3, sensorVal4; //variables to hold your sensor data
char p;  
float valvepot;


 
void setup() {
  // Open serial communications and wait for port to open:
  SerialUSB.begin(9600);
  while (!SerialUSB) {
    ; // wait for SerialUSB port to connect. Needed for native USB port only
  }

  Indio.setADCResolution(16); // Set the ADC resolution. Choices are 12bit@240SPS, 14bit@60SPS, 16bit@15SPS and 18bit@3.75SPS.
  Indio.analogReadMode(1, mA); // Set Analog-In CH1 to mA mode (0-20mA).
  Indio.analogReadMode(2, V10); 
  Indio.analogReadMode(3, mA); // Set Analog-In CH3 to mA mode (0-20mA).
  Indio.analogReadMode(4, V10); // Set Analog-In CH4 to mA mode (0-20mA).
  Indio.analogWriteMode(1,V10);


  // send an intro:
  SerialUSB.println("\n\nString toInt():");
  SerialUSB.println();
}

void loop() {
  // Read SerialUSB input:
  while (SerialUSB.available() > 0) {
    int inChar = SerialUSB.read();
    if (isDigit(inChar)) {
      // convert the incoming byte to a char and add it to the string:
      inString += (char)inChar;
    }
    // if you get a newline, print the string, then the string's value:
    if (inChar == '\n') {
      SerialUSB.print("Value:");
      SerialUSB.println(inString.toInt());
      SerialUSB.print("String: ");
      SerialUSB.println(inString);
      // clear the string for new input:
      inString = "";
    }
  }


  mAValue = Indio.analogRead(1);
  myhumid = Indio.analogRead(2);


  temp = ((mAValue*2)*1.8)+32; // convert mA to a temperature value (in celsius)...
  delay(500);
 Indio.analogWrite(1, valvepot, false);

}

Kelly Sprayberry
Kelly Sprayberry
34
| 2 1 2
Answered on 12/11/18, 12:36 PM
0
vote

Hi, i just tested below code and it works without problem, can you try please.

The Serial Monitor will show the ASCII value of the input, including NL (new line) and CR (carriage return) if your Serial Monitor is configured to do so; you can get rid of them by selecting 'no line ending'. If you need to read anything more than 1 char, look into the parseInt() function.

 

void setup() {
  // put your setup code here, to run once:
  SerialUSB.begin(9600);
  while (!SerialUSB) {}
}

void loop() {
  // put your main code here, to run repeatedly:
  if (SerialUSB.available() > 0) {
    byte incoming = SerialUSB.read();
    SerialUSB.print("received: ");
    SerialUSB.println(incoming, DEC);
  }
}

Tom
Tom
5675
| 1 1 3
Answered on 12/11/18, 2:17 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

51 follower(s)

Stats

Asked: 12/10/18, 6:32 PM
Seen: 2487 times
Last updated: 12/11/18, 2:58 PM