Skip to main content
added 116 characters in body
Source Link
CR7
  • 21
  • 2
  • 6

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code(edit- Sorry previous code was an old file. Here is the correct one):

int count=0;
void setup() { 
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pinMode(13,OUTPUT); 
}

String incoming="";
String temp="";
float f;

void loop() {
  whileif(Serial.available())
      {
      char inByte=(char)Serialf=Serial.read();
      temp=StringparseFloat(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.printlndelay(incoming1000);  
      incoming="";       
   }
//count=count+1;
      //delay(1);
//}

Python Code (edit- Sorry, the previous code was from an old file. Here is the correct one):

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.57
#data=bytearray(b'data')
while True:
        ser.write(str(data)+" "+"\n")
        time.sleep(1)
        ser.flush()

When I run this code I get the following output on the Arduino Serial Monitor. As shown in the figure below.

Ardiuno Serial Monitor

Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code:

int count=0;
void setup() { 
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pinMode(13,OUTPUT); 
}

String incoming="";
String temp="";
float f;

void loop() {
  while(Serial.available())
      {
      char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming="";       
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code(edit- Sorry previous code was an old file. Here is the correct one):

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
//pinMode(13,OUTPUT);
}
float f;

void loop() {
 if(Serial.available())
      {f=Serial.parseFloat();
        Serial.println(f);
      }
    delay(1000);        
   }
//count=count+1;
      //delay(1);
//}

Python Code (edit- Sorry, the previous code was from an old file. Here is the correct one):

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.7

while True:
        ser.write(str(data))
        time.sleep(1)
        ser.flush()

When I run this code I get the following output on the Arduino Serial Monitor. As shown in the figure below.

Ardiuno Serial Monitor

Thank you.

Format code
Source Link
user31481
user31481

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code: int count=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); //pinMode(13,OUTPUT); } String incoming=""; String temp=""; float f;

int count=0;
void setup() { 
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pinMode(13,OUTPUT); 
}

String incoming="";
String temp="";
float f;

void loop() {
  while(Serial.available())
      {
      char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming=""; 
       
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code: int count=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); //pinMode(13,OUTPUT); } String incoming=""; String temp=""; float f;

void loop() {
  while(Serial.available())
      {char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming=""; 
   
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code:

int count=0;
void setup() { 
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pinMode(13,OUTPUT); 
}

String incoming="";
String temp="";
float f;

void loop() {
  while(Serial.available())
      {
      char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming="";       
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

added 875 characters in body
Source Link
CR7
  • 21
  • 2
  • 6

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code: Thankint count=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); //pinMode(13,OUTPUT); } String incoming=""; String temp=""; float f;

void loop() {
  while(Serial.available())
      {char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming=""; 
  
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help. Thank you.

I want to Control the current flowing through a circuit using an Arduino. I have trained a PID controller for this purpose. I am using a current sensor to determine the error. It runs successful on my Arduino. In my next step I want build a system where I can send the Current setpoint (deter mined by my python code) value to the Arduino through serial communication. I am able to send integer values to Arduino. But I am unable to send and receive float values from Python to Arduino. I want to know the necessary code to be written in both sender and receiver. I tried of converting float to string and then send it to Arduino. But I failed. Please help.

Arduino Code: int count=0; void setup() { // put your setup code here, to run once: Serial.begin(9600); //pinMode(13,OUTPUT); } String incoming=""; String temp=""; float f;

void loop() {
  while(Serial.available())
      {char inByte=(char)Serial.read();
      temp=String(inByte);
      incoming+=temp;
      //Serial.println(f);
      }
      Serial.println(incoming);  
      incoming=""; 
  
  }
//count=count+1;
      //delay(1);
//}

Python Code:

import serial
import time
import struct

ser = serial.Serial('/dev/ttyACM0', 9600, timeout = 1) # ttyACM1 for Arduino board
data=5.5
#data=bytearray(b'data')
while True:
    ser.write(str(data)+" "+"\n")
    time.sleep(1)
    ser.flush()

Thank you.

deleted 1 character in body
Source Link
CR7
  • 21
  • 2
  • 6
Loading
Source Link
CR7
  • 21
  • 2
  • 6
Loading