Understanding buffer/itoa function with Gobetwino

I am trying to use gobetwino to log some sensor readings for a load cell and iteration counter. I came across some coding that works quite well, but I am trying to understand it and can’t find an easy explanation. I have created a sample code to do the basics of my data logging that I will post here. I am leaving out my longer coding because it is irrelevant since it is working.

I am confused about the buffer commands and why the itoa function must be used and how they are connect. Also, is there a way to send the reading at a specified time interval rather than 5+ times a second?

int red = 8; //red wire to to this digital pin
int i = 0; //stores variable for iterations(i)
char buffer[5];
int input = A7;
int input1 = 1;


void setup()
{
  pinMode(red, OUTPUT); //declare red wire/pin as output
  pinMode(input, INPUT);
  Serial.begin(9600);
}

void loop()
{
  input1 = analogRead(input);
  Serial.print("#S|LOGTEST|[");
Serial.print(itoa((i), buffer, 10));
Serial.print("\t");
Serial.print(itoa((input1), buffer, 10));
Serial.println("]#");
  if(i <= 50) // i=2500 turns the motor for 1 min at 24ms pulses
  //let i equal total number of times to pulse stepper motor(5000 steps= .1" displacement)
  {
  digitalWrite(red, HIGH); 
  delay( .1);
  
  digitalWrite(red, LOW);
  delay(.1);
  
  digitalWrite(red, HIGH);
  delay(.1);
  
  digitalWrite(red, LOW);
  delay(150); // 24 ms = .05in/min of crosshead movement (ASTM)
    i++; //counter for iterations
  }
  else //if iterations(i) is not within specified limit execute the following
  {
    digitalWrite(red, LOW); //Turns motor off!
    
  }

}

Thanks,
Zach

I am confused about the buffer commands and why the itoa function must be used and how they are connect.

There are no “buffer commands” and itoa() does not need to be used. What it does is force the output to be not more than 9 characters.

  delay( .1);

Is just plain silly. The delay() function takes an unsigned long (integer). Passing it 0 is a waste of effort.

I didn't realize delay was integer only.I have corrected it with delayMicroseconds(100)

With the itoa and buffer are you saying that I can just get rid of it and use the gobetwino sending commands only? I am going to try it in just a few minutes.

Thanks for the quick response! Zach

Okay I got the delay coding fixed and took out the char buffer itoa stuff. It is sending the data now and logging it. But now when I switch my analog input between 3.3v and 5v it doesn’t like to pick up the difference and print it. It will catch 1 switch sometimes, but never more than 1 switch in the analog input will be recorded to the log.

Also, can I slow the data sending rate? Should I adjust the baudrate?

int red = 10; //red wire to to this digital pin
int i = 0; //stores variable for iterations(i)
int input = A7;
int input1 = 1;


void setup()
{
  pinMode(red, OUTPUT); //declare red wire/pin as output
  pinMode(input, INPUT);
  Serial.begin(9600);
}

void loop()
{
  input1 = analogRead(input);
  Serial.print("#S|LOGTEST|[");
Serial.print(i);
Serial.print("\t");
Serial.print(input1);
Serial.println("]#");
  if(i <= 1250) // i=2500 turns the motor for 1 min at 24ms pulses
  //let i equal total number of times to pulse stepper motor(5000 steps= .1" displacement)
  {
  digitalWrite(red, HIGH); 
  delayMicroseconds(100);
  
  
  digitalWrite(red, LOW);
  delay(24); // 24 ms = .05in/min of crosshead movement (ASTM)
    i++; //counter for iterations
  }
  else //if iterations(i) is not within specified limit execute the following
  {
    digitalWrite(red, LOW); 
    
  }

}

Also, can I slow the data sending rate?

Don't do it on every pass through loop(). Look at the blink without delay example to see how to do things periodically without using delay().

Should I adjust the baudrate?

No.