Hardware communication

Hi everyone,

I need your help on a project basic info of this project:

  • Arduino Uno R3
  • BT communication master/slave
  • Encoder function sent from master to slave
    *other function used but working well

So basically what I'm trying to do is to fool an harware controller on a machine to make him think the machine is working (for service purpose).

So almost all my functions are working but I send the wrong infos to the hardware: I simulating a sensor sending different tension to the controller from 0V to 5V using an encoder.

My issue is:

I'm generating my tension on the PWM port of the arduino, it works well with a LED but the controller is receiving the 5volt and it is saying that there is a short-circuit.

What I need is to be able to send a continuous tension from 0v to 5v.

Ex: if I need 2v I need 2 volt all the time and not a cycle of 5 volt which make an average of 2volt (PWM).

Any idea how I can fix this?

Maybe a different port?
Or an electronic component?
A particular coding?

Thank you for your help.

Regards,
Paul

Le code esclave:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3); // RX, TX pour Bluetooth

//Parameters
const int sortie_signal  = 6;
const int signal_pdf = 10;
const int VERIN = 12;

void setup() {
  //Init Serial USB
  Serial.begin(9600);
  Serial.println(F("Initialize System"));
  pinMode(sortie_signal,OUTPUT);
  pinMode(signal_pdf, OUTPUT);
  BTSerial.begin(9600);
  {
  pinMode (8, INPUT);
  pinMode (9, OUTPUT);
}
{
pinMode (VERIN, INPUT) ;
pinMode (11, OUTPUT) ; }



}


void loop() {

  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
     Serial.print("Lecture Bluetooth : ");
    Serial.println(receivedChar);
    if (receivedChar == 'H') {
    analogWrite(signal_pdf,143);// 143 = 0.7volt 
   delay(8.33);// 8.33 = 1000 millisecondes divisé par 120 (le capteur fournit 120 changements d'état par seconde)
    analogWrite(signal_pdf,255);
   // Serial.println("revoie H et on a 0V");
    delay(8.33);

    } else if (receivedChar == 'L') {
      analogWrite(signal_pdf,0);
    //  Serial.println("revoie L et on a 5V");
    }
  }
  
  
 
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'A') {
    analogWrite(sortie_signal,198);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'B') {
    analogWrite(sortie_signal,194);}}
    
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'C') {
    analogWrite(sortie_signal,190);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'D') {
    analogWrite(sortie_signal,186);}}
  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'E') {
    analogWrite(sortie_signal,182);}}
    
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'F') {
    analogWrite(sortie_signal,178);}}
  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'G') {
    analogWrite(sortie_signal,174);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'I') {
    analogWrite(sortie_signal,170);}}
  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'J') {
    analogWrite(sortie_signal,166);}}

  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'K') {
    analogWrite(sortie_signal,162);}}
    
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'M') {
    analogWrite(sortie_signal,148);}}
  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'N') {
    analogWrite(sortie_signal,130);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'O') {
    analogWrite(sortie_signal,123);}}
  
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'P') {
    analogWrite(sortie_signal,110);}}
 
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'Q') {
    analogWrite(sortie_signal,106);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'R') {
    analogWrite(sortie_signal,102);}}

  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'S') {
    analogWrite(sortie_signal,98);}}

  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'T') {
    analogWrite(sortie_signal,94);}}
    
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'U') {
    analogWrite(sortie_signal,90);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'V') {
    analogWrite(sortie_signal,86);}}
   
  if (BTSerial.available()) {
    char receivedChar = BTSerial.read();
    if (receivedChar == 'W') {
    analogWrite(sortie_signal,82);}}
   {
  if (digitalRead (8) == HIGH){
    analogWrite(10,36);// 143 = 0.7volt 
  //  delay(8.33);// 8.33 = 1000 millisecondes divisé par 120 (le capteur fournit 120 changements d'état par seconde)
    analogWrite(10,255);
  //  delay(8.33);
   }
  else {
    analogWrite(10,0);
  }}

can you post a diagram of the connection?

Slave

Transforming a PWM-voltage that alternates between Vcc and 0V can be done with a low-pass-filter
Here is a thread with pictures how such a low-pass-filter looks like.

You will have some up/down of the voltage with a fraction of the averaged voltage
This is called ripple

How much rippling you have depends on the capacity of the capacitor
increasing the capacity lowers the ripple but also lowers the reaction-speed to changes

Of course there are a lot of chips that can do DAC.
one example

If you describe how fast your voltage changes 10 times per second or once every few minutes a more precise answer can be given

best regards Stefan

Hello,

Thank you for the fast answer.

Well I don't need it to change really fast like 1 grade per second would be enough as I simulating a chamber being load

Regards,
Paul

What is "one grade per second" calculated to volts per second?
The equations of low-pass-filters work with slew-rate = olts per second
not "grade per second" (whatever this "grade" is

so which pins are connected to the controller?

On D6

surely there are 2 pins?

Not sure I understand it?
Do you have a tutorial something on it?

What I mean by grade is: 20 position on the encoder from A to W

A= 0v
W= 4,80v or so
Is this the info you need?

isn't there a ground connection as well?

Per second is a speed. Any kind of unit each second.

In the former post you wrote about one "grade" per second.
How many positions per second is one "grade" per second?

I use a resistor for a pull down but nothing else

So it is one position by second

when communicating between devices there needs to be a common ground. there needs to be an electric "circuit" around which current flows.

so presumably you're connecting D6 to some signal input. but you also need a connection between the grounds of both devices

with 20 positions this means

5V / 20 = 0.25V per position which equals to 0.25V per second.

This is a pretty low speed.
So if changing from 1.00 V to 1.25V takes 0.05 seconds would be fast enough.

Here is an online calculator for the time-constant of a RC-lowpass-filter

At a voltage of 5V when using a 10 k resistor combined with a 1 µF capacitor the time-constant is 0,01 seconds.
Where the voltage changes from 0V up to 5V * 0.368 = 1.84V within 0,01 seconds
should be fast enough.

If you use a 10µF capacitor the timeconstant is 0,1 seconds

For a more deeper analyse I would use on oscilloscope that measures the real voltage.
But I think 1 µF should be sufficient for your application.

best regards Stefan

So I used a 0,47uf and a 10uf

Tried it with the oscilloscope last evening and it seems to work pretty well.

Need to see the machine reaction now.

I'll keep you update!

Thank you

It is working very well thank you!

glad that it is working.

If you would like to know how much ripple is still there you could switch your oscilloscope to AC and change to 200 mV, 50 mV, 20 mV ... per grid point
to measure how much ripple is still there.

additionaly yo could write a testcode that changes from duty-cycle 10% to 90% with different speeds and then put the oscilloscope into singleshot mode to see how fast this change is happening

Same thing for changing from duty-cycle 90% to 10%