Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Convert string to uint8_t
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Convert string to uint8_t

by juliusau93 on Wed Apr 15, 2020 2:08 am

I have a sensor that is giving me a string value of 9.1 from Arduino#1. I would want to send this number to Arduino#2 to control a stepper motor.

Code: Select all | TOGGLE FULL SIZE
String inputstring = "";                              //a string to hold incoming data from the PC
String sensorstring = "";                                     //a string to hold the data from the Atlas Scientific product
boolean input_string_complete = false;                //have we received all the data from the PC
boolean sensor_string_complete = false;               //have we received all the data from the Atlas Scientific product
float DO;                                                            //used to hold a floating point number that is the DO
int ToArdTwo      = 7;                                         //digital Pin 7

void loop()

if (input_string_complete == true)
  {                                                 
    myserial.print(inputstring);                     
    myserial.print('\r');                             
    inputstring = "";                                 
    input_string_complete = false;                   
   }
   
while(sensor_string_complete == false)
{
  if (myserial.available() >0 )
  {
    char inchar = (char)myserial.read();             
    sensorstring += inchar;                           
    if (inchar == '\r')
    {
      sensor_string_complete = true;
    }
    else
    {
    }
  }
}


  if (sensor_string_complete == true)
  {                                                   
     Serial.print("Dissolved oxygen = ");
     Serial.println(sensorstring);
    sensorstring = "";                               
    sensor_string_complete = false;                   
  }
   


I want to do something like this to send the 9.1 signal to Arduino#2
Code: Select all | TOGGLE FULL SIZE
if(digitalRead(sensorstring) < 9.1)
 {
  digitalWrite(ToArdTwo, HIGH);     //send value from Arduino#1 digital pin 7 output to Arduino#2 digital pin 1 input
 }
 else
 { 
 }


Arduino#2 digital pin 1 input will tell a stepper motor to stop or start.

juliusau93
 
Posts: 22
Joined: Tue Dec 17, 2019 12:33 am

Re: Convert string to uint8_t

by adafruit_support_bill on Wed Apr 15, 2020 5:39 am

if(digitalRead(sensorstring) < 9.1)

It is not clear what you intended to do with this statement. But it can't possibly work. digitalRead takes a pin number as an input parameter, so it would not know what to do with a string. And it returns a 0 or a 1, so you can't compare the result to a floating-point number.
digitalWrite(ToArdTwo, HIGH); //send value from Arduino#1 digital pin 7 output to Arduino#2 digital pin 1 input

There is no practical method to use digitalWrite to send anything other than a 0 or 1 value. If you need to communicate in bytes, then you should use something like i2c or a serial port.

adafruit_support_bill
 
Posts: 78733
Joined: Sat Feb 07, 2009 10:11 am

Re: Convert string to uint8_t

by juliusau93 on Wed Apr 15, 2020 10:39 am

Thank you. I will do a manual switch from UART to I2C on the EZO circuit.

juliusau93
 
Posts: 22
Joined: Tue Dec 17, 2019 12:33 am

Please be positive and constructive with your questions and comments.